summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c6
-rw-r--r--Modules/_codecsmodule.c71
-rw-r--r--Modules/_elementtree.c29
-rw-r--r--Modules/_hotshot.c19
-rw-r--r--Modules/_localemodule.c4
-rw-r--r--Modules/_testcapimodule.c3
-rw-r--r--Modules/arraymodule.c193
-rw-r--r--Modules/audioop.c4
-rw-r--r--Modules/bsddbmodule.c4
-rw-r--r--Modules/bz2module.c2
-rw-r--r--Modules/cPickle.c62
-rw-r--r--Modules/cStringIO.c55
-rw-r--r--Modules/cjkcodecs/multibytecodec.c2
-rw-r--r--Modules/collectionsmodule.c16
-rw-r--r--Modules/datetimemodule.c4
-rw-r--r--Modules/dbmmodule.c4
-rw-r--r--Modules/gcmodule.c2
-rw-r--r--Modules/gdbmmodule.c4
-rw-r--r--Modules/mmapmodule.c48
-rw-r--r--Modules/parsermodule.c11
-rw-r--r--Modules/posixmodule.c41
-rw-r--r--Modules/rgbimgmodule.c7
-rw-r--r--Modules/selectmodule.c2
-rw-r--r--Modules/shamodule.c2
-rw-r--r--Modules/stropmodule.c12
-rw-r--r--Modules/zipimport.c6
26 files changed, 338 insertions, 275 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index fca203d..9bcb334 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -1100,7 +1100,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
}
else if (PyString_Check(result)) {
char* data;
- int size;
+ Py_ssize_t size;
CLEAR_DBT(*secKey);
#if PYTHON_API_VERSION <= 1007
@@ -2614,7 +2614,7 @@ DB_set_encrypt(DBObject* self, PyObject* args, PyObject* kwargs)
/*-------------------------------------------------------------- */
/* Mapping and Dictionary-like access routines */
-int DB_length(DBObject* self)
+Py_ssize_t DB_length(DBObject* self)
{
int err;
long size = 0;
@@ -4679,7 +4679,7 @@ static PyMethodDef DB_methods[] = {
static PyMappingMethods DB_mapping = {
- (inquiry)DB_length, /*mp_length*/
+ (lenfunc)DB_length, /*mp_length*/
(binaryfunc)DB_subscript, /*mp_subscript*/
(objobjargproc)DB_ass_sub, /*mp_ass_subscript*/
};
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 8b225c3..39b443b 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -35,6 +35,7 @@ Copyright (c) Corporation for National Research Initiatives.
------------------------------------------------------------------------ */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
/* --- Registry ----------------------------------------------------------- */
@@ -196,7 +197,7 @@ escape_decode(PyObject *self,
{
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
&data, &size, &errors))
@@ -241,7 +242,7 @@ unicode_internal_decode(PyObject *self,
PyObject *obj;
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
&obj, &errors))
@@ -265,7 +266,7 @@ utf_7_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
@@ -281,15 +282,19 @@ utf_8_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
&data, &size, &errors, &final))
return NULL;
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
@@ -304,16 +309,21 @@ utf_16_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
int byteorder = 0;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
&data, &size, &errors, &final))
return NULL;
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
final ? NULL : &consumed);
@@ -327,16 +337,22 @@ utf_16_le_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
int byteorder = -1;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
&data, &size, &errors, &final))
return NULL;
+
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
&byteorder, final ? NULL : &consumed);
@@ -351,16 +367,21 @@ utf_16_be_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
int byteorder = 1;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
&data, &size, &errors, &final))
return NULL;
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
&byteorder, final ? NULL : &consumed);
@@ -382,17 +403,21 @@ utf_16_ex_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
int byteorder = 0;
PyObject *unicode, *tuple;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
&data, &size, &errors, &byteorder, &final))
return NULL;
-
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
final ? NULL : &consumed);
@@ -408,7 +433,7 @@ unicode_escape_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
@@ -424,7 +449,7 @@ raw_unicode_escape_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
@@ -440,7 +465,7 @@ latin_1_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
@@ -456,7 +481,7 @@ ascii_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
@@ -472,7 +497,7 @@ charmap_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
PyObject *mapping = NULL;
@@ -493,7 +518,7 @@ mbcs_decode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
@@ -513,7 +538,7 @@ readbuffer_encode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
@@ -529,7 +554,7 @@ charbuffer_encode(PyObject *self,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
@@ -547,7 +572,7 @@ unicode_internal_encode(PyObject *self,
PyObject *obj;
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
&obj, &errors))
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index a43fe2e..ab3ef23 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -92,6 +92,9 @@ do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0)
#endif
/* compatibility macros */
+#if (PY_VERSION_HEX < 0x02050000)
+typedef int Py_ssize_t;
+#endif
#if (PY_VERSION_HEX < 0x02040000)
#define PyDict_CheckExact PyDict_Check
#if (PY_VERSION_HEX < 0x02020000)
@@ -919,8 +922,9 @@ element_getiterator(ElementObject* self, PyObject* args)
}
static PyObject*
-element_getitem(ElementObject* self, int index)
+element_getitem(PyObject* _self, Py_ssize_t index)
{
+ ElementObject* self = (ElementObject*)_self;
if (!self->extra || index < 0 || index >= self->extra->length) {
PyErr_SetString(
PyExc_IndexError,
@@ -934,9 +938,10 @@ element_getitem(ElementObject* self, int index)
}
static PyObject*
-element_getslice(ElementObject* self, int start, int end)
+element_getslice(PyObject* _self, Py_ssize_t start, Py_ssize_t end)
{
- int i;
+ ElementObject* self = (ElementObject*)_self;
+ Py_ssize_t i;
PyObject* list;
if (!self->extra)
@@ -1022,7 +1027,7 @@ element_keys(ElementObject* self, PyObject* args)
return PyDict_Keys(self->extra->attrib);
}
-static int
+static Py_ssize_t
element_length(ElementObject* self)
{
if (!self->extra)
@@ -1161,8 +1166,9 @@ element_set(ElementObject* self, PyObject* args)
}
static int
-element_setslice(ElementObject* self, int start, int end, PyObject* item)
+element_setslice(PyObject* _self, Py_ssize_t start, Py_ssize_t end, PyObject* item)
{
+ ElementObject* self = (ElementObject*)_self;
int i, new, old;
PyObject* recycle = NULL;
@@ -1231,8 +1237,9 @@ element_setslice(ElementObject* self, int start, int end, PyObject* item)
}
static int
-element_setitem(ElementObject* self, int index, PyObject* item)
+element_setitem(PyObject* _self, Py_ssize_t index, PyObject* item)
{
+ ElementObject* self = (ElementObject*)_self;
int i;
PyObject* old;
@@ -1371,13 +1378,13 @@ element_setattr(ElementObject* self, const char* name, PyObject* value)
}
static PySequenceMethods element_as_sequence = {
- (inquiry) element_length,
+ (lenfunc) element_length,
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc) element_getitem,
- (intintargfunc) element_getslice,
- (intobjargproc) element_setitem,
- (intintobjargproc) element_setslice,
+ element_getitem,
+ element_getslice,
+ element_setitem,
+ element_setslice,
};
statichere PyTypeObject Element_Type = {
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 758c4ee..162a319 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -71,7 +71,7 @@ typedef struct {
PyObject_HEAD
PyObject *filemap;
PyObject *logfilename;
- int index;
+ Py_ssize_t index;
unsigned char buffer[BUFFERSIZE];
FILE *logfp;
int lineevents;
@@ -526,7 +526,7 @@ logreader_dealloc(LogReaderObject *self)
}
static PyObject *
-logreader_sq_item(LogReaderObject *self, int index)
+logreader_sq_item(LogReaderObject *self, Py_ssize_t index)
{
PyObject *result = logreader_tp_iternext(self);
if (result == NULL && !PyErr_Occurred()) {
@@ -610,13 +610,14 @@ pack_modified_packed_int(ProfilerObject *self, int value,
}
static int
-pack_string(ProfilerObject *self, const char *s, int len)
+pack_string(ProfilerObject *self, const char *s, Py_ssize_t len)
{
if (len + PISIZE + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
return -1;
}
- if (pack_packed_int(self, len) < 0)
+ assert(len < INT_MAX);
+ if (pack_packed_int(self, (int)len) < 0)
return -1;
memcpy(self->buffer + self->index, s, len);
self->index += len;
@@ -626,8 +627,8 @@ pack_string(ProfilerObject *self, const char *s, int len)
static int
pack_add_info(ProfilerObject *self, const char *s1, const char *s2)
{
- int len1 = strlen(s1);
- int len2 = strlen(s2);
+ Py_ssize_t len1 = strlen(s1);
+ Py_ssize_t len2 = strlen(s2);
if (len1 + len2 + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -643,7 +644,7 @@ pack_add_info(ProfilerObject *self, const char *s1, const char *s2)
static int
pack_define_file(ProfilerObject *self, int fileno, const char *filename)
{
- int len = strlen(filename);
+ Py_ssize_t len = strlen(filename);
if (len + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -660,7 +661,7 @@ static int
pack_define_func(ProfilerObject *self, int fileno, int lineno,
const char *funcname)
{
- int len = strlen(funcname);
+ Py_ssize_t len = strlen(funcname);
if (len + PISIZE*3 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -1269,7 +1270,7 @@ static PySequenceMethods logreader_as_sequence = {
0, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)logreader_sq_item, /* sq_item */
+ (ssizeargfunc)logreader_sq_item, /* sq_item */
0, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 2d84d80..e3d1e7f 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -382,11 +382,11 @@ PyLocale_getdefaultlocale(PyObject* self)
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO639LANGNAME,
locale, sizeof(locale))) {
- int i = strlen(locale);
+ Py_ssize_t i = strlen(locale);
locale[i++] = '_';
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME,
- locale+i, sizeof(locale)-i))
+ locale+i, (int)(sizeof(locale)-i)))
return Py_BuildValue("ss", locale, encoding);
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index c008b87..913c49a 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -115,7 +115,8 @@ test_list_api(PyObject *self)
static int
test_dict_inner(int count)
{
- int pos = 0, iterations = 0, i;
+ Py_ssize_t pos = 0, iterations = 0;
+ int i;
PyObject *dict = PyDict_New();
PyObject *v, *k;
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 4c7cdf2..704b745 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -3,6 +3,7 @@
/* An array is a uniform list -- all items have the same type.
The item type is restricted to simple C types like int or float */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
@@ -23,15 +24,15 @@ struct arrayobject; /* Forward */
struct arraydescr {
int typecode;
int itemsize;
- PyObject * (*getitem)(struct arrayobject *, int);
- int (*setitem)(struct arrayobject *, int, PyObject *);
+ PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
+ int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
};
typedef struct arrayobject {
PyObject_HEAD
- int ob_size;
+ Py_ssize_t ob_size;
char *ob_item;
- int allocated;
+ Py_ssize_t allocated;
struct arraydescr *ob_descr;
PyObject *weakreflist; /* List of weak references */
} arrayobject;
@@ -42,7 +43,7 @@ static PyTypeObject Arraytype;
#define array_CheckExact(op) ((op)->ob_type == &Arraytype)
static int
-array_resize(arrayobject *self, int newsize)
+array_resize(arrayobject *self, Py_ssize_t newsize)
{
char *items;
size_t _new_size;
@@ -102,13 +103,13 @@ in bounds; that's the responsibility of the caller.
****************************************************************************/
static PyObject *
-c_getitem(arrayobject *ap, int i)
+c_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
}
static int
-c_setitem(arrayobject *ap, int i, PyObject *v)
+c_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
char x;
if (!PyArg_Parse(v, "c;array item must be char", &x))
@@ -119,7 +120,7 @@ c_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-b_getitem(arrayobject *ap, int i)
+b_getitem(arrayobject *ap, Py_ssize_t i)
{
long x = ((char *)ap->ob_item)[i];
if (x >= 128)
@@ -128,7 +129,7 @@ b_getitem(arrayobject *ap, int i)
}
static int
-b_setitem(arrayobject *ap, int i, PyObject *v)
+b_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
short x;
/* PyArg_Parse's 'b' formatter is for an unsigned char, therefore
@@ -152,14 +153,14 @@ b_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-BB_getitem(arrayobject *ap, int i)
+BB_getitem(arrayobject *ap, Py_ssize_t i)
{
long x = ((unsigned char *)ap->ob_item)[i];
return PyInt_FromLong(x);
}
static int
-BB_setitem(arrayobject *ap, int i, PyObject *v)
+BB_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned char x;
/* 'B' == unsigned char, maps to PyArg_Parse's 'b' formatter */
@@ -172,16 +173,16 @@ BB_setitem(arrayobject *ap, int i, PyObject *v)
#ifdef Py_USING_UNICODE
static PyObject *
-u_getitem(arrayobject *ap, int i)
+u_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1);
}
static int
-u_setitem(arrayobject *ap, int i, PyObject *v)
+u_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
Py_UNICODE *p;
- int len;
+ Py_ssize_t len;
if (!PyArg_Parse(v, "u#;array item must be unicode character", &p, &len))
return -1;
@@ -196,13 +197,13 @@ u_setitem(arrayobject *ap, int i, PyObject *v)
#endif
static PyObject *
-h_getitem(arrayobject *ap, int i)
+h_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((short *)ap->ob_item)[i]);
}
static int
-h_setitem(arrayobject *ap, int i, PyObject *v)
+h_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
short x;
/* 'h' == signed short, maps to PyArg_Parse's 'h' formatter */
@@ -214,13 +215,13 @@ h_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-HH_getitem(arrayobject *ap, int i)
+HH_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((unsigned short *)ap->ob_item)[i]);
}
static int
-HH_setitem(arrayobject *ap, int i, PyObject *v)
+HH_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
int x;
/* PyArg_Parse's 'h' formatter is for a signed short, therefore
@@ -243,13 +244,13 @@ HH_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-i_getitem(arrayobject *ap, int i)
+i_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((int *)ap->ob_item)[i]);
}
static int
-i_setitem(arrayobject *ap, int i, PyObject *v)
+i_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
int x;
/* 'i' == signed int, maps to PyArg_Parse's 'i' formatter */
@@ -261,14 +262,14 @@ i_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-II_getitem(arrayobject *ap, int i)
+II_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(
(unsigned long) ((unsigned int *)ap->ob_item)[i]);
}
static int
-II_setitem(arrayobject *ap, int i, PyObject *v)
+II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned long x;
if (PyLong_Check(v)) {
@@ -300,13 +301,13 @@ II_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-l_getitem(arrayobject *ap, int i)
+l_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong(((long *)ap->ob_item)[i]);
}
static int
-l_setitem(arrayobject *ap, int i, PyObject *v)
+l_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
long x;
if (!PyArg_Parse(v, "l;array item must be integer", &x))
@@ -317,13 +318,13 @@ l_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-LL_getitem(arrayobject *ap, int i)
+LL_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(((unsigned long *)ap->ob_item)[i]);
}
static int
-LL_setitem(arrayobject *ap, int i, PyObject *v)
+LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned long x;
if (PyLong_Check(v)) {
@@ -355,13 +356,13 @@ LL_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-f_getitem(arrayobject *ap, int i)
+f_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyFloat_FromDouble((double) ((float *)ap->ob_item)[i]);
}
static int
-f_setitem(arrayobject *ap, int i, PyObject *v)
+f_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
float x;
if (!PyArg_Parse(v, "f;array item must be float", &x))
@@ -372,13 +373,13 @@ f_setitem(arrayobject *ap, int i, PyObject *v)
}
static PyObject *
-d_getitem(arrayobject *ap, int i)
+d_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyFloat_FromDouble(((double *)ap->ob_item)[i]);
}
static int
-d_setitem(arrayobject *ap, int i, PyObject *v)
+d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
double x;
if (!PyArg_Parse(v, "d;array item must be float", &x))
@@ -412,7 +413,7 @@ Implementations of array object methods.
****************************************************************************/
static PyObject *
-newarrayobject(PyTypeObject *type, int size, struct arraydescr *descr)
+newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
{
arrayobject *op;
size_t nbytes;
@@ -449,7 +450,7 @@ newarrayobject(PyTypeObject *type, int size, struct arraydescr *descr)
}
static PyObject *
-getarrayitem(PyObject *op, int i)
+getarrayitem(PyObject *op, Py_ssize_t i)
{
register arrayobject *ap;
assert(array_Check(op));
@@ -459,10 +460,10 @@ getarrayitem(PyObject *op, int i)
}
static int
-ins1(arrayobject *self, int where, PyObject *v)
+ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
{
char *items;
- int n = self->ob_size;
+ Py_ssize_t n = self->ob_size;
if (v == NULL) {
PyErr_BadInternalCall();
return -1;
@@ -506,7 +507,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
arrayobject *va, *wa;
PyObject *vi = NULL;
PyObject *wi = NULL;
- int i, k;
+ Py_ssize_t i, k;
PyObject *res;
if (!array_Check(v) || !array_Check(w)) {
@@ -548,8 +549,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
if (k) {
/* No more items to compare -- compare sizes */
- int vs = va->ob_size;
- int ws = wa->ob_size;
+ Py_ssize_t vs = va->ob_size;
+ Py_ssize_t ws = wa->ob_size;
int cmp;
switch (op) {
case Py_LT: cmp = vs < ws; break;
@@ -586,14 +587,14 @@ array_richcompare(PyObject *v, PyObject *w, int op)
return res;
}
-static int
+static Py_ssize_t
array_length(arrayobject *a)
{
return a->ob_size;
}
static PyObject *
-array_item(arrayobject *a, int i)
+array_item(arrayobject *a, Py_ssize_t i)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError, "array index out of range");
@@ -603,7 +604,7 @@ array_item(arrayobject *a, int i)
}
static PyObject *
-array_slice(arrayobject *a, int ilow, int ihigh)
+array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
{
arrayobject *np;
if (ilow < 0)
@@ -638,7 +639,7 @@ PyDoc_STRVAR(copy_doc,
static PyObject *
array_concat(arrayobject *a, PyObject *bb)
{
- int size;
+ Py_ssize_t size;
arrayobject *np;
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
@@ -664,13 +665,13 @@ array_concat(arrayobject *a, PyObject *bb)
}
static PyObject *
-array_repeat(arrayobject *a, int n)
+array_repeat(arrayobject *a, Py_ssize_t n)
{
- int i;
- int size;
+ Py_ssize_t i;
+ Py_ssize_t size;
arrayobject *np;
char *p;
- int nbytes;
+ Py_ssize_t nbytes;
if (n < 0)
n = 0;
size = a->ob_size * n;
@@ -760,7 +761,7 @@ array_ass_slice(arrayobject *a, int ilow, int ihigh, PyObject *v)
}
static int
-array_ass_item(arrayobject *a, int i, PyObject *v)
+array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError,
@@ -773,7 +774,7 @@ array_ass_item(arrayobject *a, int i, PyObject *v)
}
static int
-setarrayitem(PyObject *a, int i, PyObject *v)
+setarrayitem(PyObject *a, Py_ssize_t i, PyObject *v)
{
assert(array_Check(a));
return array_ass_item((arrayobject *)a, i, v);
@@ -805,7 +806,7 @@ array_iter_extend(arrayobject *self, PyObject *bb)
static int
array_do_extend(arrayobject *self, PyObject *bb)
{
- int size;
+ Py_ssize_t size;
if (!array_Check(bb))
return array_iter_extend(self, bb);
@@ -847,10 +848,10 @@ array_inplace_concat(arrayobject *self, PyObject *bb)
}
static PyObject *
-array_inplace_repeat(arrayobject *self, int n)
+array_inplace_repeat(arrayobject *self, Py_ssize_t n)
{
char *items, *p;
- int size, i;
+ Py_ssize_t size, i;
if (self->ob_size > 0) {
if (n < 0)
@@ -883,7 +884,7 @@ array_inplace_repeat(arrayobject *self, int n)
static PyObject *
-ins(arrayobject *self, int where, PyObject *v)
+ins(arrayobject *self, Py_ssize_t where, PyObject *v)
{
if (ins1(self, where, v) != 0)
return NULL;
@@ -894,8 +895,8 @@ ins(arrayobject *self, int where, PyObject *v)
static PyObject *
array_count(arrayobject *self, PyObject *v)
{
- int count = 0;
- int i;
+ Py_ssize_t count = 0;
+ Py_ssize_t i;
for (i = 0; i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -906,7 +907,10 @@ array_count(arrayobject *self, PyObject *v)
else if (cmp < 0)
return NULL;
}
- return PyInt_FromLong((long)count);
+ if (i < LONG_MAX)
+ return PyInt_FromLong((long)count);
+ else
+ return PyLong_FromLong(count);
}
PyDoc_STRVAR(count_doc,
@@ -917,7 +921,7 @@ Return number of occurences of x in the array.");
static PyObject *
array_index(arrayobject *self, PyObject *v)
{
- int i;
+ Py_ssize_t i;
for (i = 0; i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -941,7 +945,8 @@ Return index of first occurence of x in the array.");
static int
array_contains(arrayobject *self, PyObject *v)
{
- int i, cmp;
+ Py_ssize_t i;
+ int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -1079,7 +1084,7 @@ static PyObject *
array_byteswap(arrayobject *self, PyObject *unused)
{
char *p;
- int i;
+ Py_ssize_t i;
switch (self->ob_descr->itemsize) {
case 1:
@@ -1158,7 +1163,7 @@ PyDoc_STRVAR(array_doc, "Return state information for pickling.");
static PyObject *
array_reverse(arrayobject *self, PyObject *unused)
{
- register int itemsize = self->ob_descr->itemsize;
+ register Py_ssize_t itemsize = self->ob_descr->itemsize;
register char *p, *q;
/* little buffer to hold items while swapping */
char tmp[256]; /* 8 is probably enough -- but why skimp */
@@ -1223,7 +1228,7 @@ array_fromfile(arrayobject *self, PyObject *args)
nread = fread(item + (self->ob_size - n) * itemsize,
itemsize, n, fp);
if (nread < (size_t)n) {
- self->ob_size -= (n - nread);
+ self->ob_size -= (n - nread);
PyMem_RESIZE(item, char, self->ob_size*itemsize);
self->ob_item = item;
self->allocated = self->ob_size;
@@ -1275,8 +1280,8 @@ write.");
static PyObject *
array_fromlist(arrayobject *self, PyObject *list)
{
- int n;
- int itemsize = self->ob_descr->itemsize;
+ Py_ssize_t n;
+ Py_ssize_t itemsize = self->ob_descr->itemsize;
if (!PyList_Check(list)) {
PyErr_SetString(PyExc_TypeError, "arg must be list");
@@ -1285,7 +1290,7 @@ array_fromlist(arrayobject *self, PyObject *list)
n = PyList_Size(list);
if (n > 0) {
char *item = self->ob_item;
- int i;
+ Py_ssize_t i;
PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
@@ -1321,7 +1326,7 @@ static PyObject *
array_tolist(arrayobject *self, PyObject *unused)
{
PyObject *list = PyList_New(self->ob_size);
- int i;
+ Py_ssize_t i;
if (list == NULL)
return NULL;
@@ -1346,7 +1351,7 @@ static PyObject *
array_fromstring(arrayobject *self, PyObject *args)
{
char *str;
- int n;
+ Py_ssize_t n;
int itemsize = self->ob_descr->itemsize;
if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n))
return NULL;
@@ -1400,7 +1405,7 @@ static PyObject *
array_fromunicode(arrayobject *self, PyObject *args)
{
Py_UNICODE *ustr;
- int n;
+ Py_ssize_t n;
if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n))
return NULL;
@@ -1541,7 +1546,7 @@ array_repr(arrayobject *a)
{
char buf[256], typecode;
PyObject *s, *t, *v = NULL;
- int len;
+ Py_ssize_t len;
len = a->ob_size;
typecode = a->ob_descr->typecode;
@@ -1586,7 +1591,7 @@ array_subscr(arrayobject* self, PyObject* item)
return array_item(self, i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
PyObject* result;
arrayobject* ar;
int itemsize = self->ob_descr->itemsize;
@@ -1640,7 +1645,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
return array_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength;
+ Py_ssize_t start, stop, step, slicelength;
int itemsize = self->ob_descr->itemsize;
if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
@@ -1654,7 +1659,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (value == NULL) {
/* delete slice */
- int cur, i, extra;
+ Py_ssize_t cur, i, extra;
if (slicelength <= 0)
return 0;
@@ -1686,7 +1691,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
}
else {
/* assign slice */
- int cur, i;
+ Py_ssize_t cur, i;
arrayobject* av;
if (!array_Check(value)) {
@@ -1700,8 +1705,8 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (av->ob_size != slicelength) {
PyErr_Format(PyExc_ValueError,
- "attempt to assign array of size %d to extended slice of size %d",
- av->ob_size, slicelength);
+ "attempt to assign array of size %ld to extended slice of size %ld",
+ /*XXX*/(long)av->ob_size, /*XXX*/(long)slicelength);
return -1;
}
@@ -1737,13 +1742,13 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
}
static PyMappingMethods array_as_mapping = {
- (inquiry)array_length,
+ (lenfunc)array_length,
(binaryfunc)array_subscr,
(objobjargproc)array_ass_subscr
};
-static int
-array_buffer_getreadbuf(arrayobject *self, int index, const void **ptr)
+static Py_ssize_t
+array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1754,8 +1759,8 @@ array_buffer_getreadbuf(arrayobject *self, int index, const void **ptr)
return self->ob_size*self->ob_descr->itemsize;
}
-static int
-array_buffer_getwritebuf(arrayobject *self, int index, const void **ptr)
+static Py_ssize_t
+array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1766,8 +1771,8 @@ array_buffer_getwritebuf(arrayobject *self, int index, const void **ptr)
return self->ob_size*self->ob_descr->itemsize;
}
-static int
-array_buffer_getsegcount(arrayobject *self, int *lenp)
+static Py_ssize_t
+array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = self->ob_size*self->ob_descr->itemsize;
@@ -1775,22 +1780,22 @@ array_buffer_getsegcount(arrayobject *self, int *lenp)
}
static PySequenceMethods array_as_sequence = {
- (inquiry)array_length, /*sq_length*/
+ (lenfunc)array_length, /*sq_length*/
(binaryfunc)array_concat, /*sq_concat*/
- (intargfunc)array_repeat, /*sq_repeat*/
- (intargfunc)array_item, /*sq_item*/
- (intintargfunc)array_slice, /*sq_slice*/
- (intobjargproc)array_ass_item, /*sq_ass_item*/
- (intintobjargproc)array_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)array_repeat, /*sq_repeat*/
+ (ssizeargfunc)array_item, /*sq_item*/
+ (ssizessizeargfunc)array_slice, /*sq_slice*/
+ (ssizeobjargproc)array_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/
(objobjproc)array_contains, /*sq_contains*/
(binaryfunc)array_inplace_concat, /*sq_inplace_concat*/
- (intargfunc)array_inplace_repeat /*sq_inplace_repeat*/
+ (ssizeargfunc)array_inplace_repeat /*sq_inplace_repeat*/
};
static PyBufferProcs array_as_buffer = {
- (getreadbufferproc)array_buffer_getreadbuf,
- (getwritebufferproc)array_buffer_getwritebuf,
- (getsegcountproc)array_buffer_getsegcount,
+ (readbufferproc)array_buffer_getreadbuf,
+ (writebufferproc)array_buffer_getwritebuf,
+ (segcountproc)array_buffer_getsegcount,
};
static PyObject *
@@ -1822,7 +1827,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
for (descr = descriptors; descr->typecode != '\0'; descr++) {
if (descr->typecode == c) {
PyObject *a;
- int len;
+ Py_ssize_t len;
if (initial == NULL || !(PyList_Check(initial)
|| PyTuple_Check(initial)))
@@ -1835,7 +1840,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
if (len > 0) {
- int i;
+ Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *v =
PySequence_GetItem(initial, i);
@@ -1864,7 +1869,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(v);
#ifdef Py_USING_UNICODE
} else if (initial != NULL && PyUnicode_Check(initial)) {
- int n = PyUnicode_GET_DATA_SIZE(initial);
+ Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
if (n > 0) {
arrayobject *self = (arrayobject *)a;
char *item = self->ob_item;
@@ -2012,9 +2017,9 @@ static PyTypeObject Arraytype = {
typedef struct {
PyObject_HEAD
- long index;
+ Py_ssize_t index;
arrayobject *ao;
- PyObject * (*getitem)(struct arrayobject *, int);
+ PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
} arrayiterobject;
static PyTypeObject PyArrayIter_Type;
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 8d5a305..5e285f4 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1020,7 +1020,9 @@ audioop_ratecv(PyObject *self, PyObject *args)
cur_i[chan]));
if (PyErr_Occurred())
goto exit;
- len = ncp - PyString_AsString(str);
+ /* We have checked before that the length
+ * of the string fits into int. */
+ len = (int)(ncp - PyString_AsString(str));
if (len == 0) {
/*don't want to resize to zero length*/
rv = PyString_FromStringAndSize("", 0);
diff --git a/Modules/bsddbmodule.c b/Modules/bsddbmodule.c
index 6bdffde..61c6564 100644
--- a/Modules/bsddbmodule.c
+++ b/Modules/bsddbmodule.c
@@ -240,7 +240,7 @@ bsddb_dealloc(bsddbobject *dp)
#define BSDDB_END_SAVE(_dp) Py_END_ALLOW_THREADS
#endif
-static int
+static Py_ssize_t
bsddb_length(bsddbobject *dp)
{
check_bsddbobject_open(dp, -1);
@@ -374,7 +374,7 @@ bsddb_ass_sub(bsddbobject *dp, PyObject *key, PyObject *value)
}
static PyMappingMethods bsddb_as_mapping = {
- (inquiry)bsddb_length, /*mp_length*/
+ (lenfunc)bsddb_length, /*mp_length*/
(binaryfunc)bsddb_subscript, /*mp_subscript*/
(objobjargproc)bsddb_ass_sub, /*mp_ass_subscript*/
};
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 9f30f8a..a0f66ee 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -908,7 +908,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
PyObject *v = PyList_GET_ITEM(list, i);
if (!PyString_Check(v)) {
const char *buffer;
- int len;
+ Py_ssize_t len;
if (PyObject_AsCharBuffer(v, &buffer, &len)) {
PyErr_SetString(PyExc_TypeError,
"writelines() "
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index cc821fd..cb14627 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -339,7 +339,7 @@ typedef struct Picklerobject {
int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
int nesting;
- int (*write_func)(struct Picklerobject *, const char *, int);
+ int (*write_func)(struct Picklerobject *, const char *, Py_ssize_t);
char *write_buf;
int buf_size;
PyObject *dispatch_table;
@@ -368,8 +368,8 @@ typedef struct Unpicklerobject {
int *marks;
int num_marks;
int marks_size;
- int (*read_func)(struct Unpicklerobject *, char **, int);
- int (*readline_func)(struct Unpicklerobject *, char **);
+ Py_ssize_t (*read_func)(struct Unpicklerobject *, char **, Py_ssize_t);
+ Py_ssize_t (*readline_func)(struct Unpicklerobject *, char **);
int buf_size;
char *buf;
PyObject *find_class;
@@ -417,7 +417,7 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
}
static int
-write_file(Picklerobject *self, const char *s, int n)
+write_file(Picklerobject *self, const char *s, Py_ssize_t n)
{
size_t nbyteswritten;
@@ -425,6 +425,11 @@ write_file(Picklerobject *self, const char *s, int n)
return 0;
}
+ if (n > INT_MAX) {
+ /* String too large */
+ return -1;
+ }
+
Py_BEGIN_ALLOW_THREADS
nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
Py_END_ALLOW_THREADS
@@ -433,11 +438,11 @@ write_file(Picklerobject *self, const char *s, int n)
return -1;
}
- return n;
+ return (int)n;
}
static int
-write_cStringIO(Picklerobject *self, const char *s, int n)
+write_cStringIO(Picklerobject *self, const char *s, Py_ssize_t n)
{
if (s == NULL) {
return 0;
@@ -447,21 +452,26 @@ write_cStringIO(Picklerobject *self, const char *s, int n)
return -1;
}
- return n;
+ return (int)n;
}
static int
-write_none(Picklerobject *self, const char *s, int n)
+write_none(Picklerobject *self, const char *s, Py_ssize_t n)
{
if (s == NULL) return 0;
- return n;
+ if (n > INT_MAX) return -1;
+ return (int)n;
}
static int
-write_other(Picklerobject *self, const char *s, int n)
+write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
{
PyObject *py_str = 0, *junk = 0;
+ int n;
+ if (_n > INT_MAX)
+ return -1;
+ n = (int)_n;
if (s == NULL) {
if (!( self->buf_size )) return 0;
py_str = PyString_FromStringAndSize(self->write_buf,
@@ -505,8 +515,8 @@ write_other(Picklerobject *self, const char *s, int n)
}
-static int
-read_file(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
{
size_t nbytesread;
@@ -549,7 +559,7 @@ read_file(Unpicklerobject *self, char **s, int n)
}
-static int
+static Py_ssize_t
readline_file(Unpicklerobject *self, char **s)
{
int i;
@@ -588,8 +598,8 @@ readline_file(Unpicklerobject *self, char **s)
}
-static int
-read_cStringIO(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_cStringIO(Unpicklerobject *self, char **s, Py_ssize_t n)
{
char *ptr;
@@ -604,10 +614,10 @@ read_cStringIO(Unpicklerobject *self, char **s, int n)
}
-static int
+static Py_ssize_t
readline_cStringIO(Unpicklerobject *self, char **s)
{
- int n;
+ Py_ssize_t n;
char *ptr;
if ((n = PycStringIO->creadline((PyObject *)self->file, &ptr)) < 0) {
@@ -620,12 +630,12 @@ readline_cStringIO(Unpicklerobject *self, char **s)
}
-static int
-read_other(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_other(Unpicklerobject *self, char **s, Py_ssize_t n)
{
PyObject *bytes, *str=0;
- if (!( bytes = PyInt_FromLong(n))) return -1;
+ if (!( bytes = PyInt_FromSsize_t(n))) return -1;
ARG_TUP(self, bytes);
if (self->arg) {
@@ -642,11 +652,11 @@ read_other(Unpicklerobject *self, char **s, int n)
}
-static int
+static Py_ssize_t
readline_other(Unpicklerobject *self, char **s)
{
PyObject *str;
- int str_size;
+ Py_ssize_t str_size;
if (!( str = PyObject_CallObject(self->readline, empty_tuple))) {
return -1;
@@ -828,7 +838,7 @@ put2(Picklerobject *self, PyObject *ob)
static PyObject *
whichmodule(PyObject *global, PyObject *global_name)
{
- int i, j;
+ Py_ssize_t i, j;
PyObject *module = 0, *modules_dict = 0,
*global_name_attr = 0, *name = 0;
@@ -3280,7 +3290,7 @@ load_long(Unpicklerobject *self)
static int
load_counted_long(Unpicklerobject *self, int size)
{
- int i;
+ Py_ssize_t i;
char *nbytes;
unsigned char *pdata;
PyObject *along;
@@ -4253,7 +4263,7 @@ load_build(Unpicklerobject *self)
PyObject *state, *inst, *slotstate;
PyObject *__setstate__;
PyObject *d_key, *d_value;
- int i;
+ Py_ssize_t i;
int res = -1;
/* Stack is ... instance, state. We want to leave instance at
@@ -5710,7 +5720,7 @@ PyMODINIT_FUNC
initcPickle(void)
{
PyObject *m, *d, *di, *v, *k;
- int i;
+ Py_ssize_t i;
char *rev = "1.71"; /* XXX when does this change? */
PyObject *format_version;
PyObject *compatible_formats;
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index ad2f36b..618b88c 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -47,7 +47,7 @@ PyDoc_STRVAR(cStringIO_module_documentation,
typedef struct {
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
} IOobject;
#define IOOOBJECT(O) ((IOobject*)(O))
@@ -57,9 +57,10 @@ typedef struct {
typedef struct { /* Subtype of IOobject */
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
- int buf_size, softspace;
+ Py_ssize_t buf_size;
+ int softspace;
} Oobject;
/* Declarations for objects of type StringI */
@@ -67,7 +68,7 @@ typedef struct { /* Subtype of IOobject */
typedef struct { /* Subtype of IOobject */
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
/* We store a reference to the object here in order to keep
the buffer alive during the lifetime of the Iobject. */
PyObject *pbuf;
@@ -154,7 +155,7 @@ PyDoc_STRVAR(IO_read__doc__,
"read([s]) -- Read s characters, or the rest of the string");
static int
-IO_cread(PyObject *self, char **output, int n) {
+IO_cread(PyObject *self, char **output, Py_ssize_t n) {
int l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
@@ -171,10 +172,10 @@ IO_cread(PyObject *self, char **output, int n) {
static PyObject *
IO_read(IOobject *self, PyObject *args) {
- int n = -1;
+ Py_ssize_t n = -1;
char *output;
- UNLESS (PyArg_ParseTuple(args, "|i:read", &n)) return NULL;
+ UNLESS (PyArg_ParseTuple(args, "|n:read", &n)) return NULL;
if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;
@@ -186,7 +187,7 @@ PyDoc_STRVAR(IO_readline__doc__, "readline() -- Read one line");
static int
IO_creadline(PyObject *self, char **output) {
char *n, *s;
- int l;
+ Py_ssize_t l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
@@ -197,8 +198,9 @@ IO_creadline(PyObject *self, char **output) {
*output=((IOobject*)self)->buf + ((IOobject*)self)->pos;
l = n - ((IOobject*)self)->buf - ((IOobject*)self)->pos;
- ((IOobject*)self)->pos += l;
- return l;
+ assert(((IOobject*)self)->pos + l < INT_MAX);
+ ((IOobject*)self)->pos += (int)l;
+ return (int)l;
}
static PyObject *
@@ -285,10 +287,10 @@ PyDoc_STRVAR(IO_truncate__doc__,
static PyObject *
IO_truncate(IOobject *self, PyObject *args) {
- int pos = -1;
+ Py_ssize_t pos = -1;
UNLESS (IO__opencheck(self)) return NULL;
- UNLESS (PyArg_ParseTuple(args, "|i:truncate", &pos)) return NULL;
+ UNLESS (PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
if (pos < 0) pos = self->pos;
if (self->string_size > pos) self->string_size = pos;
@@ -324,10 +326,11 @@ PyDoc_STRVAR(O_seek__doc__,
static PyObject *
O_seek(Oobject *self, PyObject *args) {
- int position, mode = 0;
+ Py_ssize_t position;
+ int mode = 0;
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL;
- UNLESS (PyArg_ParseTuple(args, "i|i:seek", &position, &mode))
+ UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode))
return NULL;
if (mode == 2) {
@@ -362,8 +365,8 @@ PyDoc_STRVAR(O_write__doc__,
static int
-O_cwrite(PyObject *self, const char *c, int l) {
- int newl;
+O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
+ Py_ssize_t newl;
Oobject *oself;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
@@ -372,8 +375,10 @@ O_cwrite(PyObject *self, const char *c, int l) {
newl = oself->pos+l;
if (newl >= oself->buf_size) {
oself->buf_size *= 2;
- if (oself->buf_size <= newl)
- oself->buf_size = newl+1;
+ if (oself->buf_size <= newl) {
+ assert(newl + 1 < INT_MAX);
+ oself->buf_size = (int)(newl+1);
+ }
UNLESS (oself->buf =
(char*)realloc(oself->buf, oself->buf_size)) {
PyErr_SetString(PyExc_MemoryError,"out of memory");
@@ -384,13 +389,14 @@ O_cwrite(PyObject *self, const char *c, int l) {
memcpy(oself->buf+oself->pos,c,l);
- oself->pos += l;
+ assert(oself->pos + l < INT_MAX);
+ oself->pos += (int)l;
if (oself->string_size < oself->pos) {
oself->string_size = oself->pos;
}
- return l;
+ return (int)l;
}
static PyObject *
@@ -432,7 +438,7 @@ O_writelines(Oobject *self, PyObject *args) {
if (it == NULL)
return NULL;
while ((s = PyIter_Next(it)) != NULL) {
- int n;
+ Py_ssize_t n;
char *c;
if (PyString_AsStringAndSize(s, &c, &n) == -1) {
Py_DECREF(it);
@@ -564,10 +570,11 @@ I_close(Iobject *self, PyObject *unused) {
static PyObject *
I_seek(Iobject *self, PyObject *args) {
- int position, mode = 0;
+ Py_ssize_t position;
+ int mode = 0;
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL;
- UNLESS (PyArg_ParseTuple(args, "i|i:seek", &position, &mode))
+ UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode))
return NULL;
if (mode == 2) position += self->string_size;
@@ -648,7 +655,7 @@ static PyObject *
newIobject(PyObject *s) {
Iobject *self;
char *buf;
- int size;
+ Py_ssize_t size;
if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index b0dae0c..c13de8f 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -214,7 +214,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
if (buf->excobj == NULL) {
buf->excobj = PyUnicodeEncodeError_Create(codec->encoding,
buf->inbuf_top,
- (int)(buf->inbuf_end - buf->inbuf_top),
+ buf->inbuf_end - buf->inbuf_top,
start, end, reason);
if (buf->excobj == NULL)
goto errorexit;
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c
index 2003154..41ef8cc 100644
--- a/Modules/collectionsmodule.c
+++ b/Modules/collectionsmodule.c
@@ -314,7 +314,7 @@ PyDoc_STRVAR(extendleft_doc,
"Extend the left side of the deque with elements from the iterable");
static int
-_deque_rotate(dequeobject *deque, int n)
+_deque_rotate(dequeobject *deque, Py_ssize_t n)
{
int i, len=deque->len, halflen=(len+1)>>1;
PyObject *item, *rv;
@@ -365,7 +365,7 @@ deque_rotate(dequeobject *deque, PyObject *args)
PyDoc_STRVAR(rotate_doc,
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
-static int
+static Py_ssize_t
deque_len(dequeobject *deque)
{
return deque->len;
@@ -374,7 +374,7 @@ deque_len(dequeobject *deque)
static PyObject *
deque_remove(dequeobject *deque, PyObject *value)
{
- int i, n=deque->len;
+ Py_ssize_t i, n=deque->len;
for (i=0 ; i<n ; i++) {
PyObject *item = deque->leftblock->data[deque->leftindex];
@@ -469,7 +469,7 @@ deque_item(dequeobject *deque, int i)
*/
static int
-deque_del_item(dequeobject *deque, int i)
+deque_del_item(dequeobject *deque, Py_ssize_t i)
{
PyObject *item;
@@ -485,7 +485,7 @@ deque_del_item(dequeobject *deque, int i)
}
static int
-deque_ass_item(dequeobject *deque, int i, PyObject *v)
+deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v)
{
PyObject *old_value;
block *b;
@@ -776,12 +776,12 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwds)
}
static PySequenceMethods deque_as_sequence = {
- (inquiry)deque_len, /* sq_length */
+ (lenfunc)deque_len, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)deque_item, /* sq_item */
+ (ssizeargfunc)deque_item, /* sq_item */
0, /* sq_slice */
- (intobjargproc)deque_ass_item, /* sq_ass_item */
+ (ssizeobjargproc)deque_ass_item, /* sq_ass_item */
};
/* deque object ********************************************************/
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 50f47d4..5c0f220 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -596,7 +596,7 @@ normalize_datetime(int *year, int *month, int *day,
*/
static PyObject *
-time_alloc(PyTypeObject *type, int aware)
+time_alloc(PyTypeObject *type, Py_ssize_t aware)
{
PyObject *self;
@@ -611,7 +611,7 @@ time_alloc(PyTypeObject *type, int aware)
}
static PyObject *
-datetime_alloc(PyTypeObject *type, int aware)
+datetime_alloc(PyTypeObject *type, Py_ssize_t aware)
{
PyObject *self;
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index cc963a2..8bfbbcd 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -70,7 +70,7 @@ dbm_dealloc(register dbmobject *dp)
PyObject_Del(dp);
}
-static int
+static Py_ssize_t
dbm_length(dbmobject *dp)
{
if (dp->di_dbm == NULL) {
@@ -162,7 +162,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
}
static PyMappingMethods dbm_as_mapping = {
- (inquiry)dbm_length, /*mp_length*/
+ (lenfunc)dbm_length, /*mp_length*/
(binaryfunc)dbm_subscript, /*mp_subscript*/
(objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
};
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 00239bd..4902eb5 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1274,7 +1274,7 @@ _PyObject_GC_New(PyTypeObject *tp)
}
PyVarObject *
-_PyObject_GC_NewVar(PyTypeObject *tp, int nitems)
+_PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size);
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 6045743..025bdb7 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -86,7 +86,7 @@ dbm_dealloc(register dbmobject *dp)
PyObject_Del(dp);
}
-static int
+static Py_ssize_t
dbm_length(dbmobject *dp)
{
if (dp->di_dbm == NULL) {
@@ -178,7 +178,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
}
static PyMappingMethods dbm_as_mapping = {
- (inquiry)dbm_length, /*mp_length*/
+ (lenfunc)dbm_length, /*mp_length*/
(binaryfunc)dbm_subscript, /*mp_subscript*/
(objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
};
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index b6b2d85..7a68de4 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -583,8 +583,8 @@ static struct PyMethodDef mmap_object_methods[] = {
/* Functions for treating an mmap'ed file as a buffer */
-static int
-mmap_buffer_getreadbuf(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getreadbuf(mmap_object *self, Py_ssize_t index, const void **ptr)
{
CHECK_VALID(-1);
if ( index != 0 ) {
@@ -596,8 +596,8 @@ mmap_buffer_getreadbuf(mmap_object *self, int index, const void **ptr)
return self->size;
}
-static int
-mmap_buffer_getwritebuf(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getwritebuf(mmap_object *self, Py_ssize_t index, const void **ptr)
{
CHECK_VALID(-1);
if ( index != 0 ) {
@@ -611,8 +611,8 @@ mmap_buffer_getwritebuf(mmap_object *self, int index, const void **ptr)
return self->size;
}
-static int
-mmap_buffer_getsegcount(mmap_object *self, int *lenp)
+static Py_ssize_t
+mmap_buffer_getsegcount(mmap_object *self, Py_ssize_t *lenp)
{
CHECK_VALID(-1);
if (lenp)
@@ -620,8 +620,8 @@ mmap_buffer_getsegcount(mmap_object *self, int *lenp)
return 1;
}
-static int
-mmap_buffer_getcharbuffer(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getcharbuffer(mmap_object *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -638,7 +638,7 @@ mmap_object_getattr(mmap_object *self, char *name)
return Py_FindMethod (mmap_object_methods, (PyObject *)self, name);
}
-static int
+static Py_ssize_t
mmap_length(mmap_object *self)
{
CHECK_VALID(-1);
@@ -646,7 +646,7 @@ mmap_length(mmap_object *self)
}
static PyObject *
-mmap_item(mmap_object *self, int i)
+mmap_item(mmap_object *self, Py_ssize_t i)
{
CHECK_VALID(NULL);
if (i < 0 || (size_t)i >= self->size) {
@@ -657,7 +657,7 @@ mmap_item(mmap_object *self, int i)
}
static PyObject *
-mmap_slice(mmap_object *self, int ilow, int ihigh)
+mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
{
CHECK_VALID(NULL);
if (ilow < 0)
@@ -684,7 +684,7 @@ mmap_concat(mmap_object *self, PyObject *bb)
}
static PyObject *
-mmap_repeat(mmap_object *self, int n)
+mmap_repeat(mmap_object *self, Py_ssize_t n)
{
CHECK_VALID(NULL);
PyErr_SetString(PyExc_SystemError,
@@ -693,7 +693,7 @@ mmap_repeat(mmap_object *self, int n)
}
static int
-mmap_ass_slice(mmap_object *self, int ilow, int ihigh, PyObject *v)
+mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
{
const char *buf;
@@ -732,7 +732,7 @@ mmap_ass_slice(mmap_object *self, int ilow, int ihigh, PyObject *v)
}
static int
-mmap_ass_item(mmap_object *self, int i, PyObject *v)
+mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
const char *buf;
@@ -759,20 +759,20 @@ mmap_ass_item(mmap_object *self, int i, PyObject *v)
}
static PySequenceMethods mmap_as_sequence = {
- (inquiry)mmap_length, /*sq_length*/
+ (lenfunc)mmap_length, /*sq_length*/
(binaryfunc)mmap_concat, /*sq_concat*/
- (intargfunc)mmap_repeat, /*sq_repeat*/
- (intargfunc)mmap_item, /*sq_item*/
- (intintargfunc)mmap_slice, /*sq_slice*/
- (intobjargproc)mmap_ass_item, /*sq_ass_item*/
- (intintobjargproc)mmap_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)mmap_repeat, /*sq_repeat*/
+ (ssizeargfunc)mmap_item, /*sq_item*/
+ (ssizessizeargfunc)mmap_slice, /*sq_slice*/
+ (ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/
};
static PyBufferProcs mmap_as_buffer = {
- (getreadbufferproc)mmap_buffer_getreadbuf,
- (getwritebufferproc)mmap_buffer_getwritebuf,
- (getsegcountproc)mmap_buffer_getsegcount,
- (getcharbufferproc)mmap_buffer_getcharbuffer,
+ (readbufferproc)mmap_buffer_getreadbuf,
+ (writebufferproc)mmap_buffer_getwritebuf,
+ (segcountproc)mmap_buffer_getsegcount,
+ (charbufferproc)mmap_buffer_getcharbuffer,
};
static PyTypeObject mmap_object_type = {
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index b2b32df..514e7e6 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -55,9 +55,9 @@ PyDoc_STRVAR(parser_doc_string,
static char parser_version_string[] = "0.5";
-typedef PyObject* (*SeqMaker) (int length);
+typedef PyObject* (*SeqMaker) (Py_ssize_t length);
typedef int (*SeqInserter) (PyObject* sequence,
- int index,
+ Py_ssize_t index,
PyObject* element);
/* The function below is copyrighted by Stichting Mathematisch Centrum. The
@@ -632,8 +632,9 @@ parser_tuple2st(PyST_Object *self, PyObject *args, PyObject *kw)
static node*
build_node_children(PyObject *tuple, node *root, int *line_num)
{
- int len = PyObject_Size(tuple);
- int i, err;
+ Py_ssize_t len = PyObject_Size(tuple);
+ Py_ssize_t i;
+ int err;
for (i = 1; i < len; ++i) {
/* elem must always be a sequence, however simple */
@@ -663,7 +664,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
return (0);
}
if (ISTERMINAL(type)) {
- int len = PyObject_Size(elem);
+ Py_ssize_t len = PyObject_Size(elem);
PyObject *temp;
if ((len != 2) && (len != 3)) {
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ba7ea70..f35c090 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1642,7 +1642,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* MAX_PATH characters could mean a bigger encoded string */
char namebuf[MAX_PATH*2+5];
char *bufptr = namebuf;
- int len = sizeof(namebuf)/sizeof(namebuf[0]);
+ Py_ssize_t len = sizeof(namebuf)/sizeof(namebuf[0]);
#ifdef Py_WIN_WIDE_FILENAMES
/* If on wide-character-capable OS see if argument
@@ -2340,7 +2340,7 @@ posix_execv(PyObject *self, PyObject *args)
PyObject *argv;
char **argvlist;
int i, argc;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* execv has two arguments: (path, argv), where
argv is a list or tuple of strings. */
@@ -2409,7 +2409,7 @@ posix_execve(PyObject *self, PyObject *args)
char **envlist;
PyObject *key, *val, *keys=NULL, *vals=NULL;
int i, pos, argc, envc;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* execve has three arguments: (path, argv, env), where
@@ -2553,7 +2553,7 @@ posix_spawnv(PyObject *self, PyObject *args)
char **argvlist;
int mode, i, argc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnv has three arguments: (mode, path, argv), where
argv is a list or tuple of strings. */
@@ -2642,7 +2642,7 @@ posix_spawnve(PyObject *self, PyObject *args)
PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
int mode, i, pos, argc, envc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* spawnve has four arguments: (mode, path, argv, env), where
@@ -2794,7 +2794,7 @@ posix_spawnvp(PyObject *self, PyObject *args)
char **argvlist;
int mode, i, argc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnvp has three arguments: (mode, path, argv), where
argv is a list or tuple of strings. */
@@ -2875,7 +2875,7 @@ posix_spawnvpe(PyObject *self, PyObject *args)
PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
int mode, i, pos, argc, envc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* spawnvpe has four arguments: (mode, path, argv, env), where
@@ -4310,14 +4310,15 @@ _PyPopenCreateProcess(char *cmdstring,
char *s1,*s2, *s3 = " /c ";
const char *szConsoleSpawn = "w9xpopen.exe";
int i;
- int x;
+ Py_ssize_t x;
if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
char *comshell;
s1 = (char *)alloca(i);
if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))
- return x;
+ /* x < i, so x fits into an integer */
+ return (int)x;
/* Explicitly check if we are using COMMAND.COM. If we are
* then use the w9xpopen hack.
@@ -4520,7 +4521,7 @@ _PyPopen(char *cmdstring, int mode, int n)
switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) {
case _O_WRONLY | _O_TEXT:
/* Case for writing to child Stdin in text mode. */
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, "w");
f = PyFile_FromFile(f1, cmdstring, "w", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4531,7 +4532,7 @@ _PyPopen(char *cmdstring, int mode, int n)
case _O_RDONLY | _O_TEXT:
/* Case for reading from child Stdout in text mode. */
- fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f1 = _fdopen(fd1, "r");
f = PyFile_FromFile(f1, cmdstring, "r", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4542,7 +4543,7 @@ _PyPopen(char *cmdstring, int mode, int n)
case _O_RDONLY | _O_BINARY:
/* Case for readinig from child Stdout in binary mode. */
- fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f1 = _fdopen(fd1, "rb");
f = PyFile_FromFile(f1, cmdstring, "rb", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4553,7 +4554,7 @@ _PyPopen(char *cmdstring, int mode, int n)
case _O_WRONLY | _O_BINARY:
/* Case for writing to child Stdin in binary mode. */
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, "wb");
f = PyFile_FromFile(f1, cmdstring, "wb", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4579,9 +4580,9 @@ _PyPopen(char *cmdstring, int mode, int n)
m2 = "wb";
}
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, m2);
- fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd2 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f2 = _fdopen(fd2, m1);
p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
PyFile_SetBufSize(p1, 0);
@@ -4611,11 +4612,11 @@ _PyPopen(char *cmdstring, int mode, int n)
m2 = "wb";
}
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, m2);
- fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd2 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f2 = _fdopen(fd2, m1);
- fd3 = _open_osfhandle((long)hChildStderrRdDup, mode);
+ fd3 = _open_osfhandle((intptr_t)hChildStderrRdDup, mode);
f3 = _fdopen(fd3, m1);
p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);
@@ -5117,8 +5118,8 @@ PyDoc_STRVAR(posix_waitpid__doc__,
static PyObject *
posix_waitpid(PyObject *self, PyObject *args)
{
- int pid, options;
- int status;
+ intptr_t pid;
+ int status, options;
if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options))
return NULL;
diff --git a/Modules/rgbimgmodule.c b/Modules/rgbimgmodule.c
index 8c70d95..67b5521 100644
--- a/Modules/rgbimgmodule.c
+++ b/Modules/rgbimgmodule.c
@@ -168,7 +168,7 @@ putlong(FILE *outf, Py_UInt32 val)
buf[1] = (unsigned char) (val >> 16);
buf[2] = (unsigned char) (val >> 8);
buf[3] = (unsigned char) (val >> 0);
- return fwrite(buf, 4, 1, outf);
+ return (int)fwrite(buf, 4, 1, outf);
}
static void
@@ -200,7 +200,7 @@ writeheader(FILE *outf, IMAGE *image)
putlong(outf, image->min);
putlong(outf, image->max);
putlong(outf, 0);
- return fwrite("no name", 8, 1, outf);
+ return (int)fwrite("no name", 8, 1, outf);
}
static int
@@ -567,7 +567,8 @@ longstoimage(PyObject *self, PyObject *args)
Py_Int32 *starttab = NULL, *lengthtab = NULL;
unsigned char *rlebuf = NULL;
unsigned char *lumbuf = NULL;
- int rlebuflen, goodwrite;
+ int rlebuflen;
+ Py_ssize_t goodwrite;
PyObject *retval = NULL;
if (!PyArg_ParseTuple(args, "s#iiis:longstoimage", &lptr, &len,
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 53c68c1..c9d403a 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -340,7 +340,7 @@ static PyTypeObject poll_Type;
static int
update_ufd_array(pollObject *self)
{
- int i, pos;
+ Py_ssize_t i, pos;
PyObject *key, *value;
self->ufd_len = PyDict_Size(self->dict);
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index 058391d..93a9224 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -543,7 +543,7 @@ hashed.");
static PyObject *
SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
- static char *kwlist[] = {"string", NULL};
+ static const char *kwlist[] = {"string", NULL};
SHAobject *new;
unsigned char *cp = NULL;
int len;
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index 2917298..93dad8e 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -170,7 +170,7 @@ strop_joinfields(PyObject *self, PyObject *args)
int i, reslen = 0, slen = 0, sz = 100;
PyObject *res = NULL;
char* p = NULL;
- intargfunc getitemfunc;
+ ssizeargfunc getitemfunc;
WARN;
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
@@ -364,7 +364,7 @@ static PyObject *
do_strip(PyObject *args, int striptype)
{
char *s;
- int len, i, j;
+ Py_ssize_t len, i, j;
if (PyString_AsStringAndSize(args, &s, &len))
@@ -443,7 +443,7 @@ static PyObject *
strop_lower(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
@@ -482,7 +482,7 @@ static PyObject *
strop_upper(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
@@ -522,7 +522,7 @@ static PyObject *
strop_capitalize(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
@@ -688,7 +688,7 @@ static PyObject *
strop_swapcase(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 937b0f7..be141d0 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -249,6 +249,7 @@ make_filename(char *prefix, char *name, char *path)
*p = SEP;
}
len += strlen(name);
+ assert(len < INT_MAX);
return (int)len;
}
@@ -808,7 +809,8 @@ get_data(char *archive, PyObject *toc_entry)
PyObject *raw_data, *data = NULL, *decompress;
char *buf;
FILE *fp;
- int err, bytes_read = 0;
+ int err;
+ Py_ssize_t bytes_read = 0;
long l;
char *datapath;
long compress, data_size, file_size, file_offset;
@@ -1024,7 +1026,7 @@ get_mtime_of_source(ZipImporter *self, char *path)
{
PyObject *toc_entry;
time_t mtime = 0;
- int lastchar = strlen(path) - 1;
+ Py_ssize_t lastchar = strlen(path) - 1;
char savechar = path[lastchar];
path[lastchar] = '\0'; /* strip 'c' or 'o' from *.py[co] */
toc_entry = PyDict_GetItemString(self->files, path);