Thanks to visit codestin.com
Credit goes to github.com

Skip to content

_PyObject_IS_GC() should not use PyType_HasFeature() #124344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
neonene opened this issue Sep 23, 2024 · 2 comments
Closed

_PyObject_IS_GC() should not use PyType_HasFeature() #124344

neonene opened this issue Sep 23, 2024 · 2 comments
Labels
type-feature A feature request or enhancement

Comments

@neonene
Copy link
Contributor

neonene commented Sep 23, 2024

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

@neonene neonene added the type-feature A feature request or enhancement label Sep 23, 2024
@vstinner
Copy link
Member

Do you want to propose a PR?

@vstinner
Copy link
Member

Implemented in d9d5b3d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants