[AD] int vs long

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Allegro currently assumes that int and long are both 32 bit in length. It 
seems that it's safer to assume that int is 32 bit than that long is, so 
I've made a small preliminary patch (long_int.diff) that replaces long 
with int in places where I think this matters.
I haven't made a lot of work of this yet, so it's certainly incomplete. 
While not a complete solution, it would help for 4.2 anyway.

The second patch (file_inttypes) deprecates packf_[i|m][put|get][w|l]  in 
favour of packf_[i|m][put|get][i16|i32], which is probably also less 
confusing (for consistency, maybe a packf_puti8 should replace packf_putc, 
but here I'm less certain). It doesn't touch the rest of the library 
source, so any attempt to compile Allegro with the patch applied will 
result in deprecated warnings. I'd like to hear some comments before 
giving the library a complete overhaul for this.

Evert
Index: src/blit.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/blit.c,v
retrieving revision 1.15
diff -u -p -r1.15 blit.c
--- src/blit.c	4 Dec 2004 13:28:29 -0000	1.15
+++ src/blit.c	6 Jan 2005 11:40:53 -0000
@@ -60,7 +60,7 @@ static void blit_from_256(BITMAP *src, B
    #ifdef ALLEGRO_COLOR8
 
    int *dest_palette_color;
-   unsigned long s, d;
+   unsigned int s, d;
    unsigned char *ss;
    int x, y, c, rc;
 
@@ -143,7 +143,7 @@ static void blit_from_256(BITMAP *src, B
 
       #ifdef ALLEGRO_COLOR32
       case 32:
-         EXPAND_BLIT(32, sizeof(long));
+         EXPAND_BLIT(32, sizeof(int));
          break;
       #endif
    }
@@ -344,7 +344,7 @@ static void blit_from_15(BITMAP *src, BI
    #ifdef ALLEGRO_COLOR16
 
    int x, y, c, r, g, b;
-   unsigned long s, d;
+   unsigned int s, d;
 
    switch (bitmap_color_depth(dest)) {
 
@@ -369,7 +369,7 @@ static void blit_from_15(BITMAP *src, BI
 
       #ifdef ALLEGRO_COLOR32
       case 32:
-         CONVERT_BLIT(15, sizeof(short), 32, sizeof(long))
+         CONVERT_BLIT(15, sizeof(short), 32, sizeof(int))
          break;
       #endif
    }
@@ -387,7 +387,7 @@ static void blit_from_16(BITMAP *src, BI
    #ifdef ALLEGRO_COLOR16
 
    int x, y, c, r, g, b;
-   unsigned long s, d;
+   unsigned int s, d;
 
    switch (bitmap_color_depth(dest)) {
 
@@ -412,7 +412,7 @@ static void blit_from_16(BITMAP *src, BI
 
       #ifdef ALLEGRO_COLOR32
       case 32:
-         CONVERT_BLIT(16, sizeof(short), 32, sizeof(long))
+         CONVERT_BLIT(16, sizeof(short), 32, sizeof(int))
          break;
       #endif
    }
@@ -430,7 +430,7 @@ static void blit_from_24(BITMAP *src, BI
    #ifdef ALLEGRO_COLOR24
 
    int x, y, c, r, g, b;
-   unsigned long s, d;
+   unsigned int s, d;
 
    switch (bitmap_color_depth(dest)) {
 
@@ -461,7 +461,7 @@ static void blit_from_24(BITMAP *src, BI
 
       #ifdef ALLEGRO_COLOR32
       case 32:
-         CONVERT_BLIT(24, 3, 32, sizeof(long))
+         CONVERT_BLIT(24, 3, 32, sizeof(int))
          break;
       #endif
    }
@@ -479,7 +479,7 @@ static void blit_from_32(BITMAP *src, BI
    #ifdef ALLEGRO_COLOR32
 
    int x, y, c, r, g, b;
-   unsigned long s, d;
+   unsigned int s, d;
 
    switch (bitmap_color_depth(dest)) {
 
@@ -488,29 +488,29 @@ static void blit_from_32(BITMAP *src, BI
          if (_color_conv & COLORCONV_DITHER_PAL)
             dither_blit(src, dest, s_x, s_y, d_x, d_y, w, h);
          else 
-            CONVERT_BLIT(32, sizeof(long), 8, 1)
+            CONVERT_BLIT(32, sizeof(int), 8, 1)
          break;
       #endif
 
       #ifdef ALLEGRO_COLOR16
       case 15:
          if (_color_conv & COLORCONV_DITHER_HI)
-            CONVERT_DITHER_BLIT(32, sizeof(long), 15, sizeof(short))
+            CONVERT_DITHER_BLIT(32, sizeof(int), 15, sizeof(short))
          else
-            CONVERT_BLIT(32, sizeof(long), 15, sizeof(short))
+            CONVERT_BLIT(32, sizeof(int), 15, sizeof(short))
          break;
 
       case 16:
          if (_color_conv & COLORCONV_DITHER_HI)
-            CONVERT_DITHER_BLIT(32, sizeof(long), 16, sizeof(short))
+            CONVERT_DITHER_BLIT(32, sizeof(int), 16, sizeof(short))
          else
-            CONVERT_BLIT(32, sizeof(long), 16, sizeof(short))
+            CONVERT_BLIT(32, sizeof(int), 16, sizeof(short))
          break;
       #endif
 
       #ifdef ALLEGRO_COLOR24
       case 24:
-         CONVERT_BLIT(32, sizeof(long), 24, 3)
+         CONVERT_BLIT(32, sizeof(int), 24, 3)
          break;
       #endif
    }
@@ -601,7 +601,7 @@ void _blit_between_formats(BITMAP *src, 
  */
 static void blit_to_self(BITMAP *src, BITMAP *dest, int s_x, int s_y, int d_x, int d_y, int w, int h)
 {
-   unsigned long sx, sy, dx, dy;
+   unsigned int sx, sy, dx, dy;
    BITMAP *tmp;
 
    if (dest->id & BMP_ID_NOBLIT) {
Index: src/bmp.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/bmp.c,v
retrieving revision 1.15
diff -u -p -r1.15 bmp.c
--- src/bmp.c	11 Jan 2004 22:23:35 -0000	1.15
+++ src/bmp.c	6 Jan 2005 11:40:54 -0000
@@ -35,11 +35,11 @@
 
 typedef struct BITMAPFILEHEADER
 {
-   unsigned long  bfType;
-   unsigned long  bfSize;
+   unsigned int  bfType;
+   unsigned int  bfSize;
    unsigned short bfReserved1;
    unsigned short bfReserved2;
-   unsigned long  bfOffBits;
+   unsigned int  bfOffBits;
 } BITMAPFILEHEADER;
 
 
@@ -48,25 +48,25 @@ typedef struct BITMAPFILEHEADER
  */
 typedef struct BITMAPINFOHEADER
 {
-   unsigned long  biWidth;
-   unsigned long  biHeight;
+   unsigned int  biWidth;
+   unsigned int  biHeight;
    unsigned short biBitCount;
-   unsigned long  biCompression;
+   unsigned int  biCompression;
 } BITMAPINFOHEADER;
 
 
 typedef struct WINBMPINFOHEADER  /* size: 40 */
 {
-   unsigned long  biWidth;
-   unsigned long  biHeight;
+   unsigned int  biWidth;
+   unsigned int  biHeight;
    unsigned short biPlanes;
    unsigned short biBitCount;
-   unsigned long  biCompression;
-   unsigned long  biSizeImage;
-   unsigned long  biXPelsPerMeter;
-   unsigned long  biYPelsPerMeter;
-   unsigned long  biClrUsed;
-   unsigned long  biClrImportant;
+   unsigned int  biCompression;
+   unsigned int  biSizeImage;
+   unsigned int  biXPelsPerMeter;
+   unsigned int  biYPelsPerMeter;
+   unsigned int  biClrUsed;
+   unsigned int  biClrImportant;
 } WINBMPINFOHEADER;
 
 
@@ -173,7 +173,7 @@ static void read_bmicolors(int ncols, RG
 static void read_1bit_line(int length, PACKFILE *f, BITMAP *bmp, int line)
 {
    unsigned char b[32];
-   unsigned long n;
+   unsigned int n;
    int i, j, k;
    int pix;
 
@@ -199,7 +199,7 @@ static void read_1bit_line(int length, P
 static void read_4bit_line(int length, PACKFILE *f, BITMAP *bmp, int line)
 {
    unsigned char b[8];
-   unsigned long n;
+   unsigned int n;
    int i, j, k;
    int temp;
    int pix;
@@ -229,7 +229,7 @@ static void read_4bit_line(int length, P
 static void read_8bit_line(int length, PACKFILE *f, BITMAP *bmp, int line)
 {
    unsigned char b[4];
-   unsigned long n;
+   unsigned int n;
    int i, j, k;
    int pix;
 
@@ -285,7 +285,7 @@ static void read_bitfields_image(PACKFIL
    int bpp;
    int bytes_per_pixel;
    int red, grn, blu;
-   unsigned long buffer;
+   unsigned int buffer;
 
    bpp = bitmap_color_depth(bmp);
    bytes_per_pixel = BYTES_PER_PIXEL(bpp);
@@ -523,7 +523,7 @@ BITMAP *load_bmp(AL_CONST char *filename
    PALETTE tmppal;
    int want_palette = TRUE;
    int ncol;
-   unsigned long biSize;
+   unsigned int biSize;
    int bpp, dest_depth;
    ASSERT(filename);
 
@@ -579,9 +579,9 @@ BITMAP *load_bmp(AL_CONST char *filename
       bpp = 8;
 
    if (infoheader.biCompression == BI_BITFIELDS) {
-      unsigned long redMask = pack_igetl(f);
-      unsigned long grnMask = pack_igetl(f);
-      unsigned long bluMask = pack_igetl(f);
+      unsigned int redMask = pack_igetl(f);
+      unsigned int grnMask = pack_igetl(f);
+      unsigned int bluMask = pack_igetl(f);
 
       if ((bluMask == 0x001f) && (redMask == 0x7C00))
 	 bpp = 15;
? src/fontbios.c
? src/fontbmp.c
? src/fontdat.c
? src/fontgrx.c
? src/readfont.c
? include/allegro/font.h
Index: src/file.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/file.c,v
retrieving revision 1.52
diff -u -p -r1.52 file.c
--- src/file.c	1 Oct 2004 14:06:54 -0000	1.52
+++ src/file.c	6 Jan 2005 11:51:41 -0000
@@ -2119,10 +2119,10 @@ int pack_fseek(PACKFILE *f, int offset)
 
 
 
-/* pack_igetw:
+/* pack_igeti16:
  *  Reads a 16 bit word from a file, using intel byte ordering.
  */
-int pack_igetw(PACKFILE *f)
+int pack_igeti16(PACKFILE *f)
 {
    int b1, b2;
    ASSERT(f);
@@ -2136,10 +2136,10 @@ int pack_igetw(PACKFILE *f)
 
 
 
-/* pack_igetl:
+/* pack_igeti32:
  *  Reads a 32 bit long from a file, using intel byte ordering.
  */
-long pack_igetl(PACKFILE *f)
+long pack_igeti32(PACKFILE *f)
 {
    int b1, b2, b3, b4;
    ASSERT(f);
@@ -2156,10 +2156,10 @@ long pack_igetl(PACKFILE *f)
 
 
 
-/* pack_iputw:
+/* pack_iputi16:
  *  Writes a 16 bit int to a file, using intel byte ordering.
  */
-int pack_iputw(int w, PACKFILE *f)
+int pack_iputi16(int w, PACKFILE *f)
 {
    int b1, b2;
    ASSERT(f);
@@ -2176,10 +2176,10 @@ int pack_iputw(int w, PACKFILE *f)
 
 
 
-/* pack_iputl:
- *  Writes a 32 bit long to a file, using intel byte ordering.
+/* pack_iputi32:
+ *  Writes a 32 bit int to a file, using intel byte ordering.
  */
-long pack_iputl(long l, PACKFILE *f)
+long pack_iputi32(long l, PACKFILE *f)
 {
    int b1, b2, b3, b4;
    ASSERT(f);
@@ -2203,7 +2203,7 @@ long pack_iputl(long l, PACKFILE *f)
 /* pack_mgetw:
  *  Reads a 16 bit int from a file, using motorola byte-ordering.
  */
-int pack_mgetw(PACKFILE *f)
+int pack_mgeti16(PACKFILE *f)
 {
    int b1, b2;
    ASSERT(f);
@@ -2220,7 +2220,7 @@ int pack_mgetw(PACKFILE *f)
 /* pack_mgetl:
  *  Reads a 32 bit long from a file, using motorola byte-ordering.
  */
-long pack_mgetl(PACKFILE *f)
+long pack_mgeti32(PACKFILE *f)
 {
    int b1, b2, b3, b4;
    ASSERT(f);
@@ -2240,7 +2240,7 @@ long pack_mgetl(PACKFILE *f)
 /* pack_mputw:
  *  Writes a 16 bit int to a file, using motorola byte-ordering.
  */
-int pack_mputw(int w, PACKFILE *f)
+int pack_mputi16(int w, PACKFILE *f)
 {
    int b1, b2;
    ASSERT(f);
@@ -2260,7 +2260,7 @@ int pack_mputw(int w, PACKFILE *f)
 /* pack_mputl:
  *  Writes a 32 bit long to a file, using motorola byte-ordering.
  */
-long pack_mputl(long l, PACKFILE *f)
+long pack_mputi32(long l, PACKFILE *f)
 {
    int b1, b2, b3, b4;
    ASSERT(f);
Index: include/allegro/alcompat.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/alcompat.h,v
retrieving revision 1.17
diff -u -p -r1.17 alcompat.h
--- include/allegro/alcompat.h	22 Aug 2004 01:57:13 -0000	1.17
+++ include/allegro/alcompat.h	6 Jan 2005 11:51:42 -0000
@@ -241,6 +241,47 @@ AL_FUNCPTR(void, retrace_proc, (void));
 #endif
 AL_FUNC_DEPRECATED(int,  timer_is_using_retrace, (void));
 
+/* Old-style file I/O routines */
+AL_INLINE_DEPRECATED(int, pack_igetw(PACKFILE *f),
+{
+   return pack_igeti16(f);
+})
+
+AL_INLINE_DEPRECATED(long, pack_igetl(PACKFILE *f),
+{
+   return pack_igeti32(f);
+})
+
+AL_INLINE_DEPRECATED(int, pack_iputw, (int w, struct PACKFILE *f),
+{
+   return pack_iputi16(w, f);
+})
+
+AL_INLINE_DEPRECATED(long, pack_iputl, (long l, PACKFILE *f),
+{
+   return pack_iputi32(w, f);
+})
+
+AL_INLINE_DEPRECATED(int, pack_mgetw(PACKFILE *f),
+{
+   return pack_mgeti16(f);
+})
+
+AL_INLINE_DEPRECATED(long, pack_mgetl(PACKFILE *f),
+{
+   return pack_mgeti32(f);
+})
+
+AL_INLINE_DEPRECATED(int, pack_mputw, (int w, struct PACKFILE *f),
+{
+   return pack_mputi16(w, f);
+})
+
+AL_INLINE_DEPRECATED(long, pack_mputl, (long l, PACKFILE *f),
+{
+   return pack_mputi32(w, f);
+})
+
 #ifdef __cplusplus
    }
 #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/