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

[3.14] gh-152235: Defer GC tracking of set and frozenset to end of construction (gh-152237) by miss-islington · Pull Request #152243 · 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 @@ -1143,7 +1143,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);
if (so == NULL)
return NULL;

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

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

Expand Down Expand Up @@ -2603,7 +2607,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 @@ -2695,7 +2699,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