diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-04-14 18:11:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 18:11:20 (GMT) |
commit | 675d9a3d7afc767a2818c84da7ba4bf4181dcf26 (patch) | |
tree | 621da3f9078df542c36e8bb856c6d86da4ce52b0 /Include | |
parent | a5900ecf9f22e65bef489633692e9ea6941379c5 (diff) | |
download | cpython-675d9a3d7afc767a2818c84da7ba4bf4181dcf26.zip cpython-675d9a3d7afc767a2818c84da7ba4bf4181dcf26.tar.gz cpython-675d9a3d7afc767a2818c84da7ba4bf4181dcf26.tar.bz2 |
bpo-40170: Convert PyObject_IS_GC() macro to a function (GH-19464)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/objimpl.h | 7 | ||||
-rw-r--r-- | Include/internal/pycore_object.h | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h index 6634f29..b835936 100644 --- a/Include/cpython/objimpl.h +++ b/Include/cpython/objimpl.h @@ -120,10 +120,9 @@ PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); PyAPI_FUNC(Py_ssize_t) _PyGC_CollectIfEnabled(void); -/* Test if an object has a GC head */ -#define PyObject_IS_GC(o) \ - (PyType_IS_GC(Py_TYPE(o)) \ - && (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o))) +/* Test if an object implements the garbage collector protocol */ +PyAPI_FUNC(int) PyObject_IS_GC(PyObject *obj); + /* Code built with Py_BUILD_CORE must include pycore_gc.h instead which defines a different _PyGC_FINALIZED() macro. */ diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 7c0f24a..32e86d0 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -102,6 +102,15 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) { return ((type->tp_flags & feature) != 0); } +// Fast inlined version of PyObject_IS_GC() +static inline int +_PyObject_IS_GC(PyObject *obj) +{ + return (PyType_IS_GC(Py_TYPE(obj)) + && (Py_TYPE(obj)->tp_is_gc == NULL + || Py_TYPE(obj)->tp_is_gc(obj))); +} + // Fast inlined version of PyType_IS_GC() #define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC) |