Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Defer GC tracking in :meth:`set.union`, :meth:`set.difference` and
:meth:`set.__sub__`. Patch by Donghee Na.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may complete the Changelog entry of your previous PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, the Docs/Docs CI doesn't like set.__sub__ reference:

/home/runner/work/cpython/cpython/Doc/build/NEWS:854: WARNING: py:meth reference target not found: set.__sub__ [ref.meth]

38 changes: 26 additions & 12 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,21 @@ _PySet_Freeze(PyObject *set)
return Py_NewRef(set);
}

static PyObject *
set_copy_untracked_lock_held(PySetObject *so)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(so);
PyObject *copy = make_new_set_basetype_untracked(Py_TYPE(so), NULL);
if (copy == NULL) {
return NULL;
}
if (set_merge_lock_held((PySetObject *)copy, (PyObject *)so) < 0) {
Py_DECREF(copy);
return NULL;
}
return copy;
}

/*[clinic input]
@critical_section
set.copy
Expand All @@ -1589,14 +1604,9 @@ static PyObject *
set_copy_impl(PySetObject *so)
/*[clinic end generated code: output=c9223a1e1cc6b041 input=c169a4fbb8209257]*/
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(so);
PyObject *copy = make_new_set_basetype(Py_TYPE(so), NULL);
if (copy == NULL) {
return NULL;
}
if (set_merge_lock_held((PySetObject *)copy, (PyObject *)so) < 0) {
Py_DECREF(copy);
return NULL;
PyObject *copy = set_copy_untracked_lock_held(so);
if (copy != NULL) {
_PyObject_GC_TRACK(copy);
}
return copy;
}
Expand Down Expand Up @@ -1652,7 +1662,8 @@ set_union_impl(PySetObject *so, PyObject * const *others,
PyObject *other;
Py_ssize_t i;

result = (PySetObject *)set_copy((PyObject *)so, NULL);
result = (PySetObject *)make_new_set_basetype_untracked(Py_TYPE(so),
(PyObject *)so);
if (result == NULL)
return NULL;

Expand All @@ -1665,6 +1676,7 @@ set_union_impl(PySetObject *so, PyObject * const *others,
return NULL;
}
}
_PyObject_GC_TRACK(result);
return (PyObject *)result;
}

Expand Down Expand Up @@ -2059,7 +2071,7 @@ set_copy_and_difference(PySetObject *so, PyObject *other)
{
PyObject *result;

result = set_copy_impl(so);
result = set_copy_untracked_lock_held(so);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may rename set_copy_and_difference() to set_copy_and_difference_untracked(), and rename set_difference() to set_difference_untracked().

if (result == NULL)
return NULL;
if (set_difference_update_internal((PySetObject *) result, other) == 0)
Expand Down Expand Up @@ -2118,7 +2130,6 @@ set_difference(PySetObject *so, PyObject *other)
}
Py_DECREF(key);
}
_PyObject_GC_TRACK(result);
return result;
}

Expand All @@ -2142,7 +2153,6 @@ set_difference(PySetObject *so, PyObject *other)
}
Py_DECREF(key);
}
_PyObject_GC_TRACK(result);
return result;
}

Expand Down Expand Up @@ -2185,6 +2195,7 @@ set_difference_multi_impl(PySetObject *so, PyObject * const *others,
return NULL;
}
}
_PyObject_GC_TRACK(result);
return result;
}

Expand All @@ -2199,6 +2210,9 @@ set_sub(PyObject *self, PyObject *other)
Py_BEGIN_CRITICAL_SECTION2(so, other);
rv = set_difference(so, other);
Py_END_CRITICAL_SECTION2();
if (rv != NULL) {
_PyObject_GC_TRACK(rv);
}
return rv;
}

Expand Down
Loading