diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-09-08 16:33:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-09-08 16:33:56 (GMT) |
commit | 98ee9d5b738eaf098cfd37c9383f8f2496a964d5 (patch) | |
tree | a8f5041e1ece9795a2b26b61756d5749d3e4834f /Objects | |
parent | 742da040db28e1284615e88874d5c952da80344e (diff) | |
download | cpython-98ee9d5b738eaf098cfd37c9383f8f2496a964d5.zip cpython-98ee9d5b738eaf098cfd37c9383f8f2496a964d5.tar.gz cpython-98ee9d5b738eaf098cfd37c9383f8f2496a964d5.tar.bz2 |
Add Py_MEMBER_SIZE macro
Issue #27350: use Py_MEMBER_SIZE() macro to get the size of
PyDictKeyEntry.dk_indices, rather than hardcoding 8.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 8e5fe82..df5f29f 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -431,9 +431,10 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) dk = keys_free_list[--numfreekeys]; } else { - dk = PyObject_MALLOC(sizeof(PyDictKeysObject) - 8 + - es * size + - sizeof(PyDictKeyEntry) * usable); + dk = PyObject_MALLOC(sizeof(PyDictKeysObject) + - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + + es * size + + sizeof(PyDictKeyEntry) * usable); if (dk == NULL) { PyErr_NoMemory(); return NULL; @@ -2786,17 +2787,20 @@ _PyDict_SizeOf(PyDictObject *mp) /* If the dictionary is split, the keys portion is accounted-for in the type object. */ if (mp->ma_keys->dk_refcnt == 1) - res += sizeof(PyDictKeysObject) - 8 + DK_IXSIZE(mp->ma_keys) * size + - sizeof(PyDictKeyEntry) * usable; + res += (sizeof(PyDictKeysObject) + - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + + DK_IXSIZE(mp->ma_keys) * size + + sizeof(PyDictKeyEntry) * usable); return res; } Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys) { - return sizeof(PyDictKeysObject) - 8 - + DK_IXSIZE(keys) * DK_SIZE(keys) - + USABLE_FRACTION(DK_SIZE(keys)) * sizeof(PyDictKeyEntry); + return (sizeof(PyDictKeysObject) + - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + + DK_IXSIZE(keys) * DK_SIZE(keys) + + USABLE_FRACTION(DK_SIZE(keys)) * sizeof(PyDictKeyEntry)); } static PyObject * |