]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39573: Use Py_TYPE() macro in object.c (GH-18398)
authorVictor Stinner <vstinner@python.org>
Fri, 7 Feb 2020 10:18:33 +0000 (11:18 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Feb 2020 10:18:33 +0000 (11:18 +0100)
Replace direct acccess to PyVarObject.ob_size with usage of the
Py_SIZE() macro.

Objects/object.c

index 503fb867802c1e0052657da8b437c8158d16ccfe..ff6c497900cf207b0a4165af4e10a77f62ac1c39 100644 (file)
@@ -1041,13 +1041,11 @@ _PyObject_GetDictPtr(PyObject *obj)
     if (dictoffset == 0)
         return NULL;
     if (dictoffset < 0) {
-        Py_ssize_t tsize;
-        size_t size;
-
-        tsize = ((PyVarObject *)obj)->ob_size;
-        if (tsize < 0)
+        Py_ssize_t tsize = Py_SIZE(obj);
+        if (tsize < 0) {
             tsize = -tsize;
-        size = _PyObject_VAR_SIZE(tp, tsize);
+        }
+        size_t size = _PyObject_VAR_SIZE(tp, tsize);
 
         dictoffset += (long)size;
         _PyObject_ASSERT(obj, dictoffset > 0);
@@ -1219,13 +1217,11 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
         dictoffset = tp->tp_dictoffset;
         if (dictoffset != 0) {
             if (dictoffset < 0) {
-                Py_ssize_t tsize;
-                size_t size;
-
-                tsize = ((PyVarObject *)obj)->ob_size;
-                if (tsize < 0)
+                Py_ssize_t tsize = Py_SIZE(obj);
+                if (tsize < 0) {
                     tsize = -tsize;
-                size = _PyObject_VAR_SIZE(tp, tsize);
+                }
+                size_t size = _PyObject_VAR_SIZE(tp, tsize);
                 _PyObject_ASSERT(obj, size <= PY_SSIZE_T_MAX);
 
                 dictoffset += (Py_ssize_t)size;