Skip to content

Commit

Permalink
Purported fixes for 64-bit platforms with help from John Jorgensen
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.python.org/projects/python/trunk@10610 6015fed2-1504-0410-9fe1-9d1591cc4771
  • Loading branch information
guido committed Apr 23, 1998
1 parent 1729c2f commit 2299700
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 69 deletions.
36 changes: 24 additions & 12 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down Expand Up @@ -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))



Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
42 changes: 27 additions & 15 deletions Modules/imageop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand Down
Loading

0 comments on commit 2299700

Please sign in to comment.