]> granicus.if.org Git - python/commitdiff
bpo-29865: Use PyXXX_GET_SIZE macros rather than Py_SIZE for concrete types. (#748)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 21 Mar 2017 06:53:25 +0000 (08:53 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Mar 2017 06:53:25 +0000 (08:53 +0200)
13 files changed:
Modules/_io/bufferedio.c
Modules/_io/bytesio.c
Modules/_io/iobase.c
Modules/_io/stringio.c
Modules/_json.c
Modules/_pickle.c
Modules/itertoolsmodule.c
Objects/call.c
Objects/descrobject.c
Objects/memoryobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Python/ast.c

index 59e9beb47cf47d286286f3653d0eb9a23d93a246..4f6dddb3a31054e0887e75709c6107f3c174ca6d 100644 (file)
@@ -83,7 +83,7 @@ _bufferediobase_readinto_generic(PyObject *self, Py_buffer *buffer, char readint
         return NULL;
     }
 
-    len = Py_SIZE(data);
+    len = PyBytes_GET_SIZE(data);
     if (len > buffer->len) {
         PyErr_Format(PyExc_ValueError,
                      "read() returned too much data: "
index 59b917d0bdaaa16469c3aa1c3cc77bfe9fdb911c..f78b4475d00a192a291b1c2aac7fa3e50ae8af33 100644 (file)
@@ -822,7 +822,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
     /* We allow the state tuple to be longer than 3, because we may need
        someday to extend the object's state without breaking
        backward-compatibility. */
-    if (!PyTuple_Check(state) || Py_SIZE(state) < 3) {
+    if (!PyTuple_Check(state) || PyTuple_GET_SIZE(state) < 3) {
         PyErr_Format(PyExc_TypeError,
                      "%.200s.__setstate__ argument should be 3-tuple, got %.200s",
                      Py_TYPE(self)->tp_name, Py_TYPE(state)->tp_name);
index ee6ad474b596b7c65eb363dbc7b0cc7b9fe1d412..b176457e0d99dee1bbee0fe861ac151a82dc19d0 100644 (file)
@@ -518,7 +518,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
     if (buffer == NULL)
         return NULL;
 
-    while (limit < 0 || Py_SIZE(buffer) < limit) {
+    while (limit < 0 || PyByteArray_GET_SIZE(buffer) < limit) {
         Py_ssize_t nreadahead = 1;
         PyObject *b;
 
index a73171fd8f602c899fc8bde89747a4260e63ce05..ef450328fa37b644e0600e21efa8d23dade8c555 100644 (file)
@@ -877,7 +877,7 @@ stringio_setstate(stringio *self, PyObject *state)
     /* We allow the state tuple to be longer than 4, because we may need
        someday to extend the object's state without breaking
        backward-compatibility. */
-    if (!PyTuple_Check(state) || Py_SIZE(state) < 4) {
+    if (!PyTuple_Check(state) || PyTuple_GET_SIZE(state) < 4) {
         PyErr_Format(PyExc_TypeError,
                      "%.200s.__setstate__ argument should be 4-tuple, got %.200s",
                      Py_TYPE(self)->tp_name, Py_TYPE(state)->tp_name);
index f4000f83a55891181929118786bf037cb2df2e38..28fdc79834f731125ddb85fc891f29b65307f9f7 100644 (file)
@@ -1654,7 +1654,7 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
     idx = 0;
     while ((item = PyIter_Next(it)) != NULL) {
         PyObject *encoded, *key, *value;
-        if (!PyTuple_Check(item) || Py_SIZE(item) != 2) {
+        if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 2) {
             PyErr_SetString(PyExc_ValueError, "items must return 2-tuples");
             goto bail;
         }
index e65b88e9c0739ae112a1f53f300069428c9e5b60..a6f3abeba06f85836b1f8ae3d15aa324b53056b0 100644 (file)
@@ -3559,10 +3559,10 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
         PyObject *args;
         PyObject *kwargs;
 
-        if (Py_SIZE(argtup) != 3) {
+        if (PyTuple_GET_SIZE(argtup) != 3) {
             PyErr_Format(st->PicklingError,
                          "length of the NEWOBJ_EX argument tuple must be "
-                         "exactly 3, not %zd", Py_SIZE(argtup));
+                         "exactly 3, not %zd", PyTuple_GET_SIZE(argtup));
             return -1;
         }
 
@@ -3602,7 +3602,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
             Py_ssize_t i;
             _Py_IDENTIFIER(__new__);
 
-            newargs = PyTuple_New(Py_SIZE(args) + 2);
+            newargs = PyTuple_New(PyTuple_GET_SIZE(args) + 2);
             if (newargs == NULL)
                 return -1;
 
@@ -3614,7 +3614,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
             PyTuple_SET_ITEM(newargs, 0, cls_new);
             Py_INCREF(cls);
             PyTuple_SET_ITEM(newargs, 1, cls);
-            for (i = 0; i < Py_SIZE(args); i++) {
+            for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
                 PyObject *item = PyTuple_GET_ITEM(args, i);
                 Py_INCREF(item);
                 PyTuple_SET_ITEM(newargs, i + 2, item);
@@ -3649,7 +3649,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
         int p;
 
         /* Sanity checks. */
-        if (Py_SIZE(argtup) < 1) {
+        if (PyTuple_GET_SIZE(argtup) < 1) {
             PyErr_SetString(st->PicklingError, "__newobj__ arglist is empty");
             return -1;
         }
@@ -3702,7 +3702,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
         if (save(self, cls, 0) < 0)
             return -1;
 
-        newargtup = PyTuple_GetSlice(argtup, 1, Py_SIZE(argtup));
+        newargtup = PyTuple_GetSlice(argtup, 1, PyTuple_GET_SIZE(argtup));
         if (newargtup == NULL)
             return -1;
 
@@ -4431,7 +4431,7 @@ Pickler_set_memo(PicklerObject *self, PyObject *obj)
             Py_ssize_t memo_id;
             PyObject *memo_obj;
 
-            if (!PyTuple_Check(value) || Py_SIZE(value) != 2) {
+            if (!PyTuple_Check(value) || PyTuple_GET_SIZE(value) != 2) {
                 PyErr_SetString(PyExc_TypeError,
                                 "'memo' values must be 2-item tuples");
                 goto error;
@@ -5168,7 +5168,7 @@ instantiate(PyObject *cls, PyObject *args)
        Pdata_poptuple which packs objects from the top of the stack
        into a newly created tuple. */
     assert(PyTuple_Check(args));
-    if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
+    if (PyTuple_GET_SIZE(args) > 0 || !PyType_Check(cls) ||
         _PyObject_HasAttrId(cls, &PyId___getinitargs__)) {
         result = PyObject_CallObject(cls, args);
     }
@@ -6048,7 +6048,7 @@ load_build(UnpicklerObject *self)
     /* A default __setstate__.  First see whether state embeds a
      * slot state dict too (a proto 2 addition).
      */
-    if (PyTuple_Check(state) && Py_SIZE(state) == 2) {
+    if (PyTuple_Check(state) && PyTuple_GET_SIZE(state) == 2) {
         PyObject *tmp = state;
 
         state = PyTuple_GET_ITEM(tmp, 0);
index 7cbee2b2fcd477d50f4ac2a08a7ce6c811e61984..f867252481007cd9e582714c1f7069515e92dd3c 100644 (file)
@@ -942,11 +942,11 @@ cycle_next(cycleobject *lz)
             return NULL;
         Py_CLEAR(lz->it);
     }
-    if (Py_SIZE(lz->saved) == 0)
+    if (PyList_GET_SIZE(lz->saved) == 0)
         return NULL;
     item = PyList_GET_ITEM(lz->saved, lz->index);
     lz->index++;
-    if (lz->index >= Py_SIZE(lz->saved))
+    if (lz->index >= PyList_GET_SIZE(lz->saved))
         lz->index = 0;
     Py_INCREF(item);
     return item;
index dd022ec6e89665a63dd7ecd0d2c9b2d5546e47f4..7890c138d6151316ab143677e52b13db961552ea 100644 (file)
@@ -321,11 +321,12 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
             return function_code_fastcall(co, args, nargs, globals);
         }
         else if (nargs == 0 && argdefs != NULL
-                 && co->co_argcount == Py_SIZE(argdefs)) {
+                 && co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
             /* function called with no arguments, but all parameters have
                a default value: use default values as arguments .*/
             args = &PyTuple_GET_ITEM(argdefs, 0);
-            return function_code_fastcall(co, args, Py_SIZE(argdefs), globals);
+            return function_code_fastcall(co, args, PyTuple_GET_SIZE(argdefs),
+                                          globals);
         }
     }
 
@@ -364,7 +365,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
 
     if (argdefs != NULL) {
         d = &PyTuple_GET_ITEM(argdefs, 0);
-        nd = Py_SIZE(argdefs);
+        nd = PyTuple_GET_SIZE(argdefs);
     }
     else {
         d = NULL;
@@ -406,11 +407,12 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject **stack,
             return function_code_fastcall(co, stack, nargs, globals);
         }
         else if (nargs == 0 && argdefs != NULL
-                 && co->co_argcount == Py_SIZE(argdefs)) {
+                 && co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
             /* function called with no arguments, but all parameters have
                a default value: use default values as arguments .*/
             stack = &PyTuple_GET_ITEM(argdefs, 0);
-            return function_code_fastcall(co, stack, Py_SIZE(argdefs), globals);
+            return function_code_fastcall(co, stack, PyTuple_GET_SIZE(argdefs),
+                                          globals);
         }
     }
 
@@ -421,7 +423,7 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject **stack,
 
     if (argdefs != NULL) {
         d = &PyTuple_GET_ITEM(argdefs, 0);
-        nd = Py_SIZE(argdefs);
+        nd = PyTuple_GET_SIZE(argdefs);
     }
     else {
         d = NULL;
index 8677cdd754a229962fb2084de4a2cc9a2488c956..1d11605a9b8d3bf1ad8b38752a186f3368339567 100644 (file)
@@ -1385,7 +1385,7 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
     PyTuple_SET_ITEM(args, 0, obj);
     ret = PyObject_Call(gs->prop_get, args, NULL);
     if (cached_args == NULL && Py_REFCNT(args) == 1) {
-        assert(Py_SIZE(args) == 1);
+        assert(PyTuple_GET_SIZE(args) == 1);
         assert(PyTuple_GET_ITEM(args, 0) == obj);
         cached_args = args;
         Py_DECREF(obj);
index b1798a2073d108cff67a2f5453971b68b50aa1c0..8a2316333b06da26902be8d879972f0bb76521b9 100644 (file)
@@ -2143,7 +2143,7 @@ memory_hex(PyMemoryViewObject *self, PyObject *dummy)
     if (bytes == NULL)
         return NULL;
 
-    ret = _Py_strhex(PyBytes_AS_STRING(bytes), Py_SIZE(bytes));
+    ret = _Py_strhex(PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes));
     Py_DECREF(bytes);
 
     return ret;
index 3e1e8d7725acc7d9586978db46b296dd9adb05a0..64a72d2f14661236f3d1d1e96201f5cfce19143a 100644 (file)
@@ -4022,7 +4022,7 @@ _PyObject_GetState(PyObject *obj, int required)
             if (obj->ob_type->tp_weaklistoffset)
                 basicsize += sizeof(PyObject *);
             if (slotnames != Py_None)
-                basicsize += sizeof(PyObject *) * Py_SIZE(slotnames);
+                basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames);
             if (obj->ob_type->tp_basicsize > basicsize) {
                 Py_DECREF(slotnames);
                 Py_DECREF(state);
@@ -4033,7 +4033,7 @@ _PyObject_GetState(PyObject *obj, int required)
             }
         }
 
-        if (slotnames != Py_None && Py_SIZE(slotnames) > 0) {
+        if (slotnames != Py_None && PyList_GET_SIZE(slotnames) > 0) {
             PyObject *slots;
             Py_ssize_t slotnames_size, i;
 
@@ -4044,7 +4044,7 @@ _PyObject_GetState(PyObject *obj, int required)
                 return NULL;
             }
 
-            slotnames_size = Py_SIZE(slotnames);
+            slotnames_size = PyList_GET_SIZE(slotnames);
             for (i = 0; i < slotnames_size; i++) {
                 PyObject *name, *value;
 
@@ -4070,7 +4070,7 @@ _PyObject_GetState(PyObject *obj, int required)
 
                 /* The list is stored on the class so it may mutate while we
                    iterate over it */
-                if (slotnames_size != Py_SIZE(slotnames)) {
+                if (slotnames_size != PyList_GET_SIZE(slotnames)) {
                     PyErr_Format(PyExc_RuntimeError,
                                  "__slotsname__ changed size during iteration");
                     goto error;
@@ -4142,10 +4142,10 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
             Py_DECREF(newargs);
             return -1;
         }
-        if (Py_SIZE(newargs) != 2) {
+        if (PyTuple_GET_SIZE(newargs) != 2) {
             PyErr_Format(PyExc_ValueError,
                          "__getnewargs_ex__ should return a tuple of "
-                         "length 2, not %zd", Py_SIZE(newargs));
+                         "length 2, not %zd", PyTuple_GET_SIZE(newargs));
             Py_DECREF(newargs);
             return -1;
         }
index 1a696cc5c89ead6e078a8511d91d49bd877e0d78..d3a7f54d0e705b58e2aeff757d1518b8f5199bfa 100644 (file)
@@ -3633,7 +3633,8 @@ PyUnicode_AsEncodedString(PyObject *unicode,
             return NULL;
         }
 
-        b = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
+        b = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v),
+                                      PyByteArray_GET_SIZE(v));
         Py_DECREF(v);
         return b;
     }
index 55beef580a9baa5d60755104fae1e5183f2dfffa..d8941f039e57e97afe023dc6539bcd4c7bcb032d 100644 (file)
@@ -4221,7 +4221,7 @@ decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s,
                 p += 10;
             }
             /* Should be impossible to overflow */
-            assert(p - buf <= Py_SIZE(u));
+            assert(p - buf <= PyBytes_GET_SIZE(u));
             Py_DECREF(w);
         } else {
             *p++ = *s++;