_PyObject_GetDictPtr(): when the offset is negative, always align --
we can't trust that tp_basicsize is aligned. Fixes SF bug #462848.
This commit is contained in:
parent
aefd766eed
commit
dd4d1c4f5d
@ -1150,18 +1150,13 @@ _PyObject_GetDictPtr(PyObject *obj)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (dictoffset < 0) {
|
if (dictoffset < 0) {
|
||||||
dictoffset += tp->tp_basicsize;
|
dictoffset += tp->tp_basicsize;
|
||||||
|
dictoffset += tp->tp_itemsize * ((PyVarObject *)obj)->ob_size;
|
||||||
assert(dictoffset > 0); /* Sanity check */
|
assert(dictoffset > 0); /* Sanity check */
|
||||||
if (tp->tp_itemsize > 0) {
|
/* Round up, if necessary */
|
||||||
int n = ((PyVarObject *)obj)->ob_size;
|
if (dictoffset % PTRSIZE != 0) {
|
||||||
if (n > 0) {
|
dictoffset /= PTRSIZE;
|
||||||
dictoffset += tp->tp_itemsize * n;
|
dictoffset += 1;
|
||||||
/* Round up, if necessary */
|
dictoffset *= PTRSIZE;
|
||||||
if (tp->tp_itemsize % PTRSIZE != 0) {
|
|
||||||
dictoffset += PTRSIZE - 1;
|
|
||||||
dictoffset /= PTRSIZE;
|
|
||||||
dictoffset *= PTRSIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (PyObject **) ((char *)obj + dictoffset);
|
return (PyObject **) ((char *)obj + dictoffset);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user