Skip to content

Commit fff9a31

Browse files
bpo-29865: Use PyXXX_GET_SIZE macros rather than Py_SIZE for concrete types. (python#748)
1 parent c61ac16 commit fff9a31

13 files changed

Lines changed: 35 additions & 32 deletions

File tree

Modules/_io/bufferedio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ _bufferediobase_readinto_generic(PyObject *self, Py_buffer *buffer, char readint
8383
return NULL;
8484
}
8585

86-
len = Py_SIZE(data);
86+
len = PyBytes_GET_SIZE(data);
8787
if (len > buffer->len) {
8888
PyErr_Format(PyExc_ValueError,
8989
"read() returned too much data: "

Modules/_io/bytesio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
822822
/* We allow the state tuple to be longer than 3, because we may need
823823
someday to extend the object's state without breaking
824824
backward-compatibility. */
825-
if (!PyTuple_Check(state) || Py_SIZE(state) < 3) {
825+
if (!PyTuple_Check(state) || PyTuple_GET_SIZE(state) < 3) {
826826
PyErr_Format(PyExc_TypeError,
827827
"%.200s.__setstate__ argument should be 3-tuple, got %.200s",
828828
Py_TYPE(self)->tp_name, Py_TYPE(state)->tp_name);

Modules/_io/iobase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
518518
if (buffer == NULL)
519519
return NULL;
520520

521-
while (limit < 0 || Py_SIZE(buffer) < limit) {
521+
while (limit < 0 || PyByteArray_GET_SIZE(buffer) < limit) {
522522
Py_ssize_t nreadahead = 1;
523523
PyObject *b;
524524

Modules/_io/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ stringio_setstate(stringio *self, PyObject *state)
877877
/* We allow the state tuple to be longer than 4, because we may need
878878
someday to extend the object's state without breaking
879879
backward-compatibility. */
880-
if (!PyTuple_Check(state) || Py_SIZE(state) < 4) {
880+
if (!PyTuple_Check(state) || PyTuple_GET_SIZE(state) < 4) {
881881
PyErr_Format(PyExc_TypeError,
882882
"%.200s.__setstate__ argument should be 4-tuple, got %.200s",
883883
Py_TYPE(self)->tp_name, Py_TYPE(state)->tp_name);

Modules/_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
16541654
idx = 0;
16551655
while ((item = PyIter_Next(it)) != NULL) {
16561656
PyObject *encoded, *key, *value;
1657-
if (!PyTuple_Check(item) || Py_SIZE(item) != 2) {
1657+
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 2) {
16581658
PyErr_SetString(PyExc_ValueError, "items must return 2-tuples");
16591659
goto bail;
16601660
}

Modules/_pickle.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,10 +3559,10 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
35593559
PyObject *args;
35603560
PyObject *kwargs;
35613561

3562-
if (Py_SIZE(argtup) != 3) {
3562+
if (PyTuple_GET_SIZE(argtup) != 3) {
35633563
PyErr_Format(st->PicklingError,
35643564
"length of the NEWOBJ_EX argument tuple must be "
3565-
"exactly 3, not %zd", Py_SIZE(argtup));
3565+
"exactly 3, not %zd", PyTuple_GET_SIZE(argtup));
35663566
return -1;
35673567
}
35683568

@@ -3602,7 +3602,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
36023602
Py_ssize_t i;
36033603
_Py_IDENTIFIER(__new__);
36043604

3605-
newargs = PyTuple_New(Py_SIZE(args) + 2);
3605+
newargs = PyTuple_New(PyTuple_GET_SIZE(args) + 2);
36063606
if (newargs == NULL)
36073607
return -1;
36083608

@@ -3614,7 +3614,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
36143614
PyTuple_SET_ITEM(newargs, 0, cls_new);
36153615
Py_INCREF(cls);
36163616
PyTuple_SET_ITEM(newargs, 1, cls);
3617-
for (i = 0; i < Py_SIZE(args); i++) {
3617+
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
36183618
PyObject *item = PyTuple_GET_ITEM(args, i);
36193619
Py_INCREF(item);
36203620
PyTuple_SET_ITEM(newargs, i + 2, item);
@@ -3649,7 +3649,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
36493649
int p;
36503650

36513651
/* Sanity checks. */
3652-
if (Py_SIZE(argtup) < 1) {
3652+
if (PyTuple_GET_SIZE(argtup) < 1) {
36533653
PyErr_SetString(st->PicklingError, "__newobj__ arglist is empty");
36543654
return -1;
36553655
}
@@ -3702,7 +3702,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
37023702
if (save(self, cls, 0) < 0)
37033703
return -1;
37043704

3705-
newargtup = PyTuple_GetSlice(argtup, 1, Py_SIZE(argtup));
3705+
newargtup = PyTuple_GetSlice(argtup, 1, PyTuple_GET_SIZE(argtup));
37063706
if (newargtup == NULL)
37073707
return -1;
37083708

@@ -4431,7 +4431,7 @@ Pickler_set_memo(PicklerObject *self, PyObject *obj)
44314431
Py_ssize_t memo_id;
44324432
PyObject *memo_obj;
44334433

4434-
if (!PyTuple_Check(value) || Py_SIZE(value) != 2) {
4434+
if (!PyTuple_Check(value) || PyTuple_GET_SIZE(value) != 2) {
44354435
PyErr_SetString(PyExc_TypeError,
44364436
"'memo' values must be 2-item tuples");
44374437
goto error;
@@ -5168,7 +5168,7 @@ instantiate(PyObject *cls, PyObject *args)
51685168
Pdata_poptuple which packs objects from the top of the stack
51695169
into a newly created tuple. */
51705170
assert(PyTuple_Check(args));
5171-
if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
5171+
if (PyTuple_GET_SIZE(args) > 0 || !PyType_Check(cls) ||
51725172
_PyObject_HasAttrId(cls, &PyId___getinitargs__)) {
51735173
result = PyObject_CallObject(cls, args);
51745174
}
@@ -6048,7 +6048,7 @@ load_build(UnpicklerObject *self)
60486048
/* A default __setstate__. First see whether state embeds a
60496049
* slot state dict too (a proto 2 addition).
60506050
*/
6051-
if (PyTuple_Check(state) && Py_SIZE(state) == 2) {
6051+
if (PyTuple_Check(state) && PyTuple_GET_SIZE(state) == 2) {
60526052
PyObject *tmp = state;
60536053

60546054
state = PyTuple_GET_ITEM(tmp, 0);

Modules/itertoolsmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,11 @@ cycle_next(cycleobject *lz)
942942
return NULL;
943943
Py_CLEAR(lz->it);
944944
}
945-
if (Py_SIZE(lz->saved) == 0)
945+
if (PyList_GET_SIZE(lz->saved) == 0)
946946
return NULL;
947947
item = PyList_GET_ITEM(lz->saved, lz->index);
948948
lz->index++;
949-
if (lz->index >= Py_SIZE(lz->saved))
949+
if (lz->index >= PyList_GET_SIZE(lz->saved))
950950
lz->index = 0;
951951
Py_INCREF(item);
952952
return item;

Objects/call.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
321321
return function_code_fastcall(co, args, nargs, globals);
322322
}
323323
else if (nargs == 0 && argdefs != NULL
324-
&& co->co_argcount == Py_SIZE(argdefs)) {
324+
&& co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
325325
/* function called with no arguments, but all parameters have
326326
a default value: use default values as arguments .*/
327327
args = &PyTuple_GET_ITEM(argdefs, 0);
328-
return function_code_fastcall(co, args, Py_SIZE(argdefs), globals);
328+
return function_code_fastcall(co, args, PyTuple_GET_SIZE(argdefs),
329+
globals);
329330
}
330331
}
331332

@@ -364,7 +365,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
364365

365366
if (argdefs != NULL) {
366367
d = &PyTuple_GET_ITEM(argdefs, 0);
367-
nd = Py_SIZE(argdefs);
368+
nd = PyTuple_GET_SIZE(argdefs);
368369
}
369370
else {
370371
d = NULL;
@@ -406,11 +407,12 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject **stack,
406407
return function_code_fastcall(co, stack, nargs, globals);
407408
}
408409
else if (nargs == 0 && argdefs != NULL
409-
&& co->co_argcount == Py_SIZE(argdefs)) {
410+
&& co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
410411
/* function called with no arguments, but all parameters have
411412
a default value: use default values as arguments .*/
412413
stack = &PyTuple_GET_ITEM(argdefs, 0);
413-
return function_code_fastcall(co, stack, Py_SIZE(argdefs), globals);
414+
return function_code_fastcall(co, stack, PyTuple_GET_SIZE(argdefs),
415+
globals);
414416
}
415417
}
416418

@@ -421,7 +423,7 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject **stack,
421423

422424
if (argdefs != NULL) {
423425
d = &PyTuple_GET_ITEM(argdefs, 0);
424-
nd = Py_SIZE(argdefs);
426+
nd = PyTuple_GET_SIZE(argdefs);
425427
}
426428
else {
427429
d = NULL;

Objects/descrobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
13851385
PyTuple_SET_ITEM(args, 0, obj);
13861386
ret = PyObject_Call(gs->prop_get, args, NULL);
13871387
if (cached_args == NULL && Py_REFCNT(args) == 1) {
1388-
assert(Py_SIZE(args) == 1);
1388+
assert(PyTuple_GET_SIZE(args) == 1);
13891389
assert(PyTuple_GET_ITEM(args, 0) == obj);
13901390
cached_args = args;
13911391
Py_DECREF(obj);

Objects/memoryobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ memory_hex(PyMemoryViewObject *self, PyObject *dummy)
21432143
if (bytes == NULL)
21442144
return NULL;
21452145

2146-
ret = _Py_strhex(PyBytes_AS_STRING(bytes), Py_SIZE(bytes));
2146+
ret = _Py_strhex(PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes));
21472147
Py_DECREF(bytes);
21482148

21492149
return ret;

0 commit comments

Comments
 (0)