compiler/libec: Resolving long type size properly
authorJerome St-Louis <jerome@ecere.com>
Mon, 15 Apr 2013 09:42:51 +0000 (05:42 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 15 Apr 2013 09:42:51 +0000 (05:42 -0400)
- Solves Distributed Objects that were deadlocking on UNIX due to Thread ID comparison

14 files changed:
compiler/libec/src/ast.ec
ecere/src/com/String.ec
ecere/src/com/dataTypes.ec
ecere/src/com/instance.ec
ecere/src/gfx/bitmaps/PNGFormat.ec
ecere/src/gfx/drivers/LFBDisplayDriver.ec
ecere/src/gui/dialogs/ColorPicker.ec
ecere/src/gui/drivers/XInterface.ec
ecere/src/net/Socket.ec
ecere/src/sys/EARArchive.ec
ecere/src/sys/File.ec
ecere/src/sys/GlobalAppSettings.ec
ecere/src/sys/Time.ec
ecere/src/sys/unicode.ec

index 5051507..9b9048d 100644 (file)
@@ -2234,7 +2234,7 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
                isTypedef = true;
             else if(spec.specifier == VOID) specType.kind = voidType;
             else if(spec.specifier == CHAR) specType.kind = charType;
-            else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
+            else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType && !isLong) specType.kind = intType; }
             else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
             else if(spec.specifier == INT64) specType.kind = int64Type;
             else if(spec.specifier == VALIST) 
@@ -2242,7 +2242,7 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             else if(spec.specifier == SHORT) specType.kind = shortType;
             else if(spec.specifier == LONG) 
             {
-               if(isLong)
+               if(isLong || (targetBits == 64 && targetPlatform != win32))
                   specType.kind = int64Type;
                else
                   specType.kind = intType;
index 17fa08a..0ce03d4 100644 (file)
@@ -1060,7 +1060,7 @@ public uint GetHexValue(char ** buffer)
 {
    char string[20];
    GetString(buffer,string,20);
-   return strtoul(string, null, 16);
+   return (uint)strtoul(string, null, 16);
 }
 
 public char * StripQuotes(char * string, char * output)
index 24e3fe0..b03956b 100644 (file)
@@ -1334,7 +1334,7 @@ static char * UInteger_OnGetString(Class _class, unsigned int * data, char * str
 static bool UInteger_OnGetDataFromString(Class _class, unsigned int * data, char * string)
 {
    char * end;
-   uint result = strtoul(string, &end, 0);
+   uint result = (uint)strtoul(string, &end, 0);
    if(end > string)
    {
       *data = result;
index 4a77e2a..5dadab7 100644 (file)
@@ -3466,7 +3466,7 @@ static void ComputeClassParameters(Class templatedClass, char * templateParams,
                   }
                   else if(!strcmp(curParam.dataTypeString, "uint"))
                   {
-                     argument.expression.ui = strtoul(value, null, 0);
+                     argument.expression.ui = (uint)strtoul(value, null, 0);
                   }
                   else if(!strcmp(curParam.dataTypeString, "char"))
                   {
@@ -3502,7 +3502,7 @@ static void ComputeClassParameters(Class templatedClass, char * templateParams,
                   }
                   else // if(!strcmp(curParam.dataTypeString, "int"))
                   {
-                     argument.expression.i = strtol(value, null, 0);
+                     argument.expression.i = (int)strtol(value, null, 0);
                   }
                   break;
                } 
index dff0233..ee18986 100644 (file)
@@ -89,7 +89,7 @@ class PNGFormat : BitmapFormat
                      png_set_tRNS_to_alpha(png_ptr);
                   numPasses = png_set_interlace_handling(png_ptr);
 
-                  if((result = bitmap.Allocate(null, width, height, 0, pixelFormatRGBA, false)))
+                  if((result = bitmap.Allocate(null, (uint)width, (uint)height, 0, pixelFormatRGBA, false)))
                   {
                      int pass;
 
index d31a27b..3b820ac 100644 (file)
@@ -159,7 +159,7 @@ static HB_Error hb_getSFntTable(void *font, HB_Tag tableTag, HB_Byte *buffer, HB
         return HB_Err_Invalid_Argument;
 
     error = FT_Load_Sfnt_Table(face, tableTag, 0, buffer, &ftlen);
-    *length = ftlen;
+    *length = (uint)ftlen;
     return (HB_Error)error;
 }
 
@@ -183,8 +183,8 @@ static HB_Error hb_getPointInOutline(HB_Font font, HB_Glyph glyph, int flags, hb
     if (point > *nPoints)
         return (HB_Error)HB_Err_Invalid_SubTable;
 
-    *xpos = face->glyph->outline.points[point].x;
-    *ypos = face->glyph->outline.points[point].y;
+    *xpos = (int)face->glyph->outline.points[point].x;
+    *ypos = (int)face->glyph->outline.points[point].y;
 
     return HB_Err_Ok;
 }
@@ -246,11 +246,11 @@ static HB_FontClass hb_fontClass =
    hb_getPointInOutline, hb_getGlyphMetrics, hb_getFontMetric
 };
 
-static uint FT_stream_load(FT_Stream stream, uint offset, byte * buffer, uint count)
+static uint FT_stream_load(FT_Stream stream, long offset, byte * buffer, long count)
 {
     File f = stream->descriptor.pointer;
-    f.Seek(offset, start);
-    return count ? f.Read(buffer, 1, count) : 0;
+    f.Seek((int)offset, start);
+    return count ? f.Read(buffer, 1, (uint)count) : 0;
 }
 
 static void FT_stream_close(FT_Stream stream)
@@ -426,8 +426,8 @@ class GlyphPack : BTNode
 
             fontEntry.hbFont.x_ppem  = fontEntry.face->size->metrics.x_ppem;
             fontEntry.hbFont.y_ppem  = fontEntry.face->size->metrics.y_ppem;
-            fontEntry.hbFont.x_scale = fontEntry.face->size->metrics.x_scale;
-            fontEntry.hbFont.y_scale = fontEntry.face->size->metrics.y_scale;
+            fontEntry.hbFont.x_scale = (int)fontEntry.face->size->metrics.x_scale;
+            fontEntry.hbFont.y_scale = (int)fontEntry.face->size->metrics.y_scale;
          }
       }
 
@@ -521,7 +521,7 @@ class GlyphPack : BTNode
             //glyph->top = (int)(ascender - slot->bitmap_top); // + ((faces[c]->size->metrics.height >> 6) - (faces[0]->size->metrics.height >> 6)) + (font.height - (faces[c]->size->metrics.height >> 6));
             
             //glyph->top = (int)(ascender - slot->bitmap_top);// + (font.height - maxHeight);
-            glyph->top = (int)(ascender - slot->bitmap_top) + (font.height - (faces[c]->size->metrics.height >> 6)) / 2;
+            glyph->top = (int)(ascender - slot->bitmap_top) + (int)(font.height - (faces[c]->size->metrics.height >> 6)) / 2;
 
             // printf("[char: %d] mode: %d, width: %d, height: %d, pitch: %d\n", key + c, slot->bitmap.pixel_mode, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch);
             xMax = x + slot->bitmap.width;
@@ -574,12 +574,12 @@ class GlyphPack : BTNode
             glyph->w = slot->bitmap.width;
             glyph->h = slot->bitmap.rows;
             glyph->glyphNo = glyphNo;
-            glyph->bx = faces[c]->glyph->metrics.horiBearingX;
-            glyph->by = faces[c]->glyph->metrics.horiBearingY;
+            glyph->bx = (int)faces[c]->glyph->metrics.horiBearingX;
+            glyph->by = (int)faces[c]->glyph->metrics.horiBearingY;
             glyph->scale = scales[c];
 
-            glyph->ax = slot->advance.x;
-            glyph->ay = slot->advance.y + (64 - slot->advance.y % 64);
+            glyph->ax = (int)slot->advance.x;
+            glyph->ay = (int)(slot->advance.y + (64 - slot->advance.y % 64));
          }
          #if 0
          {
@@ -3070,7 +3070,7 @@ public class LFBDisplayDriver : DisplayDriver
                      }
                      FT_Set_Transform(fontEntry.face, &matrix, &pen );
                      FaceSetCharSize(fontEntry.face, size);
-                     font.height = ((fontEntry.face->size->metrics.height) >> 6); //* y_scale;
+                     font.height = (int)((fontEntry.face->size->metrics.height) >> 6); //* y_scale;
                      // printf("Font height is %d\n", font.height);
                      font.fakeItalic = fakeItalic;
                      font.size = size;
index ef231b1..a013e9c 100644 (file)
@@ -685,10 +685,10 @@ private:
       bool NotifyModified(EditBox control)
       {
          ColorRGB rgb;
-         int value = strtoul(control.contents, null, 16);
+         uint value = (uint)strtoul(control.contents, null, 16);
          if(strlen(control.contents) <= 6)
             value |= 0xFF000000;
-         argb = (unsigned int)value;
+         argb = value;
          rgb = argb;
          cmyk = rgb;
          hsv = rgb;
index a77a200..2983be5 100644 (file)
@@ -253,7 +253,7 @@ static void RepositionDesktop(bool updateChildren)
       if(data)
       {
          int desktops = 0;
-         desktops = *(long *)data;
+         desktops = (int)*(long *)data;
 
          //printf("_NET_NUMBER_OF_DESKTOPS is %d\n", desktops);
 
@@ -273,7 +273,7 @@ static void RepositionDesktop(bool updateChildren)
       
       if(data)
       {
-         current = *(long *)data;
+         current = (int)*(long *)data;
          XFree(data);
          data = null;
 
@@ -306,10 +306,10 @@ static void RepositionDesktop(bool updateChildren)
       {
          workareas = (long *)data;
      
-         x = workareas[current * 4];
-         y = workareas[current * 4 + 1];
-         w = workareas[current * 4 + 2];
-         h = workareas[current * 4 + 3];   
+         x = (int)workareas[current * 4];
+         y = (int)workareas[current * 4 + 1];
+         w = (int)workareas[current * 4 + 2];
+         h = (int)workareas[current * 4 + 3];
 
          //printf("_NET_WORKAREA is x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
          XFree(data);
@@ -408,14 +408,14 @@ static bool ProcessKeyMessage(Window window, uint keyCode, int release, XKeyEven
 */
 
    if(!buf)
-      buf = malloc(bufsize);
+      buf = malloc((uint)bufsize);
    if(windowData && windowData.ic)
    { 
-      buflength = XmbLookupString(windowData.ic, event, buf, bufsize, &keysym, &status);
+      buflength = XmbLookupString(windowData.ic, event, buf, (int)bufsize, &keysym, &status);
       if (status == XBufferOverflow)
       {
-         buf = realloc(buf, (bufsize = buflength));
-         buflength = XmbLookupString(windowData.ic, event, buf, bufsize, &keysym, &status);
+         buf = realloc(buf, (uint)(bufsize = buflength));
+         buflength = XmbLookupString(windowData.ic, event, buf, (int)bufsize, &keysym, &status);
       }
       if(status != XLookupKeySym && status != XLookupBoth && release == 1)
          keysym = XLookupKeysym(event, 0);
@@ -1053,7 +1053,7 @@ class XInterface : Interface
             {
                XVisualInfo vinfo;
                XVisualInfo *vinfo_ret;
-               long numitems;
+               int numitems = 0;
               
                vinfo.visualid = XVisualIDFromVisual(xSystemVisual);
                vinfo_ret = XGetVisualInfo(xGlobalDisplay, VisualIDMask, &vinfo, &numitems);
@@ -1463,7 +1463,7 @@ class XInterface : Interface
                         event->x_root, event->y_root, &keyFlags, false, false);
                      delete window;
                      //*if(xGlobalDisplay) XLockDisplay(xGlobalDisplay);
-                     lastTime = event->time;
+                     lastTime = (uint)event->time;
                   }
                   break;
                }
@@ -1705,7 +1705,7 @@ class XInterface : Interface
                      //if(event->send_event)
                      {
                         X11Window rootChild;
-                        long rootX, rootY;
+                        int rootX, rootY;
                         XTranslateCoordinates(xGlobalDisplay, event->window,
                            RootWindow(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 0, 0, 
                            &rootX, &rootY, &rootChild);
@@ -1749,7 +1749,7 @@ class XInterface : Interface
                      bool laterFocus;
                      activeWindow = (X11Window)window.windowHandle;
 
-                     timeStamp = event->data.l[1];
+                     timeStamp = (int)event->data.l[1];
                      
                      windowData = window.windowData;
                      laterFocus = windowData.laterFocus;
@@ -1864,8 +1864,8 @@ class XInterface : Interface
                         bool hadFrameExtents = windowData.gotFrameExtents;
                         windowData.decor =
                         {
-                           left = extents[0], right  = extents[1],
-                           top  = extents[2], bottom = extents[3]
+                           left = (int)extents[0], right  = (int)extents[1],
+                           top  = (int)extents[2], bottom = (int)extents[3]
                         };
                         windowData.gotFrameExtents = true;
                         {
index e4e5b1d..80f5d4e 100644 (file)
@@ -305,7 +305,7 @@ public:
          fd_set ws, es;
 
          if(s != -1 && ((type == tcp && (count = SendData(buffer, size, 0))) ||
-            (type == udp && (count = sendto(s, buffer, size,0, (SOCKADDR *)&a, sizeof(a))))))
+            (type == udp && (count = (int)sendto(s, buffer, size,0, (SOCKADDR *)&a, sizeof(a))))))
          {
    #if defined(__WIN32__)
             int error = WSAGetLastError();
@@ -618,7 +618,7 @@ private:
             else
             {
                int len = sizeof(a);
-               count = recvfrom(s, recvBuffer + recvBytes, 
+               count = (int)recvfrom(s, recvBuffer + recvBytes, 
                   recvBufferSize - recvBytes, 0, (SOCKADDR *)&a, &len);
                strcpy(inetAddress, inet_ntoa(this.a.sin_addr));
                inetPort = ntohs((uint16)a.sin_port);
index 9523261..5004f91 100644 (file)
@@ -537,7 +537,7 @@ class EARArchive : Archive
                      {
                         unsigned long destLen = entry.size;
                         uncompress(uncompressed, &destLen, compressed, entry.cSize);
-                        entry.size = destLen;
+                        entry.size = (FileSize)destLen;  // TODO: Support 64 bit file sizes
                      }
                      delete compressed;
                   }
@@ -588,7 +588,7 @@ class EARArchive : Archive
                {
                   unsigned long destLen = entry.size;
                   uncompress(uncompressed, &destLen, compressed, entry.cSize);
-                  entry.size = destLen;
+                  entry.size = (FileSize)destLen;
                }
                delete compressed;
             }
@@ -723,7 +723,7 @@ class EARArchiveDir : ArchiveDir
                      {
                         unsigned long destLen = entry.size;
                         uncompress(uncompressed, &destLen, compressed, entry.cSize);
-                        entry.size = destLen;
+                        entry.size = (FileSize)destLen;
                      }
                      delete compressed;
                   }
@@ -1127,7 +1127,7 @@ class EARArchiveDir : ArchiveDir
                   if(compressed)
                   {
                      compress2(compressed, &destLen, uncompressed, entry.size, compression);
-                     entry.cSize = destLen;
+                     entry.cSize = (FileSize)destLen;
                   }
                }
                delete uncompressed;
@@ -1388,7 +1388,7 @@ class EARFileSystem : FileSystem
                            {
                               unsigned long destLen = entry.size;
                               uncompress(uncompressed, &destLen, compressed, entry.cSize);
-                              entry.size = destLen;
+                              entry.size = (FileSize)destLen;
                            }
                            delete compressed;
                         }
index 72915e9..462bed5 100644 (file)
@@ -470,7 +470,7 @@ public:
 
    virtual uint Tell(void)
    {
-      return input ? ftell(input) : ftell(output);
+      return (uint)(input ? ftell(input) : ftell(output));
    }
 
    virtual int Read(void * buffer, uint size, uint count)
@@ -703,7 +703,7 @@ public:
    {
       char string[32];
       GetString(string, sizeof(string));
-      return strtoul(string, null, 16);
+      return (uint)strtoul(string, null, 16);
    }
 
    float GetFloat(void)
@@ -1395,7 +1395,7 @@ static FileDesc FileFind(char * path, char * extensions)
                if(!stat(file.path, &s))
                {
                   file.stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-                  file.stats.size = s.st_size;
+                  file.stats.size = (FileSize)s.st_size;
                   file.stats.accessed = s.st_atime;
                   file.stats.modified = s.st_mtime;
                   file.stats.created = s.st_ctime;
@@ -1671,7 +1671,7 @@ private class FileDesc : struct
                {
                   stats.attribs = FileAttribs { };
                   stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-                  stats.size = s.st_size;
+                  stats.size = (FileSize)s.st_size;
                   stats.accessed = s.st_atime;
                   stats.modified = s.st_mtime;
                   stats.created = s.st_ctime;
index 1944fbe..51ef0d1 100644 (file)
@@ -514,7 +514,7 @@ public:
                      case integer:
                      {
                         int * integer = value;
-                        *integer = strtoul(string, null, 0);
+                        *integer = (int)strtol(string, null, 0);
                         break;
                      }
                   }
index ecd3486..26ea723 100644 (file)
@@ -822,7 +822,7 @@ public Time GetTime(void)
 
    if(!secbase)
    {
-      secbase = tp.tv_sec;
+      secbase = (int)tp.tv_sec;
       return tp.tv_usec / 1000000.0;
    }
    return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0;
index 317534b..ce0ef92 100644 (file)
@@ -409,10 +409,10 @@ static class UnicodeDatabase
             if(line[0] && line[0] != '#')
             {
                char * endPtr;
-               uint start = strtoul(line, &endPtr, 16);
+               uint start = (uint)strtoul(line, &endPtr, 16);
                if(endPtr)
                {
-                  uint end = (endPtr && *endPtr == '.') ? strtoul(endPtr + 2, &endPtr, 16) : start;
+                  uint end = (endPtr && *endPtr == '.') ? (uint)strtoul(endPtr + 2, &endPtr, 16) : start;
                   if(endPtr)
                   {
                      endPtr = strchr(endPtr, ';');