mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-39542: Convert PyType_Check() to static inline function (GH-18364)
Convert PyType_HasFeature(), PyType_Check() and PyType_CheckExact() macros to static inline functions.
This commit is contained in:
parent
f58bd7c169
commit
509dd90f46
4 changed files with 30 additions and 17 deletions
|
@ -207,10 +207,6 @@ PyAPI_DATA(struct _typeobject) PySuper_Type; /* built-in 'super' */
|
|||
|
||||
PyAPI_FUNC(unsigned long) PyType_GetFlags(struct _typeobject*);
|
||||
|
||||
#define PyType_Check(op) \
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
|
||||
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
|
||||
|
||||
PyAPI_FUNC(int) PyType_Ready(struct _typeobject *);
|
||||
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(struct _typeobject *, Py_ssize_t);
|
||||
PyAPI_FUNC(PyObject *) PyType_GenericNew(struct _typeobject *,
|
||||
|
@ -342,11 +338,6 @@ given type object has a specified feature.
|
|||
/* Type structure has tp_finalize member (3.4) */
|
||||
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
|
||||
|
||||
#ifdef Py_LIMITED_API
|
||||
# define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
|
||||
#endif
|
||||
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
|
||||
|
||||
|
||||
/*
|
||||
The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
|
||||
|
@ -600,6 +591,28 @@ times.
|
|||
# undef Py_CPYTHON_OBJECT_H
|
||||
#endif
|
||||
|
||||
|
||||
static inline int
|
||||
PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
|
||||
#ifdef Py_LIMITED_API
|
||||
return ((PyType_GetFlags(type) & feature) != 0);
|
||||
#else
|
||||
return ((type->tp_flags & feature) != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PyType_FastSubclass(type, flag) PyType_HasFeature(type, flag)
|
||||
|
||||
static inline int _PyType_Check(PyObject *op) {
|
||||
return PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS);
|
||||
}
|
||||
#define PyType_Check(op) _PyType_Check(_PyObject_CAST(op))
|
||||
|
||||
static inline int _PyType_CheckExact(PyObject *op) {
|
||||
return (Py_TYPE(op) == &PyType_Type);
|
||||
}
|
||||
#define PyType_CheckExact(op) _PyType_CheckExact(_PyObject_CAST(op))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue