Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f8bfef

Browse files
committed
replace PY_SIZE_MAX with SIZE_MAX
1 parent c75abff commit 2f8bfef

12 files changed

Lines changed: 18 additions & 26 deletions

File tree

Include/pyport.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,8 @@ typedef Py_ssize_t Py_ssize_clean_t;
115115
typedef int Py_ssize_clean_t;
116116
#endif
117117

118-
/* Largest possible value of size_t.
119-
SIZE_MAX is part of C99, so it might be defined on some
120-
platforms. If it is not defined, (size_t)-1 is a portable
121-
definition for C89, due to the way signed->unsigned
122-
conversion is defined. */
123-
#ifdef SIZE_MAX
118+
/* Largest possible value of size_t. */
124119
#define PY_SIZE_MAX SIZE_MAX
125-
#else
126-
#define PY_SIZE_MAX ((size_t)-1)
127-
#endif
128120

129121
/* Largest positive value of type Py_ssize_t. */
130122
#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
17871787
step = -step;
17881788
}
17891789

1790-
assert((size_t)slicelen <= PY_SIZE_MAX / sizeof(PyObject *));
1790+
assert((size_t)slicelen <= SIZE_MAX / sizeof(PyObject *));
17911791

17921792
/* recycle is a list that will contain all the children
17931793
* scheduled for removal.

Modules/_tkinter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ static PyType_Spec PyTclObject_Type_spec = {
976976
};
977977

978978

979-
#if PY_SIZE_MAX > INT_MAX
979+
#if SIZE_MAX > INT_MAX
980980
#define CHECK_STRING_LENGTH(s) do { \
981981
if (s != NULL && strlen(s) >= INT_MAX) { \
982982
PyErr_SetString(PyExc_OverflowError, "string is too long"); \

Modules/_tracemalloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
655655
}
656656
}
657657

658-
assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
658+
assert(tracemalloc_traced_memory <= SIZE_MAX - size);
659659
tracemalloc_traced_memory += size;
660660
if (tracemalloc_traced_memory > tracemalloc_peak_traced_memory)
661661
tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
@@ -672,7 +672,7 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
672672
PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
673673
void *ptr;
674674

675-
assert(elsize == 0 || nelem <= PY_SIZE_MAX / elsize);
675+
assert(elsize == 0 || nelem <= SIZE_MAX / elsize);
676676

677677
if (use_calloc)
678678
ptr = alloc->calloc(alloc->ctx, nelem, elsize);

Modules/audioop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
13371337
weightA /= d;
13381338
weightB /= d;
13391339

1340-
if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) {
1340+
if ((size_t)nchannels > SIZE_MAX/sizeof(int)) {
13411341
PyErr_SetString(PyExc_MemoryError,
13421342
"not enough memory for output buffer");
13431343
return NULL;

Objects/listobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
4949
new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
5050

5151
/* check for integer overflow */
52-
if (new_allocated > PY_SIZE_MAX - newsize) {
52+
if (new_allocated > SIZE_MAX - newsize) {
5353
PyErr_NoMemory();
5454
return -1;
5555
} else {
@@ -59,7 +59,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
5959
if (newsize == 0)
6060
new_allocated = 0;
6161
items = self->ob_item;
62-
if (new_allocated <= (PY_SIZE_MAX / sizeof(PyObject *)))
62+
if (new_allocated <= (SIZE_MAX / sizeof(PyObject *)))
6363
PyMem_RESIZE(items, PyObject *, new_allocated);
6464
else
6565
items = NULL;

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ _PyLong_NumBits(PyObject *vv)
721721
assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
722722
if (ndigits > 0) {
723723
digit msd = v->ob_digit[ndigits - 1];
724-
if ((size_t)(ndigits - 1) > PY_SIZE_MAX / (size_t)PyLong_SHIFT)
724+
if ((size_t)(ndigits - 1) > SIZE_MAX / (size_t)PyLong_SHIFT)
725725
goto Overflow;
726726
result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT;
727727
do {

Objects/obmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ new_arena(void)
10571057
if (numarenas <= maxarenas)
10581058
return NULL; /* overflow */
10591059
#if SIZEOF_SIZE_T <= SIZEOF_INT
1060-
if (numarenas > PY_SIZE_MAX / sizeof(*arenas))
1060+
if (numarenas > SIZE_MAX / sizeof(*arenas))
10611061
return NULL; /* overflow */
10621062
#endif
10631063
nbytes = numarenas * sizeof(*arenas);

Parser/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PyNode_AddChild(node *n1, int type, char *str, int lineno, int col_offset)
9191
if (current_capacity < 0 || required_capacity < 0)
9292
return E_OVERFLOW;
9393
if (current_capacity < required_capacity) {
94-
if ((size_t)required_capacity > PY_SIZE_MAX / sizeof(node)) {
94+
if ((size_t)required_capacity > SIZE_MAX / sizeof(node)) {
9595
return E_NOMEM;
9696
}
9797
n = n1->n_child;

Python/asdl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
99

1010
/* check size is sane */
1111
if (size < 0 ||
12-
(size && (((size_t)size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
12+
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
1313
PyErr_NoMemory();
1414
return NULL;
1515
}
1616
n = (size ? (sizeof(void *) * (size - 1)) : 0);
1717

1818
/* check if size can be added safely */
19-
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
19+
if (n > SIZE_MAX - sizeof(asdl_seq)) {
2020
PyErr_NoMemory();
2121
return NULL;
2222
}
@@ -40,14 +40,14 @@ _Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
4040

4141
/* check size is sane */
4242
if (size < 0 ||
43-
(size && (((size_t)size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
43+
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
4444
PyErr_NoMemory();
4545
return NULL;
4646
}
4747
n = (size ? (sizeof(void *) * (size - 1)) : 0);
4848

4949
/* check if size can be added safely */
50-
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
50+
if (n > SIZE_MAX - sizeof(asdl_seq)) {
5151
PyErr_NoMemory();
5252
return NULL;
5353
}

0 commit comments

Comments
 (0)