diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index ff35862..130e1c6 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3996,8 +3996,8 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds) return -1; } if (PyTuple_GET_SIZE(args)) { - int res = _init_pos_args(self, Py_TYPE(self), - args, kwds, 0); + Py_ssize_t res = _init_pos_args(self, Py_TYPE(self), + args, kwds, 0); if (res == -1) return -1; if (res < PyTuple_GET_SIZE(args)) { diff --git a/Modules/_ctypes/libffi_msvc/prep_cif.c b/Modules/_ctypes/libffi_msvc/prep_cif.c index 2650fa0..9dfa549 100644 --- a/Modules/_ctypes/libffi_msvc/prep_cif.c +++ b/Modules/_ctypes/libffi_msvc/prep_cif.c @@ -89,7 +89,7 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, /*@dependent@*/ ffi_type **atypes) { - unsigned bytes = 0; + size_t bytes = 0; unsigned int i; ffi_type **ptr; diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 3061d8e..57178fb 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -219,8 +219,8 @@ typedef struct { PyObject* attrib; /* child elements */ - int length; /* actual number of items */ - int allocated; /* allocated items */ + Py_ssize_t length; /* actual number of items */ + Py_ssize_t allocated; /* allocated items */ /* this either points to _children or to a malloced buffer */ PyObject* *children; @@ -337,9 +337,9 @@ element_new(PyObject* tag, PyObject* attrib) } LOCAL(int) -element_resize(ElementObject* self, int extra) +element_resize(ElementObject* self, Py_ssize_t extra) { - int size; + Py_ssize_t size; PyObject* *children; /* make sure self->children can hold the given number of extra @@ -693,7 +693,7 @@ element_deepcopy(ElementObject* self, PyObject* args) } /* add object to memo dictionary (so deepcopy won't visit it again) */ - id = PyLong_FromLong((Py_uintptr_t) self); + id = PyLong_FromVoidPtr(self); if (!id) goto error; @@ -1219,7 +1219,7 @@ static int element_setitem(PyObject* self_, Py_ssize_t index, PyObject* item) { ElementObject* self = (ElementObject*) self_; - int i; + Py_ssize_t i; PyObject* old; if (!self->extra || index < 0 || index >= self->extra->length) { @@ -2076,7 +2076,7 @@ makeuniversal(XMLParserObject* self, const char* string) /* convert a UTF-8 tag/attribute name from the expat parser to a universal name string */ - int size = strlen(string); + Py_ssize_t size = strlen(string); PyObject* key; PyObject* value; @@ -2572,11 +2572,16 @@ xmlparser_dealloc(XMLParserObject* self) /* methods (in alphabetical order) */ LOCAL(PyObject*) -expat_parse(XMLParserObject* self, char* data, int data_len, int final) +expat_parse(XMLParserObject* self, char* data, Py_ssize_t data_len, int final) { int ok; - ok = EXPAT(Parse)(self->parser, data, data_len, final); + if (data_len > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, "length doesn't fit in an int"); + return NULL; + } + + ok = EXPAT(Parse)(self->parser, data, (int)data_len, final); if (PyErr_Occurred()) return NULL; diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index bc9b04a..f29a658 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -234,7 +234,7 @@ random_seed(RandomObject *self, PyObject *args) if (PyLong_Check(arg)) n = PyNumber_Absolute(arg); else { - long hash = PyObject_Hash(arg); + Py_hash_t hash = PyObject_Hash(arg); if (hash == -1) goto Done; n = PyLong_FromUnsignedLong((unsigned long)hash); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 11c68d3..049b20c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -871,7 +871,7 @@ wrapper_dealloc(wrapperobject *wp) static PyObject * wrapper_richcompare(PyObject *a, PyObject *b, int op) { - int result; + Py_ssize_t result; PyObject *v; PyWrapperDescrObject *a_descr, *b_descr; diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 10fb8b3..6fbed08 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -464,7 +464,7 @@ static int frame_traverse(PyFrameObject *f, visitproc visit, void *arg) { PyObject **fastlocals, **p; - int i, slots; + Py_ssize_t i, slots; Py_VISIT(f->f_back); Py_VISIT(f->f_code); @@ -477,7 +477,8 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) Py_VISIT(f->f_exc_traceback); /* locals */ - slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); + slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars); + slots += PyTuple_GET_SIZE(f->f_code->co_freevars); fastlocals = f->f_localsplus; for (i = slots; --i >= 0; ++fastlocals) Py_VISIT(*fastlocals); @@ -494,7 +495,7 @@ static void frame_clear(PyFrameObject *f) { PyObject **fastlocals, **p, **oldtop; - int i, slots; + Py_ssize_t i, slots; /* Before anything else, make sure that this frame is clearly marked * as being defunct! Else, e.g., a generator reachable from this @@ -846,7 +847,7 @@ PyFrame_FastToLocals(PyFrameObject *f) PyObject *error_type, *error_value, *error_traceback; PyCodeObject *co; Py_ssize_t j; - int ncells, nfreevars; + Py_ssize_t ncells, nfreevars; if (f == NULL) return; locals = f->f_locals; @@ -897,8 +898,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) PyObject **fast; PyObject *error_type, *error_value, *error_traceback; PyCodeObject *co; - Py_ssize_t j; - int ncells, nfreevars; + Py_ssize_t j, ncells, nfreevars; if (f == NULL) return; locals = f->f_locals; diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 3916262..ad350b6 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -253,7 +253,7 @@ struct pool_header { block *freeblock; /* pool's free list head */ struct pool_header *nextpool; /* next pool of this size class */ struct pool_header *prevpool; /* previous pool "" */ - uint arenaindex; /* index into arenas of base adr */ + size_t arenaindex; /* index into arenas of base adr */ uint szidx; /* block size class index */ uint nextoffset; /* bytes to virgin block */ uint maxnextoffset; /* largest valid nextoffset */ diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 3f6be2f..d74e490 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -663,7 +663,8 @@ translate_into_utf8(const char* str, const char* enc) { static char * translate_newlines(const char *s, int exec_input, struct tok_state *tok) { - int skip_next_lf = 0, needed_length = strlen(s) + 2, final_length; + int skip_next_lf = 0; + size_t needed_length = strlen(s) + 2, final_length; char *buf, *current; char c = '\0'; buf = PyMem_MALLOC(needed_length);