From 690119621eb0645444236f13c69eb2dacda65ab5 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 23 Apr 1998 20:23:00 +0000 Subject: Purported fixes for 64-bit platforms with help from John Jorgensen --- Modules/audioop.c | 36 ++++++++++++------- Modules/imageop.c | 42 ++++++++++++++-------- Modules/rgbimgmodule.c | 96 ++++++++++++++++++++++++++++---------------------- 3 files changed, 105 insertions(+), 69 deletions(-) diff --git a/Modules/audioop.c b/Modules/audioop.c index 50a899e..e7edfec 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -33,6 +33,18 @@ PERFORMANCE OF THIS SOFTWARE. #include "Python.h" +#if SIZEOF_INT == 4 +typedef int Py_Int32; +typedef unsigned int Py_UInt32; +#else +#if SIZEOF_LONG == 4 +typedef long Py_Int32; +typedef unsigned long Py_UInt32; +#else +#error "No 4-byte integral type" +#endif +#endif + #if defined(__CHAR_UNSIGNED__) #if defined(signed) !ERROR!; READ THE SOURCE FILE!; @@ -164,7 +176,7 @@ static int stepsizeTable[89] = { #define CHARP(cp, i) ((signed char *)(cp+i)) #define SHORTP(cp, i) ((short *)(cp+i)) -#define LONGP(cp, i) ((long *)(cp+i)) +#define LONGP(cp, i) ((Py_Int32 *)(cp+i)) @@ -670,7 +682,7 @@ audioop_mul(self, args) val = (int)fval; if ( size == 1 ) *CHARP(ncp, i) = (signed char)val; else if ( size == 2 ) *SHORTP(ncp, i) = (short)val; - else if ( size == 4 ) *LONGP(ncp, i) = (long)val; + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)val; } return rv; } @@ -716,7 +728,7 @@ audioop_tomono(self, args) val1 = (int)fval; if ( size == 1 ) *CHARP(ncp, i/2) = (signed char)val1; else if ( size == 2 ) *SHORTP(ncp, i/2) = (short)val1; - else if ( size == 4 ) *LONGP(ncp, i/2)= (long)val1; + else if ( size == 4 ) *LONGP(ncp, i/2)= (Py_Int32)val1; } return rv; } @@ -766,11 +778,11 @@ audioop_tostereo(self, args) if ( size == 1 ) *CHARP(ncp, i*2) = (signed char)val1; else if ( size == 2 ) *SHORTP(ncp, i*2) = (short)val1; - else if ( size == 4 ) *LONGP(ncp, i*2) = (long)val1; + else if ( size == 4 ) *LONGP(ncp, i*2) = (Py_Int32)val1; if ( size == 1 ) *CHARP(ncp, i*2+1) = (signed char)val2; else if ( size == 2 ) *SHORTP(ncp, i*2+2) = (short)val2; - else if ( size == 4 ) *LONGP(ncp, i*2+4) = (long)val2; + else if ( size == 4 ) *LONGP(ncp, i*2+4) = (Py_Int32)val2; } return rv; } @@ -825,7 +837,7 @@ audioop_add(self, args) if ( size == 1 ) *CHARP(ncp, i) = (signed char)newval; else if ( size == 2 ) *SHORTP(ncp, i) = (short)newval; - else if ( size == 4 ) *LONGP(ncp, i) = (long)newval; + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)newval; } return rv; } @@ -863,7 +875,7 @@ audioop_bias(self, args) if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val+bias); else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val+bias); - else if ( size == 4 ) *LONGP(ncp, i) = (long)(val+bias); + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val+bias); } return rv; } @@ -902,7 +914,7 @@ audioop_reverse(self, args) if ( size == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val); - else if ( size == 4 ) *LONGP(ncp, j) = (long)(val<<16); + else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16); } return rv; } @@ -940,7 +952,7 @@ audioop_lin2lin(self, args) if ( size2 == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val); - else if ( size2 == 4 ) *LONGP(ncp, j) = (long)(val<<16); + else if ( size2 == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16); } return rv; } @@ -1080,7 +1092,7 @@ audioop_ratecv(self, args) else if (size == 2) *SHORTP(ncp, 0) = (short)(cur_o); else if (size == 4) - *LONGP(ncp, 0) = (long)(cur_o<<16); + *LONGP(ncp, 0) = (Py_Int32)(cur_o<<16); ncp += size; } d -= inrate; @@ -1155,7 +1167,7 @@ audioop_ulaw2lin(self, args) if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val >> 8); else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val); - else if ( size == 4 ) *LONGP(ncp, i) = (long)(val<<16); + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val<<16); } return rv; } @@ -1355,7 +1367,7 @@ audioop_adpcm2lin(self, args) /* Step 6 - Output value */ if ( size == 1 ) *CHARP(ncp, i) = (signed char)(valpred >> 8); else if ( size == 2 ) *SHORTP(ncp, i) = (short)(valpred); - else if ( size == 4 ) *LONGP(ncp, i) = (long)(valpred<<16); + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(valpred<<16); } rv = Py_BuildValue("(O(ii))", str, valpred, index); diff --git a/Modules/imageop.c b/Modules/imageop.c index 049908d..7b82e04 100644 --- a/Modules/imageop.c +++ b/Modules/imageop.c @@ -37,9 +37,21 @@ PERFORMANCE OF THIS SOFTWARE. #include "Python.h" +#if SIZEOF_INT == 4 +typedef int Py_Int32; +typedef unsigned int Py_UInt32; +#else +#if SIZEOF_LONG == 4 +typedef long Py_Int32; +typedef unsigned long Py_UInt32; +#else +#error "No 4-byte integral type" +#endif +#endif + #define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x)) #define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(y*xmax+x))) -#define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x))) +#define LONGP(cp, xmax, x, y) ((Py_Int32 *)(cp+4*(y*xmax+x))) static PyObject *ImageopError; @@ -50,7 +62,7 @@ PyObject *args; { char *cp, *ncp; short *nsp; - long *nlp; + Py_Int32 *nlp; int len, size, x, y, newx1, newx2, newy1, newy2; int ix, iy, xstep, ystep; PyObject *rv; @@ -76,7 +88,7 @@ PyObject *args; return 0; ncp = (char *)PyString_AsString(rv); nsp = (short *)ncp; - nlp = (long *)ncp; + nlp = (Py_Int32 *)ncp; newy2 += ystep; newx2 += xstep; for( iy = newy1; iy != newy2; iy+=ystep ) { @@ -106,7 +118,7 @@ PyObject *args; { char *cp, *ncp; short *nsp; - long *nlp; + Py_Int32 *nlp; int len, size, x, y, newx, newy; int ix, iy; int oix, oiy; @@ -130,7 +142,7 @@ PyObject *args; return 0; ncp = (char *)PyString_AsString(rv); nsp = (short *)ncp; - nlp = (long *)ncp; + nlp = (Py_Int32 *)ncp; for( iy = 0; iy < newy; iy++ ) { for ( ix = 0; ix < newx; ix++ ) { oix = ix * x / newx; @@ -539,11 +551,11 @@ imageop_rgb2rgb8(self, args) PyObject *args; { int x, y, len, nlen; - unsigned long *cp; + Py_UInt32 *cp; unsigned char *ncp; PyObject *rv; int i, r, g, b; - unsigned long value, nvalue; + Py_UInt32 value, nvalue; if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) return 0; @@ -584,10 +596,10 @@ PyObject *args; { int x, y, len, nlen; unsigned char *cp; - unsigned long *ncp; + Py_UInt32 *ncp; PyObject *rv; int i, r, g, b; - unsigned long value, nvalue; + Py_UInt32 value, nvalue; if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) return 0; @@ -601,7 +613,7 @@ PyObject *args; rv = PyString_FromStringAndSize(NULL, nlen*4); if ( rv == 0 ) return 0; - ncp = (unsigned long *)PyString_AsString(rv); + ncp = (Py_UInt32 *)PyString_AsString(rv); for ( i=0; i < nlen; i++ ) { /* Bits in source: RRRBBGGG @@ -626,11 +638,11 @@ imageop_rgb2grey(self, args) PyObject *args; { int x, y, len, nlen; - unsigned long *cp; + Py_UInt32 *cp; unsigned char *ncp; PyObject *rv; int i, r, g, b; - unsigned long value, nvalue; + Py_UInt32 value, nvalue; if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) return 0; @@ -665,10 +677,10 @@ PyObject *args; { int x, y, len, nlen; unsigned char *cp; - unsigned long *ncp; + Py_UInt32 *ncp; PyObject *rv; int i; - unsigned long value; + Py_UInt32 value; if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) return 0; @@ -682,7 +694,7 @@ PyObject *args; rv = PyString_FromStringAndSize(NULL, nlen*4); if ( rv == 0 ) return 0; - ncp = (unsigned long *)PyString_AsString(rv); + ncp = (Py_UInt32 *)PyString_AsString(rv); for ( i=0; i < nlen; i++ ) { value = *cp++; diff --git a/Modules/rgbimgmodule.c b/Modules/rgbimgmodule.c index 36f6419..94b055d 100644 --- a/Modules/rgbimgmodule.c +++ b/Modules/rgbimgmodule.c @@ -16,6 +16,18 @@ */ #include "Python.h" +#if SIZEOF_INT == 4 +typedef int Py_Int32; +typedef unsigned int Py_UInt32; +#else +#if SIZEOF_LONG == 4 +typedef long Py_Int32; +typedef unsigned long Py_UInt32; +#else +#error "No 4-byte integral type" +#endif +#endif + #ifdef HAVE_UNISTD_H #include #endif @@ -32,13 +44,13 @@ typedef struct { unsigned short xsize; unsigned short ysize; unsigned short zsize; - unsigned long min; - unsigned long max; - unsigned long wastebytes; + Py_UInt32 min; + Py_UInt32 max; + Py_UInt32 wastebytes; char name[80]; - unsigned long colormap; + Py_UInt32 colormap; - long file; /* stuff used in core only */ + Py_Int32 file; /* stuff used in core only */ unsigned short flags; short dorev; short x; @@ -48,10 +60,10 @@ typedef struct { unsigned short *ptr; unsigned short *base; unsigned short *tmpbuf; - unsigned long offset; - unsigned long rleend; /* for rle images */ - unsigned long *rowstart; /* for rle images */ - long *rowsize; /* for rle images */ + Py_UInt32 offset; + Py_UInt32 rleend; /* for rle images */ + Py_UInt32 *rowstart; /* for rle images */ + Py_Int32 *rowsize; /* for rle images */ } IMAGE; #define IMAGIC 0732 @@ -85,7 +97,7 @@ typedef struct { static void expandrow Py_PROTO((unsigned char *, unsigned char *, int)); static void setalpha Py_PROTO((unsigned char *, int)); -static void copybw Py_PROTO((long *, int)); +static void copybw Py_PROTO((Py_Int32 *, int)); static void interleaverow Py_PROTO((unsigned char*, unsigned char*, int, int)); static int compressrow Py_PROTO((unsigned char *, unsigned char *, int, int)); static void lumrow Py_PROTO((unsigned char *, unsigned char *, int)); @@ -108,7 +120,7 @@ static int reverse_order; */ static void addlongimgtag(dptr, xsize, ysize) - unsigned long *dptr; + Py_UInt32 *dptr; int xsize, ysize; { dptr = dptr + (xsize * ysize); @@ -134,7 +146,7 @@ getshort(inf) return (buf[0] << 8) + (buf[1] << 0); } -static unsigned long +static Py_UInt32 getlong(inf) FILE *inf; { @@ -159,7 +171,7 @@ putshort(outf, val) static int putlong(outf, val) FILE *outf; - unsigned long val; + Py_UInt32 val; { unsigned char buf[4]; @@ -209,7 +221,7 @@ writeheader(outf, image) static int writetab(outf, tab, len) FILE *outf; - /*unsigned*/ long *tab; + /*unsigned*/ Py_Int32 *tab; int len; { int r = 0; @@ -224,7 +236,7 @@ writetab(outf, tab, len) static void readtab(inf, tab, len) FILE *inf; - /*unsigned*/ long *tab; + /*unsigned*/ Py_Int32 *tab; int len; { while(len) { @@ -277,7 +289,7 @@ longimagedata(self, args) char *name; unsigned char *base, *lptr; unsigned char *rledat = NULL, *verdat = NULL; - long *starttab = NULL, *lengthtab = NULL; + Py_Int32 *starttab = NULL, *lengthtab = NULL; FILE *inf = NULL; IMAGE image; int y, z, tablen; @@ -311,9 +323,9 @@ longimagedata(self, args) ysize = image.ysize; zsize = image.zsize; if (rle) { - tablen = ysize * zsize * sizeof(long); - starttab = (long *)malloc(tablen); - lengthtab = (long *)malloc(tablen); + tablen = ysize * zsize * sizeof(Py_Int32); + starttab = (Py_Int32 *)malloc(tablen); + lengthtab = (Py_Int32 *)malloc(tablen); rlebuflen = (int) (1.05 * xsize +10); rledat = (unsigned char *)malloc(rlebuflen); if (!starttab || !lengthtab || !rledat) { @@ -343,7 +355,7 @@ longimagedata(self, args) fseek(inf, 512 + 2 * tablen, SEEK_SET); cur = 512 + 2 * tablen; rv = PyString_FromStringAndSize((char *)NULL, - (xsize * ysize + TAGLEN) * sizeof(long)); + (xsize * ysize + TAGLEN) * sizeof(Py_Int32)); if (rv == NULL) goto finally; @@ -356,7 +368,7 @@ longimagedata(self, args) lptr = base; if (reverse_order) lptr += (ysize - 1) * xsize - * sizeof(unsigned long); + * sizeof(Py_UInt32); for (y = 0; y < ysize; y++) { int idx = y + z * ysize; if (cur != starttab[idx]) { @@ -376,17 +388,17 @@ longimagedata(self, args) expandrow(lptr, rledat, 3-z); if (reverse_order) lptr -= xsize - * sizeof(unsigned long); + * sizeof(Py_UInt32); else lptr += xsize - * sizeof(unsigned long); + * sizeof(Py_UInt32); } } } else { lptr = base; if (reverse_order) lptr += (ysize - 1) * xsize - * sizeof(unsigned long); + * sizeof(Py_UInt32); for (y = 0; y < ysize; y++) { for(z = 0; z < zsize; z++) { int idx = y + z * ysize; @@ -400,19 +412,19 @@ longimagedata(self, args) expandrow(lptr, rledat, 3-z); } if (reverse_order) - lptr -= xsize * sizeof(unsigned long); + lptr -= xsize * sizeof(Py_UInt32); else - lptr += xsize * sizeof(unsigned long); + lptr += xsize * sizeof(Py_UInt32); } } if (zsize == 3) setalpha(base, xsize * ysize); else if (zsize < 3) - copybw((long *) base, xsize * ysize); + copybw((Py_Int32 *) base, xsize * ysize); } else { rv = PyString_FromStringAndSize((char *) 0, - (xsize*ysize+TAGLEN)*sizeof(long)); + (xsize*ysize+TAGLEN)*sizeof(Py_Int32)); if (rv == NULL) goto finally; @@ -426,20 +438,20 @@ longimagedata(self, args) lptr = base; if (reverse_order) lptr += (ysize - 1) * xsize - * sizeof(unsigned long); + * sizeof(Py_UInt32); for (y = 0; y < ysize; y++) { fread(verdat, xsize, 1, inf); interleaverow(lptr, verdat, 3-z, xsize); if (reverse_order) - lptr -= xsize * sizeof(unsigned long); + lptr -= xsize * sizeof(Py_UInt32); else - lptr += xsize * sizeof(unsigned long); + lptr += xsize * sizeof(Py_UInt32); } } if (zsize == 3) setalpha(base, xsize * ysize); else if (zsize < 3) - copybw((long *) base, xsize * ysize); + copybw((Py_Int32 *) base, xsize * ysize); } finally: free(starttab); @@ -466,7 +478,7 @@ interleaverow(lptr, cptr, z, n) static void copybw(lptr, n) - long *lptr; + Py_Int32 *lptr; int n; { while (n >= 8) { @@ -583,7 +595,7 @@ longstoimage(self, args) FILE *outf = NULL; IMAGE image; int tablen, y, z, pos, len; - long *starttab = NULL, *lengthtab = NULL; + Py_Int32 *starttab = NULL, *lengthtab = NULL; unsigned char *rlebuf = NULL; unsigned char *lumbuf = NULL; int rlebuflen, goodwrite; @@ -599,13 +611,13 @@ longstoimage(self, args) PyErr_SetString(ImgfileError, "can't open output file"); return NULL; } - tablen = ysize * zsize * sizeof(long); + tablen = ysize * zsize * sizeof(Py_Int32); - starttab = (long *)malloc(tablen); - lengthtab = (long *)malloc(tablen); + starttab = (Py_Int32 *)malloc(tablen); + lengthtab = (Py_Int32 *)malloc(tablen); rlebuflen = (int) (1.05 * xsize + 10); rlebuf = (unsigned char *)malloc(rlebuflen); - lumbuf = (unsigned char *)malloc(xsize * sizeof(long)); + lumbuf = (unsigned char *)malloc(xsize * sizeof(Py_Int32)); if (!starttab || !lengthtab || !rlebuf || !lumbuf) { PyErr_NoMemory(); goto finally; @@ -627,7 +639,7 @@ longstoimage(self, args) pos = 512 + 2 * tablen; fseek(outf, pos, SEEK_SET); if (reverse_order) - lptr += (ysize - 1) * xsize * sizeof(unsigned long); + lptr += (ysize - 1) * xsize * sizeof(Py_UInt32); for (y = 0; y < ysize; y++) { for (z = 0; z < zsize; z++) { if (zsize == 1) { @@ -649,9 +661,9 @@ longstoimage(self, args) pos += len; } if (reverse_order) - lptr -= xsize * sizeof(unsigned long); + lptr -= xsize * sizeof(Py_UInt32); else - lptr += xsize * sizeof(unsigned long); + lptr += xsize * sizeof(Py_UInt32); } fseek(outf, 512, SEEK_SET); @@ -696,7 +708,7 @@ compressrow(lbuf, rlebuf, z, cnt) { unsigned char *iptr, *ibufend, *sptr, *optr; short todo, cc; - long count; + Py_Int32 count; lbuf += z; iptr = lbuf; -- cgit v0.12