FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-152235: Defer GC tracking of set and frozenset to end of construction by corona10 · Pull Request #152237 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Defer GC tracking of a :class:`set` or :class:`frozenset` to the end of its
construction from iterable. Patch by Donghee Na.
10 changes: 7 additions & 3 deletions Objects/setobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,9 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
assert(PyType_Check(type));
PySetObject *so;

so = (PySetObject *)type->tp_alloc(type, 0);
// Allocate untracked: the fill below runs user code, and a half-built
// set must not be reachable from another thread via gc.get_objects().
so = (PySetObject *)_PyType_AllocNoTrack(type, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should we update the type spec and remove PyType_GenericAlloc from tp_alloc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice catch :)

if (so == NULL)
return NULL;

Expand All @@ -1370,6 +1372,8 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
}
}

// Track only once fully built.
_PyObject_GC_TRACK(so);
return (PyObject *)so;
}

Expand Down Expand Up @@ -2885,7 +2889,7 @@ PyTypeObject PySet_Type = {
0, /* tp_descr_set */
0, /* tp_dictoffset */
set_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
_PyType_AllocNoTrack, /* tp_alloc */
set_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = set_vectorcall,
Expand Down Expand Up @@ -2977,7 +2981,7 @@ PyTypeObject PyFrozenSet_Type = {
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
_PyType_AllocNoTrack, /* tp_alloc */
frozenset_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = frozenset_vectorcall,
Expand Down
Loading

Back | FazBrowse Home | New Git URL