]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
replace PY_SIZE_MAX with SIZE_MAX
authorBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 16:26:18 +0000 (09:26 -0700)
committerBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 16:26:18 +0000 (09:26 -0700)
12 files changed:
Include/pyport.h
Modules/_elementtree.c
Modules/_tkinter.c
Modules/_tracemalloc.c
Modules/audioop.c
Objects/listobject.c
Objects/longobject.c
Objects/obmalloc.c
Parser/node.c
Python/asdl.c
Python/ast.c
Python/compile.c

index 2f780527dab48e42d871640d4b026738d8d75dca..94c135ff610e16182e9b8c734df820e08444a045 100644 (file)
@@ -115,16 +115,8 @@ typedef Py_ssize_t Py_ssize_clean_t;
 typedef int Py_ssize_clean_t;
 #endif
 
-/* Largest possible value of size_t.
-   SIZE_MAX is part of C99, so it might be defined on some
-   platforms. If it is not defined, (size_t)-1 is a portable
-   definition for C89, due to the way signed->unsigned
-   conversion is defined. */
-#ifdef SIZE_MAX
+/* Largest possible value of size_t. */
 #define PY_SIZE_MAX SIZE_MAX
-#else
-#define PY_SIZE_MAX ((size_t)-1)
-#endif
 
 /* Largest positive value of type Py_ssize_t. */
 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
index ca5ab2cbe2fc9199d35fa04ac971b8fc6e79671f..dd8417a1ac741ca88e7cea68d162b4df6b32872f 100644 (file)
@@ -1787,7 +1787,7 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
                 step = -step;
             }
 
-            assert((size_t)slicelen <= PY_SIZE_MAX / sizeof(PyObject *));
+            assert((size_t)slicelen <= SIZE_MAX / sizeof(PyObject *));
 
             /* recycle is a list that will contain all the children
              * scheduled for removal.
index 8afc4d59f0c699ee8cd0eaa1cb6ad88eb07a939d..21f063d20aa39165821253176339be695ac43b2b 100644 (file)
@@ -976,7 +976,7 @@ static PyType_Spec PyTclObject_Type_spec = {
 };
 
 
-#if PY_SIZE_MAX > INT_MAX
+#if SIZE_MAX > INT_MAX
 #define CHECK_STRING_LENGTH(s) do {                                     \
         if (s != NULL && strlen(s) >= INT_MAX) {                        \
             PyErr_SetString(PyExc_OverflowError, "string is too long"); \
index 1a53cfec252e476742897679de003a27040a6a7b..ec8bd960a7f7e02d9cf12cea11705bab212b3136 100644 (file)
@@ -655,7 +655,7 @@ tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
         }
     }
 
-    assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
+    assert(tracemalloc_traced_memory <= SIZE_MAX - size);
     tracemalloc_traced_memory += size;
     if (tracemalloc_traced_memory > tracemalloc_peak_traced_memory)
         tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
@@ -672,7 +672,7 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
     PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
     void *ptr;
 
-    assert(elsize == 0 || nelem <= PY_SIZE_MAX / elsize);
+    assert(elsize == 0 || nelem <= SIZE_MAX / elsize);
 
     if (use_calloc)
         ptr = alloc->calloc(alloc->ctx, nelem, elsize);
index d715783d52ad4ea58bb9fbcacdd3125f687e8fd2..44e5198b3cf8983ac599e28653e4bce7c4a54eae 100644 (file)
@@ -1337,7 +1337,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
     weightA /= d;
     weightB /= d;
 
-    if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) {
+    if ((size_t)nchannels > SIZE_MAX/sizeof(int)) {
         PyErr_SetString(PyExc_MemoryError,
                         "not enough memory for output buffer");
         return NULL;
index 90bbf2a5d0bbfdaf11bc555c8053a760a26431fe..dcd7b5efe5b0fe7bb0e4c4b20b233f7e7a92b6ed 100644 (file)
@@ -49,7 +49,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
     new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
 
     /* check for integer overflow */
-    if (new_allocated > PY_SIZE_MAX - newsize) {
+    if (new_allocated > SIZE_MAX - newsize) {
         PyErr_NoMemory();
         return -1;
     } else {
@@ -59,7 +59,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
     if (newsize == 0)
         new_allocated = 0;
     items = self->ob_item;
-    if (new_allocated <= (PY_SIZE_MAX / sizeof(PyObject *)))
+    if (new_allocated <= (SIZE_MAX / sizeof(PyObject *)))
         PyMem_RESIZE(items, PyObject *, new_allocated);
     else
         items = NULL;
index 6eb40e40df7257948db31975bb64c3ea9dce948a..740b7f588611fbcb048d42b31ca6088b03027952 100644 (file)
@@ -721,7 +721,7 @@ _PyLong_NumBits(PyObject *vv)
     assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
     if (ndigits > 0) {
         digit msd = v->ob_digit[ndigits - 1];
-        if ((size_t)(ndigits - 1) > PY_SIZE_MAX / (size_t)PyLong_SHIFT)
+        if ((size_t)(ndigits - 1) > SIZE_MAX / (size_t)PyLong_SHIFT)
             goto Overflow;
         result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT;
         do {
index c201da1a37cbfe21650ef3e61741aef41da0b7d8..54d68b75492782e90b25d8f805e4715410d93852 100644 (file)
@@ -1057,7 +1057,7 @@ new_arena(void)
         if (numarenas <= maxarenas)
             return NULL;                /* overflow */
 #if SIZEOF_SIZE_T <= SIZEOF_INT
-        if (numarenas > PY_SIZE_MAX / sizeof(*arenas))
+        if (numarenas > SIZE_MAX / sizeof(*arenas))
             return NULL;                /* overflow */
 #endif
         nbytes = numarenas * sizeof(*arenas);
index 00103240afd593ebbe25aacd67f621f1bb70b493..240d29057c4ef12f93c4982c0bf7972f0619b3a0 100644 (file)
@@ -91,7 +91,7 @@ PyNode_AddChild(node *n1, int type, char *str, int lineno, int col_offset)
     if (current_capacity < 0 || required_capacity < 0)
         return E_OVERFLOW;
     if (current_capacity < required_capacity) {
-        if ((size_t)required_capacity > PY_SIZE_MAX / sizeof(node)) {
+        if ((size_t)required_capacity > SIZE_MAX / sizeof(node)) {
             return E_NOMEM;
         }
         n = n1->n_child;
index df387b2119b6559c7a15b79735b5a8d685153bd7..c21107811813af96ca21a15ae508b0ae39bf9a6e 100644 (file)
@@ -9,14 +9,14 @@ _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
 
     /* check size is sane */
     if (size < 0 ||
-        (size && (((size_t)size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
+        (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
         PyErr_NoMemory();
         return NULL;
     }
     n = (size ? (sizeof(void *) * (size - 1)) : 0);
 
     /* check if size can be added safely */
-    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
+    if (n > SIZE_MAX - sizeof(asdl_seq)) {
         PyErr_NoMemory();
         return NULL;
     }
@@ -40,14 +40,14 @@ _Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
 
     /* check size is sane */
     if (size < 0 ||
-        (size && (((size_t)size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
+        (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
             PyErr_NoMemory();
             return NULL;
     }
     n = (size ? (sizeof(void *) * (size - 1)) : 0);
 
     /* check if size can be added safely */
-    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
+    if (n > SIZE_MAX - sizeof(asdl_seq)) {
         PyErr_NoMemory();
         return NULL;
     }
index 0f9c19333d7c22ef8bb473bffa2902a5fde05bc7..c5f363b6593378fa785f4633697902b4bbba9624 100644 (file)
@@ -3985,7 +3985,7 @@ decode_unicode_with_escapes(struct compiling *c, const char *s, size_t len)
     const char *end;
 
     /* check for integer overflow */
-    if (len > PY_SIZE_MAX / 6)
+    if (len > SIZE_MAX / 6)
         return NULL;
     /* "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
        "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */
index 6fe5d5fa829a0f5d6c4f8420f1cf9d563bb237d9..45e4262b40822f42ae7016592ede63dbd534e5ca 100644 (file)
@@ -804,7 +804,7 @@ compiler_next_instr(struct compiler *c, basicblock *b)
         oldsize = b->b_ialloc * sizeof(struct instr);
         newsize = oldsize << 1;
 
-        if (oldsize > (PY_SIZE_MAX >> 1)) {
+        if (oldsize > (SIZE_MAX >> 1)) {
             PyErr_NoMemory();
             return -1;
         }
@@ -4520,7 +4520,7 @@ assemble_init(struct assembler *a, int nblocks, int firstlineno)
     a->a_lnotab = PyBytes_FromStringAndSize(NULL, DEFAULT_LNOTAB_SIZE);
     if (!a->a_lnotab)
         return 0;
-    if ((size_t)nblocks > PY_SIZE_MAX / sizeof(basicblock *)) {
+    if ((size_t)nblocks > SIZE_MAX / sizeof(basicblock *)) {
         PyErr_NoMemory();
         return 0;
     }