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

gh-152235: Defer GC tracking during the lock-free fill in set.__init__ by corona10 · Pull Request #153079 · python/cpython · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type 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
31 changes: 23 additions & 8 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 @@ -2770,21 +2770,36 @@ set_init(PyObject *so, PyObject *args, PyObject *kwds)
if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
return -1;

if (_PyObject_IsUniquelyReferenced((PyObject *)self) && self->fill == 0) {
self->hash = -1;
if (iterable == NULL) {
return 0;
}
return set_update_local(self, iterable);
if (!_PyObject_IsUniquelyReferenced((PyObject *)self) || self->fill != 0) {
goto shared;
}

_PyObject_GC_UNTRACK(self);
// Double-check that the object is still uniquely referenced after untracking it.
if (!_PyObject_IsUniquelyReferenced((PyObject *)self)) {
_PyObject_GC_TRACK(self);
goto shared;
}

self->hash = -1;
int rv = 0;
if (iterable != NULL) {
rv = set_update_local(self, iterable);
}
_PyObject_GC_TRACK(self);
return rv;

shared:
Py_BEGIN_CRITICAL_SECTION(self);
if (self->fill)
if (self->fill) {
set_clear_internal((PyObject*)self);
}
self->hash = -1;
Py_END_CRITICAL_SECTION();

if (iterable == NULL)
if (iterable == NULL) {
return 0;
}
return set_update_internal(self, iterable);
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL