Skip to content

_PyObject_IS_GC() should not use PyType_HasFeature() #124344

@neonene

Description

@neonene

Feature or enhancement

Proposal:

_PyObject_IS_GC() is one of the most frequently used functions, which keeps using PyType_HasFeature() rather than _PyType_HasFeature().

I know it has no performance issues since introduced, but switching to use _PyType_HasFeature() would make more sense:

  • Include/internal/pycore_object.h
// Fast inlined version of PyObject_IS_GC()
static inline int
_PyObject_IS_GC(PyObject *obj)
{
    PyTypeObject *type = Py_TYPE(obj);
    return (PyType_IS_GC(type)
            && (type->tp_is_gc == NULL || type->tp_is_gc(obj)));
}
...
// Fast inlined version of PyType_IS_GC()
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
  • Include/objimpl.h
/* Test if a type has a GC head */
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)

cc @vstinner

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions