Skip to content

Commit 4bb2a1e

Browse files
author
Erlend Egeberg Aasland
authored
bpo-43181: Convert PyObject_TypeCheck to static inline function (GH-24533)
1 parent fcbe0cb commit 4bb2a1e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Doc/c-api/object.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ Object Protocol
297297
298298
.. c:function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
299299
300-
Return true if the object *o* is of type *type* or a subtype of *type*. Both
301-
parameters must be non-``NULL``.
300+
Return non-zero if the object *o* is of type *type* or a subtype of *type*, and
301+
``0`` otherwise. Both parameters must be non-``NULL``.
302302
303303
304304
.. c:function:: Py_ssize_t PyObject_Size(PyObject *o)

Include/object.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ PyAPI_FUNC(void *) PyType_GetModuleState(struct _typeobject *);
235235

236236
/* Generic type check */
237237
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
238-
#define PyObject_TypeCheck(ob, tp) \
239-
(Py_IS_TYPE(ob, tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
238+
239+
static inline int _PyObject_TypeCheck(PyObject *ob, PyTypeObject *type) {
240+
return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
241+
}
242+
#define PyObject_TypeCheck(ob, type) _PyObject_TypeCheck(_PyObject_CAST(ob), type)
240243

241244
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
242245
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Convert :c:func:`PyObject_TypeCheck` macro to a static inline function. Patch by
2+
Erlend E. Aasland.

0 commit comments

Comments
 (0)