Skip to content

Commit c65b320

Browse files
authored
bpo-39573: Use Py_TYPE() macro in object.c (GH-18398)
Replace direct acccess to PyVarObject.ob_size with usage of the Py_SIZE() macro.
1 parent bec4186 commit c65b320

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Objects/object.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -1041,13 +1041,11 @@ _PyObject_GetDictPtr(PyObject *obj)
10411041
if (dictoffset == 0)
10421042
return NULL;
10431043
if (dictoffset < 0) {
1044-
Py_ssize_t tsize;
1045-
size_t size;
1046-
1047-
tsize = ((PyVarObject *)obj)->ob_size;
1048-
if (tsize < 0)
1044+
Py_ssize_t tsize = Py_SIZE(obj);
1045+
if (tsize < 0) {
10491046
tsize = -tsize;
1050-
size = _PyObject_VAR_SIZE(tp, tsize);
1047+
}
1048+
size_t size = _PyObject_VAR_SIZE(tp, tsize);
10511049

10521050
dictoffset += (long)size;
10531051
_PyObject_ASSERT(obj, dictoffset > 0);
@@ -1219,13 +1217,11 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
12191217
dictoffset = tp->tp_dictoffset;
12201218
if (dictoffset != 0) {
12211219
if (dictoffset < 0) {
1222-
Py_ssize_t tsize;
1223-
size_t size;
1224-
1225-
tsize = ((PyVarObject *)obj)->ob_size;
1226-
if (tsize < 0)
1220+
Py_ssize_t tsize = Py_SIZE(obj);
1221+
if (tsize < 0) {
12271222
tsize = -tsize;
1228-
size = _PyObject_VAR_SIZE(tp, tsize);
1223+
}
1224+
size_t size = _PyObject_VAR_SIZE(tp, tsize);
12291225
_PyObject_ASSERT(obj, size <= PY_SSIZE_T_MAX);
12301226

12311227
dictoffset += (Py_ssize_t)size;

0 commit comments

Comments
 (0)