]> granicus.if.org Git - python/commitdiff
_PyObject_GetDictPtr(): when the offset is negative, always align --
authorGuido van Rossum <guido@python.org>
Thu, 20 Sep 2001 13:38:22 +0000 (13:38 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 20 Sep 2001 13:38:22 +0000 (13:38 +0000)
we can't trust that tp_basicsize is aligned.  Fixes SF bug #462848.

Objects/object.c

index 668bd4f33246fee6957f028877bafce94a0973db..6d7a5e9aeb02e205eb69fb621ae2aa4b0a46f673 100644 (file)
@@ -1150,18 +1150,13 @@ _PyObject_GetDictPtr(PyObject *obj)
                return NULL;
        if (dictoffset < 0) {
                dictoffset += tp->tp_basicsize;
+               dictoffset += tp->tp_itemsize * ((PyVarObject *)obj)->ob_size;
                assert(dictoffset > 0); /* Sanity check */
-               if (tp->tp_itemsize > 0) {
-                       int n = ((PyVarObject *)obj)->ob_size;
-                       if (n > 0) {
-                               dictoffset += tp->tp_itemsize * n;
-                               /* Round up, if necessary */
-                               if (tp->tp_itemsize % PTRSIZE != 0) {
-                                       dictoffset += PTRSIZE - 1;
-                                       dictoffset /= PTRSIZE;
-                                       dictoffset *= PTRSIZE;
-                               }
-                       }
+               /* Round up, if necessary */
+               if (dictoffset % PTRSIZE != 0) {
+                       dictoffset /= PTRSIZE;
+                       dictoffset += 1;
+                       dictoffset *= PTRSIZE;
                }
        }
        return (PyObject **) ((char *)obj + dictoffset);