Kaydet (Commit) 69011962 authored tarafından Guido van Rossum's avatar Guido van Rossum

Purported fixes for 64-bit platforms with help from John Jorgensen

üst 115f517f
...@@ -33,6 +33,18 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -33,6 +33,18 @@ PERFORMANCE OF THIS SOFTWARE.
#include "Python.h" #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(__CHAR_UNSIGNED__)
#if defined(signed) #if defined(signed)
!ERROR!; READ THE SOURCE FILE!; !ERROR!; READ THE SOURCE FILE!;
...@@ -164,7 +176,7 @@ static int stepsizeTable[89] = { ...@@ -164,7 +176,7 @@ static int stepsizeTable[89] = {
#define CHARP(cp, i) ((signed char *)(cp+i)) #define CHARP(cp, i) ((signed char *)(cp+i))
#define SHORTP(cp, i) ((short *)(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) ...@@ -670,7 +682,7 @@ audioop_mul(self, args)
val = (int)fval; val = (int)fval;
if ( size == 1 ) *CHARP(ncp, i) = (signed char)val; if ( size == 1 ) *CHARP(ncp, i) = (signed char)val;
else if ( size == 2 ) *SHORTP(ncp, i) = (short)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; return rv;
} }
...@@ -716,7 +728,7 @@ audioop_tomono(self, args) ...@@ -716,7 +728,7 @@ audioop_tomono(self, args)
val1 = (int)fval; val1 = (int)fval;
if ( size == 1 ) *CHARP(ncp, i/2) = (signed char)val1; if ( size == 1 ) *CHARP(ncp, i/2) = (signed char)val1;
else if ( size == 2 ) *SHORTP(ncp, i/2) = (short)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; return rv;
} }
...@@ -766,11 +778,11 @@ audioop_tostereo(self, args) ...@@ -766,11 +778,11 @@ audioop_tostereo(self, args)
if ( size == 1 ) *CHARP(ncp, i*2) = (signed char)val1; if ( size == 1 ) *CHARP(ncp, i*2) = (signed char)val1;
else if ( size == 2 ) *SHORTP(ncp, i*2) = (short)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; 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 == 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; return rv;
} }
...@@ -825,7 +837,7 @@ audioop_add(self, args) ...@@ -825,7 +837,7 @@ audioop_add(self, args)
if ( size == 1 ) *CHARP(ncp, i) = (signed char)newval; if ( size == 1 ) *CHARP(ncp, i) = (signed char)newval;
else if ( size == 2 ) *SHORTP(ncp, i) = (short)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; return rv;
} }
...@@ -863,7 +875,7 @@ audioop_bias(self, args) ...@@ -863,7 +875,7 @@ audioop_bias(self, args)
if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val+bias); if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val+bias);
else if ( size == 2 ) *SHORTP(ncp, i) = (short)(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; return rv;
} }
...@@ -902,7 +914,7 @@ audioop_reverse(self, args) ...@@ -902,7 +914,7 @@ audioop_reverse(self, args)
if ( size == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); if ( size == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8);
else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val); 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; return rv;
} }
...@@ -940,7 +952,7 @@ audioop_lin2lin(self, args) ...@@ -940,7 +952,7 @@ audioop_lin2lin(self, args)
if ( size2 == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); if ( size2 == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8);
else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val); 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; return rv;
} }
...@@ -1080,7 +1092,7 @@ audioop_ratecv(self, args) ...@@ -1080,7 +1092,7 @@ audioop_ratecv(self, args)
else if (size == 2) else if (size == 2)
*SHORTP(ncp, 0) = (short)(cur_o); *SHORTP(ncp, 0) = (short)(cur_o);
else if (size == 4) else if (size == 4)
*LONGP(ncp, 0) = (long)(cur_o<<16); *LONGP(ncp, 0) = (Py_Int32)(cur_o<<16);
ncp += size; ncp += size;
} }
d -= inrate; d -= inrate;
...@@ -1155,7 +1167,7 @@ audioop_ulaw2lin(self, args) ...@@ -1155,7 +1167,7 @@ audioop_ulaw2lin(self, args)
if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val >> 8); if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val >> 8);
else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val); 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; return rv;
} }
...@@ -1355,7 +1367,7 @@ audioop_adpcm2lin(self, args) ...@@ -1355,7 +1367,7 @@ audioop_adpcm2lin(self, args)
/* Step 6 - Output value */ /* Step 6 - Output value */
if ( size == 1 ) *CHARP(ncp, i) = (signed char)(valpred >> 8); if ( size == 1 ) *CHARP(ncp, i) = (signed char)(valpred >> 8);
else if ( size == 2 ) *SHORTP(ncp, i) = (short)(valpred); 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); rv = Py_BuildValue("(O(ii))", str, valpred, index);
......
...@@ -37,9 +37,21 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -37,9 +37,21 @@ PERFORMANCE OF THIS SOFTWARE.
#include "Python.h" #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 CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x))
#define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(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; static PyObject *ImageopError;
...@@ -50,7 +62,7 @@ PyObject *args; ...@@ -50,7 +62,7 @@ PyObject *args;
{ {
char *cp, *ncp; char *cp, *ncp;
short *nsp; short *nsp;
long *nlp; Py_Int32 *nlp;
int len, size, x, y, newx1, newx2, newy1, newy2; int len, size, x, y, newx1, newx2, newy1, newy2;
int ix, iy, xstep, ystep; int ix, iy, xstep, ystep;
PyObject *rv; PyObject *rv;
...@@ -76,7 +88,7 @@ PyObject *args; ...@@ -76,7 +88,7 @@ PyObject *args;
return 0; return 0;
ncp = (char *)PyString_AsString(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (long *)ncp; nlp = (Py_Int32 *)ncp;
newy2 += ystep; newy2 += ystep;
newx2 += xstep; newx2 += xstep;
for( iy = newy1; iy != newy2; iy+=ystep ) { for( iy = newy1; iy != newy2; iy+=ystep ) {
...@@ -106,7 +118,7 @@ PyObject *args; ...@@ -106,7 +118,7 @@ PyObject *args;
{ {
char *cp, *ncp; char *cp, *ncp;
short *nsp; short *nsp;
long *nlp; Py_Int32 *nlp;
int len, size, x, y, newx, newy; int len, size, x, y, newx, newy;
int ix, iy; int ix, iy;
int oix, oiy; int oix, oiy;
...@@ -130,7 +142,7 @@ PyObject *args; ...@@ -130,7 +142,7 @@ PyObject *args;
return 0; return 0;
ncp = (char *)PyString_AsString(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (long *)ncp; nlp = (Py_Int32 *)ncp;
for( iy = 0; iy < newy; iy++ ) { for( iy = 0; iy < newy; iy++ ) {
for ( ix = 0; ix < newx; ix++ ) { for ( ix = 0; ix < newx; ix++ ) {
oix = ix * x / newx; oix = ix * x / newx;
...@@ -539,11 +551,11 @@ imageop_rgb2rgb8(self, args) ...@@ -539,11 +551,11 @@ imageop_rgb2rgb8(self, args)
PyObject *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned long *cp; Py_UInt32 *cp;
unsigned char *ncp; unsigned char *ncp;
PyObject *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; Py_UInt32 value, nvalue;
if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
...@@ -584,10 +596,10 @@ PyObject *args; ...@@ -584,10 +596,10 @@ PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp; unsigned char *cp;
unsigned long *ncp; Py_UInt32 *ncp;
PyObject *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; Py_UInt32 value, nvalue;
if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
...@@ -601,7 +613,7 @@ PyObject *args; ...@@ -601,7 +613,7 @@ PyObject *args;
rv = PyString_FromStringAndSize(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned long *)PyString_AsString(rv); ncp = (Py_UInt32 *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
/* Bits in source: RRRBBGGG /* Bits in source: RRRBBGGG
...@@ -626,11 +638,11 @@ imageop_rgb2grey(self, args) ...@@ -626,11 +638,11 @@ imageop_rgb2grey(self, args)
PyObject *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned long *cp; Py_UInt32 *cp;
unsigned char *ncp; unsigned char *ncp;
PyObject *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; Py_UInt32 value, nvalue;
if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
...@@ -665,10 +677,10 @@ PyObject *args; ...@@ -665,10 +677,10 @@ PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp; unsigned char *cp;
unsigned long *ncp; Py_UInt32 *ncp;
PyObject *rv; PyObject *rv;
int i; int i;
unsigned long value; Py_UInt32 value;
if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
...@@ -682,7 +694,7 @@ PyObject *args; ...@@ -682,7 +694,7 @@ PyObject *args;
rv = PyString_FromStringAndSize(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned long *)PyString_AsString(rv); ncp = (Py_UInt32 *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
value = *cp++; value = *cp++;
......
...@@ -16,6 +16,18 @@ ...@@ -16,6 +16,18 @@
*/ */
#include "Python.h" #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 #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
...@@ -32,13 +44,13 @@ typedef struct { ...@@ -32,13 +44,13 @@ typedef struct {
unsigned short xsize; unsigned short xsize;
unsigned short ysize; unsigned short ysize;
unsigned short zsize; unsigned short zsize;
unsigned long min; Py_UInt32 min;
unsigned long max; Py_UInt32 max;
unsigned long wastebytes; Py_UInt32 wastebytes;
char name[80]; 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; unsigned short flags;
short dorev; short dorev;
short x; short x;
...@@ -48,10 +60,10 @@ typedef struct { ...@@ -48,10 +60,10 @@ typedef struct {
unsigned short *ptr; unsigned short *ptr;
unsigned short *base; unsigned short *base;
unsigned short *tmpbuf; unsigned short *tmpbuf;
unsigned long offset; Py_UInt32 offset;
unsigned long rleend; /* for rle images */ Py_UInt32 rleend; /* for rle images */
unsigned long *rowstart; /* for rle images */ Py_UInt32 *rowstart; /* for rle images */
long *rowsize; /* for rle images */ Py_Int32 *rowsize; /* for rle images */
} IMAGE; } IMAGE;
#define IMAGIC 0732 #define IMAGIC 0732
...@@ -85,7 +97,7 @@ typedef struct { ...@@ -85,7 +97,7 @@ typedef struct {
static void expandrow Py_PROTO((unsigned char *, unsigned char *, int)); static void expandrow Py_PROTO((unsigned char *, unsigned char *, int));
static void setalpha Py_PROTO((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 void interleaverow Py_PROTO((unsigned char*, unsigned char*, int, int));
static int compressrow 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)); static void lumrow Py_PROTO((unsigned char *, unsigned char *, int));
...@@ -108,7 +120,7 @@ static int reverse_order; ...@@ -108,7 +120,7 @@ static int reverse_order;
*/ */
static void static void
addlongimgtag(dptr, xsize, ysize) addlongimgtag(dptr, xsize, ysize)
unsigned long *dptr; Py_UInt32 *dptr;
int xsize, ysize; int xsize, ysize;
{ {
dptr = dptr + (xsize * ysize); dptr = dptr + (xsize * ysize);
...@@ -134,7 +146,7 @@ getshort(inf) ...@@ -134,7 +146,7 @@ getshort(inf)
return (buf[0] << 8) + (buf[1] << 0); return (buf[0] << 8) + (buf[1] << 0);
} }
static unsigned long static Py_UInt32
getlong(inf) getlong(inf)
FILE *inf; FILE *inf;
{ {
...@@ -159,7 +171,7 @@ putshort(outf, val) ...@@ -159,7 +171,7 @@ putshort(outf, val)
static int static int
putlong(outf, val) putlong(outf, val)
FILE *outf; FILE *outf;
unsigned long val; Py_UInt32 val;
{ {
unsigned char buf[4]; unsigned char buf[4];
...@@ -209,7 +221,7 @@ writeheader(outf, image) ...@@ -209,7 +221,7 @@ writeheader(outf, image)
static int static int
writetab(outf, tab, len) writetab(outf, tab, len)
FILE *outf; FILE *outf;
/*unsigned*/ long *tab; /*unsigned*/ Py_Int32 *tab;
int len; int len;
{ {
int r = 0; int r = 0;
...@@ -224,7 +236,7 @@ writetab(outf, tab, len) ...@@ -224,7 +236,7 @@ writetab(outf, tab, len)
static void static void
readtab(inf, tab, len) readtab(inf, tab, len)
FILE *inf; FILE *inf;
/*unsigned*/ long *tab; /*unsigned*/ Py_Int32 *tab;
int len; int len;
{ {
while(len) { while(len) {
...@@ -277,7 +289,7 @@ longimagedata(self, args) ...@@ -277,7 +289,7 @@ longimagedata(self, args)
char *name; char *name;
unsigned char *base, *lptr; unsigned char *base, *lptr;
unsigned char *rledat = NULL, *verdat = NULL; unsigned char *rledat = NULL, *verdat = NULL;
long *starttab = NULL, *lengthtab = NULL; Py_Int32 *starttab = NULL, *lengthtab = NULL;
FILE *inf = NULL; FILE *inf = NULL;
IMAGE image; IMAGE image;
int y, z, tablen; int y, z, tablen;
...@@ -311,9 +323,9 @@ longimagedata(self, args) ...@@ -311,9 +323,9 @@ longimagedata(self, args)
ysize = image.ysize; ysize = image.ysize;
zsize = image.zsize; zsize = image.zsize;
if (rle) { if (rle) {
tablen = ysize * zsize * sizeof(long); tablen = ysize * zsize * sizeof(Py_Int32);
starttab = (long *)malloc(tablen); starttab = (Py_Int32 *)malloc(tablen);
lengthtab = (long *)malloc(tablen); lengthtab = (Py_Int32 *)malloc(tablen);
rlebuflen = (int) (1.05 * xsize +10); rlebuflen = (int) (1.05 * xsize +10);
rledat = (unsigned char *)malloc(rlebuflen); rledat = (unsigned char *)malloc(rlebuflen);
if (!starttab || !lengthtab || !rledat) { if (!starttab || !lengthtab || !rledat) {
...@@ -343,7 +355,7 @@ longimagedata(self, args) ...@@ -343,7 +355,7 @@ longimagedata(self, args)
fseek(inf, 512 + 2 * tablen, SEEK_SET); fseek(inf, 512 + 2 * tablen, SEEK_SET);
cur = 512 + 2 * tablen; cur = 512 + 2 * tablen;
rv = PyString_FromStringAndSize((char *)NULL, rv = PyString_FromStringAndSize((char *)NULL,
(xsize * ysize + TAGLEN) * sizeof(long)); (xsize * ysize + TAGLEN) * sizeof(Py_Int32));
if (rv == NULL) if (rv == NULL)
goto finally; goto finally;
...@@ -356,7 +368,7 @@ longimagedata(self, args) ...@@ -356,7 +368,7 @@ longimagedata(self, args)
lptr = base; lptr = base;
if (reverse_order) if (reverse_order)
lptr += (ysize - 1) * xsize lptr += (ysize - 1) * xsize
* sizeof(unsigned long); * sizeof(Py_UInt32);
for (y = 0; y < ysize; y++) { for (y = 0; y < ysize; y++) {
int idx = y + z * ysize; int idx = y + z * ysize;
if (cur != starttab[idx]) { if (cur != starttab[idx]) {
...@@ -376,17 +388,17 @@ longimagedata(self, args) ...@@ -376,17 +388,17 @@ longimagedata(self, args)
expandrow(lptr, rledat, 3-z); expandrow(lptr, rledat, 3-z);
if (reverse_order) if (reverse_order)
lptr -= xsize lptr -= xsize
* sizeof(unsigned long); * sizeof(Py_UInt32);
else else
lptr += xsize lptr += xsize
* sizeof(unsigned long); * sizeof(Py_UInt32);
} }
} }
} else { } else {
lptr = base; lptr = base;
if (reverse_order) if (reverse_order)
lptr += (ysize - 1) * xsize lptr += (ysize - 1) * xsize
* sizeof(unsigned long); * sizeof(Py_UInt32);
for (y = 0; y < ysize; y++) { for (y = 0; y < ysize; y++) {
for(z = 0; z < zsize; z++) { for(z = 0; z < zsize; z++) {
int idx = y + z * ysize; int idx = y + z * ysize;
...@@ -400,19 +412,19 @@ longimagedata(self, args) ...@@ -400,19 +412,19 @@ longimagedata(self, args)
expandrow(lptr, rledat, 3-z); expandrow(lptr, rledat, 3-z);
} }
if (reverse_order) if (reverse_order)
lptr -= xsize * sizeof(unsigned long); lptr -= xsize * sizeof(Py_UInt32);
else else
lptr += xsize * sizeof(unsigned long); lptr += xsize * sizeof(Py_UInt32);
} }
} }
if (zsize == 3) if (zsize == 3)
setalpha(base, xsize * ysize); setalpha(base, xsize * ysize);
else if (zsize < 3) else if (zsize < 3)
copybw((long *) base, xsize * ysize); copybw((Py_Int32 *) base, xsize * ysize);
} }
else { else {
rv = PyString_FromStringAndSize((char *) 0, rv = PyString_FromStringAndSize((char *) 0,
(xsize*ysize+TAGLEN)*sizeof(long)); (xsize*ysize+TAGLEN)*sizeof(Py_Int32));
if (rv == NULL) if (rv == NULL)
goto finally; goto finally;
...@@ -426,20 +438,20 @@ longimagedata(self, args) ...@@ -426,20 +438,20 @@ longimagedata(self, args)
lptr = base; lptr = base;
if (reverse_order) if (reverse_order)
lptr += (ysize - 1) * xsize lptr += (ysize - 1) * xsize
* sizeof(unsigned long); * sizeof(Py_UInt32);
for (y = 0; y < ysize; y++) { for (y = 0; y < ysize; y++) {
fread(verdat, xsize, 1, inf); fread(verdat, xsize, 1, inf);
interleaverow(lptr, verdat, 3-z, xsize); interleaverow(lptr, verdat, 3-z, xsize);
if (reverse_order) if (reverse_order)
lptr -= xsize * sizeof(unsigned long); lptr -= xsize * sizeof(Py_UInt32);
else else
lptr += xsize * sizeof(unsigned long); lptr += xsize * sizeof(Py_UInt32);
} }
} }
if (zsize == 3) if (zsize == 3)
setalpha(base, xsize * ysize); setalpha(base, xsize * ysize);
else if (zsize < 3) else if (zsize < 3)
copybw((long *) base, xsize * ysize); copybw((Py_Int32 *) base, xsize * ysize);
} }
finally: finally:
free(starttab); free(starttab);
...@@ -466,7 +478,7 @@ interleaverow(lptr, cptr, z, n) ...@@ -466,7 +478,7 @@ interleaverow(lptr, cptr, z, n)
static void static void
copybw(lptr, n) copybw(lptr, n)
long *lptr; Py_Int32 *lptr;
int n; int n;
{ {
while (n >= 8) { while (n >= 8) {
...@@ -583,7 +595,7 @@ longstoimage(self, args) ...@@ -583,7 +595,7 @@ longstoimage(self, args)
FILE *outf = NULL; FILE *outf = NULL;
IMAGE image; IMAGE image;
int tablen, y, z, pos, len; int tablen, y, z, pos, len;
long *starttab = NULL, *lengthtab = NULL; Py_Int32 *starttab = NULL, *lengthtab = NULL;
unsigned char *rlebuf = NULL; unsigned char *rlebuf = NULL;
unsigned char *lumbuf = NULL; unsigned char *lumbuf = NULL;
int rlebuflen, goodwrite; int rlebuflen, goodwrite;
...@@ -599,13 +611,13 @@ longstoimage(self, args) ...@@ -599,13 +611,13 @@ longstoimage(self, args)
PyErr_SetString(ImgfileError, "can't open output file"); PyErr_SetString(ImgfileError, "can't open output file");
return NULL; return NULL;
} }
tablen = ysize * zsize * sizeof(long); tablen = ysize * zsize * sizeof(Py_Int32);
starttab = (long *)malloc(tablen); starttab = (Py_Int32 *)malloc(tablen);
lengthtab = (long *)malloc(tablen); lengthtab = (Py_Int32 *)malloc(tablen);
rlebuflen = (int) (1.05 * xsize + 10); rlebuflen = (int) (1.05 * xsize + 10);
rlebuf = (unsigned char *)malloc(rlebuflen); 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) { if (!starttab || !lengthtab || !rlebuf || !lumbuf) {
PyErr_NoMemory(); PyErr_NoMemory();
goto finally; goto finally;
...@@ -627,7 +639,7 @@ longstoimage(self, args) ...@@ -627,7 +639,7 @@ longstoimage(self, args)
pos = 512 + 2 * tablen; pos = 512 + 2 * tablen;
fseek(outf, pos, SEEK_SET); fseek(outf, pos, SEEK_SET);
if (reverse_order) if (reverse_order)
lptr += (ysize - 1) * xsize * sizeof(unsigned long); lptr += (ysize - 1) * xsize * sizeof(Py_UInt32);
for (y = 0; y < ysize; y++) { for (y = 0; y < ysize; y++) {
for (z = 0; z < zsize; z++) { for (z = 0; z < zsize; z++) {
if (zsize == 1) { if (zsize == 1) {
...@@ -649,9 +661,9 @@ longstoimage(self, args) ...@@ -649,9 +661,9 @@ longstoimage(self, args)
pos += len; pos += len;
} }
if (reverse_order) if (reverse_order)
lptr -= xsize * sizeof(unsigned long); lptr -= xsize * sizeof(Py_UInt32);
else else
lptr += xsize * sizeof(unsigned long); lptr += xsize * sizeof(Py_UInt32);
} }
fseek(outf, 512, SEEK_SET); fseek(outf, 512, SEEK_SET);
...@@ -696,7 +708,7 @@ compressrow(lbuf, rlebuf, z, cnt) ...@@ -696,7 +708,7 @@ compressrow(lbuf, rlebuf, z, cnt)
{ {
unsigned char *iptr, *ibufend, *sptr, *optr; unsigned char *iptr, *ibufend, *sptr, *optr;
short todo, cc; short todo, cc;
long count; Py_Int32 count;
lbuf += z; lbuf += z;
iptr = lbuf; iptr = lbuf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment