Skip to content

bpo-44562: Use PyType_GenericAlloc in Py_GenericAlias #27021

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

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ PyTypeObject Py_GenericAliasType = {
PyObject *
Py_GenericAlias(PyObject *origin, PyObject *args)
{
gaobject *alias = PyObject_GC_New(gaobject, &Py_GenericAliasType);
gaobject *alias = (gaobject*) PyType_GenericAlloc(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyType_GenericAlloc() calls _PyObject_GC_Malloc() instead of PyObject_GC_New().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_PyObject_GC_New calls _PyObject_GC_Malloc + _PyObject_Init, which PyType_GenericAlloc also calls. What I am missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right then.

Please fix also ga_new().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ga_new doesn't seem to need the fix. It uses tp_alloc which is set to PyType_GenericAlloc .

(PyTypeObject *)&Py_GenericAliasType, 0);
if (alias == NULL) {
return NULL;
}
_PyObject_GC_TRACK(alias);
if (!setup_ga(alias, origin, args)) {
Py_DECREF(alias);
return NULL;
Expand Down