Index: Modules/audioop.c =================================================================== --- Modules/audioop.c (revision 81078) +++ Modules/audioop.c (working copy) @@ -1,6 +1,7 @@ - /* audioopmodule - Module to detect peak values in arrays */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #if SIZEOF_INT == 4 @@ -299,10 +300,10 @@ audioop_getsample(PyObject *self, PyObject *args) { signed char *cp; - int len, size, val = 0; - int i; + Py_ssize_t len, i; + int size, val = 0; - if ( !PyArg_ParseTuple(args, "s#ii:getsample", &cp, &len, &size, &i) ) + if ( !PyArg_ParseTuple(args, "s#in:getsample", &cp, &len, &size, &i) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -322,8 +323,8 @@ audioop_max(PyObject *self, PyObject *args) { signed char *cp; - int len, size, val = 0; - int i; + Py_ssize_t len, i; + int size, val = 0; int max = 0; if ( !PyArg_ParseTuple(args, "s#i:max", &cp, &len, &size) ) @@ -346,8 +347,8 @@ audioop_minmax(PyObject *self, PyObject *args) { signed char *cp; - int len, size, val = 0; - int i; + Py_ssize_t len, i; + int size, val = 0; int min = 0x7fffffff, max = -0x7fffffff; if (!PyArg_ParseTuple(args, "s#i:minmax", &cp, &len, &size)) @@ -370,8 +371,8 @@ audioop_avg(PyObject *self, PyObject *args) { signed char *cp; - int len, size, val = 0; - int i; + Py_ssize_t len, i; + int size, val = 0; double avg = 0.0; if ( !PyArg_ParseTuple(args, "s#i:avg", &cp, &len, &size) ) @@ -397,8 +398,8 @@ audioop_rms(PyObject *self, PyObject *args) { signed char *cp; - int len, size, val = 0; - int i; + Py_ssize_t len, i; + int size, val = 0; double sum_squares = 0.0; if ( !PyArg_ParseTuple(args, "s#i:rms", &cp, &len, &size) ) @@ -420,9 +421,9 @@ return PyLong_FromLong(val); } -static double _sum2(short *a, short *b, int len) +static double _sum2(short *a, short *b, Py_ssize_t len) { - int i; + Py_ssize_t i; double sum = 0.0; for( i=0; i INT_MAX/2) { + if (len > PY_SSIZE_T_MAX/2) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0; @@ -893,9 +895,9 @@ audioop_add(PyObject *self, PyObject *args) { signed char *cp1, *cp2, *ncp; - int len1, len2, size, val1 = 0, val2 = 0, maxval, newval; + Py_ssize_t len1, len2, i; + int size, val1 = 0, val2 = 0, maxval, newval; PyObject *rv; - int i; if ( !PyArg_ParseTuple(args, "s#s#i:add", &cp1, &len1, &cp2, &len2, &size ) ) @@ -946,9 +948,9 @@ audioop_bias(PyObject *self, PyObject *args) { signed char *cp, *ncp; - int len, size, val = 0; + Py_ssize_t len, i; + int size, val = 0; PyObject *rv; - int i; int bias; if ( !PyArg_ParseTuple(args, "s#ii:bias", @@ -983,9 +985,9 @@ { signed char *cp; unsigned char *ncp; - int len, size, val = 0; + Py_ssize_t len, i, j; + int size, val = 0; PyObject *rv; - int i, j; if ( !PyArg_ParseTuple(args, "s#i:reverse", &cp, &len, &size) ) @@ -1020,9 +1022,9 @@ { signed char *cp; unsigned char *ncp; - int len, size, size2, val = 0; + Py_ssize_t len, i, j; + int size, size2, val = 0; PyObject *rv; - int i, j; if ( !PyArg_ParseTuple(args, "s#ii:lin2lin", &cp, &len, &size, &size2) ) @@ -1034,7 +1036,7 @@ return 0; } - if (len/size > INT_MAX/size2) { + if (len/size > PY_SSIZE_T_MAX/size2) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0; @@ -1071,7 +1073,8 @@ audioop_ratecv(PyObject *self, PyObject *args) { char *cp, *ncp; - int len, size, nchannels, inrate, outrate, weightA, weightB; + Py_ssize_t len; + int size, nchannels, inrate, outrate, weightA, weightB; int chan, d, *prev_i, *cur_i, cur_o; PyObject *state, *samps, *str, *rv = NULL; int bytes_per_frame; @@ -1161,9 +1164,9 @@ requires bytes_per_frame bytes. Computing this without spurious overflow is the challenge; we can settle for a reasonable upper bound, though. */ - int ceiling; /* the number of output frames */ - int nbytes; /* the number of output bytes needed */ - int q = len / inrate; + Py_ssize_t ceiling; /* the number of output frames */ + Py_ssize_t nbytes; /* the number of output bytes needed */ + Py_ssize_t q = len / inrate; /* Now len = q * inrate + r exactly (with r = len % inrate), and this is less than q * inrate + inrate = (q+1)*inrate. So a reasonable upper bound on len*outrate/inrate is @@ -1203,7 +1206,7 @@ goto exit; /* We have checked before that the length * of the string fits into int. */ - len = (int)(ncp - PyBytes_AsString(str)); + len = (Py_ssize_t)(ncp - PyBytes_AsString(str)); rv = PyBytes_FromStringAndSize (PyBytes_AsString(str), len); Py_DECREF(str); @@ -1262,9 +1265,9 @@ { signed char *cp; unsigned char *ncp; - int len, size, val = 0; + Py_ssize_t len, i; + int size, val = 0; PyObject *rv; - int i; if ( !PyArg_ParseTuple(args, "s#i:lin2ulaw", &cp, &len, &size) ) @@ -1296,9 +1299,9 @@ unsigned char *cp; unsigned char cval; signed char *ncp; - int len, size, val; + Py_ssize_t len, i; + int size, val; PyObject *rv; - int i; if ( !PyArg_ParseTuple(args, "s#i:ulaw2lin", &cp, &len, &size) ) @@ -1309,7 +1312,7 @@ return 0; } - if (len > INT_MAX/size) { + if (len > PY_SSIZE_T_MAX/size) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0; @@ -1335,9 +1338,9 @@ { signed char *cp; unsigned char *ncp; - int len, size, val = 0; + Py_ssize_t len, i; + int size, val = 0; PyObject *rv; - int i; if ( !PyArg_ParseTuple(args, "s#i:lin2alaw", &cp, &len, &size) ) @@ -1369,9 +1372,9 @@ unsigned char *cp; unsigned char cval; signed char *ncp; - int len, size, val; + Py_ssize_t len, i; + int size, val; PyObject *rv; - int i; if ( !PyArg_ParseTuple(args, "s#i:alaw2lin", &cp, &len, &size) ) @@ -1382,7 +1385,7 @@ return 0; } - if (len > INT_MAX/size) { + if (len > PY_SSIZE_T_MAX/size) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0; @@ -1408,10 +1411,11 @@ { signed char *cp; signed char *ncp; - int len, size, val = 0, step, valpred, delta, + Py_ssize_t len, i; + int size, val = 0, step, valpred, delta, index, sign, vpdiff, diff; PyObject *rv, *state, *str; - int i, outputbuffer = 0, bufferstep; + int outputbuffer = 0, bufferstep; if ( !PyArg_ParseTuple(args, "s#iO:lin2adpcm", &cp, &len, &size, &state) ) @@ -1517,9 +1521,10 @@ { signed char *cp; signed char *ncp; - int len, size, valpred, step, delta, index, sign, vpdiff; + Py_ssize_t len, i; + int size, valpred, step, delta, index, sign, vpdiff; PyObject *rv, *str, *state; - int i, inputbuffer = 0, bufferstep; + int inputbuffer = 0, bufferstep; if ( !PyArg_ParseTuple(args, "s#iO:adpcm2lin", &cp, &len, &size, &state) ) @@ -1539,7 +1544,7 @@ } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) ) return 0; - if (len > (INT_MAX/2)/size) { + if (len > (PY_SSIZE_T_MAX/2)/size) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0;