Skip to content

Commit 1cb20e6

Browse files
committed
PyObject_GetItemData: parametrize raising
1 parent 9d1386a commit 1cb20e6

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Objects/typeobject.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5995,25 +5995,30 @@ PyType_GetTypeDataSize(PyTypeObject *cls)
59955995
return result;
59965996
}
59975997

5998-
void *
5999-
PyObject_GetItemData_DuringGC(PyObject *obj)
5998+
static inline void
5999+
getitemdata(PyObject *obj, bool raise)
60006000
{
6001-
if (!PyType_HasFeature(Py_TYPE(obj), Py_TPFLAGS_ITEMS_AT_END)) {
6001+
if (!_PyType_HasFeature(Py_TYPE(obj), Py_TPFLAGS_ITEMS_AT_END)) {
6002+
if (raise) {
6003+
PyErr_Format(PyExc_TypeError,
6004+
"type '%T' does not have Py_TPFLAGS_ITEMS_AT_END",
6005+
obj);
6006+
}
60026007
return NULL;
60036008
}
60046009
return (char *)obj + Py_TYPE(obj)->tp_basicsize;
60056010
}
60066011

6012+
void *
6013+
PyObject_GetItemData_DuringGC(PyObject *obj)
6014+
{
6015+
return getitemdata(obj, false);
6016+
}
6017+
60076018
void *
60086019
PyObject_GetItemData(PyObject *obj)
60096020
{
6010-
if (!PyType_HasFeature(Py_TYPE(obj), Py_TPFLAGS_ITEMS_AT_END)) {
6011-
PyErr_Format(PyExc_TypeError,
6012-
"type '%s' does not have Py_TPFLAGS_ITEMS_AT_END",
6013-
Py_TYPE(obj)->tp_name);
6014-
return NULL;
6015-
}
6016-
return PyObject_GetItemData_DuringGC(obj);
6021+
return getitemdata(obj, true);
60176022
}
60186023

60196024
/* Internal API to look for a name through the MRO, bypassing the method cache.

0 commit comments

Comments
 (0)