Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39492: Fix a reference cycle between reducer_override and a Pickler instance #18266
Conversation
This comment has been minimized.
This comment has been minimized.
@pitrou if you want to take a look. |
Thank you for noticing and for the fix. |
self->framing = 0; | ||
return 0; | ||
Py_CLEAR(self->reducer_override); |
This comment has been minimized.
This comment has been minimized.
pass | ||
|
||
collect = threading.Event() | ||
_ = weakref.ref(f, lambda obj: collect.set()) |
This comment has been minimized.
This comment has been minimized.
pitrou
Feb 1, 2020
Member
This is complicated. You could simply do this:
wr = weakref.ref(f)
# ...
del p
del f
self.assertIsNone(wr())
@@ -3499,6 +3499,37 @@ class MyClass: | |||
ValueError, 'The reducer just failed'): | |||
p.dump(h) | |||
|
|||
def test_reducer_override_no_reference_cycle(self): |
This comment has been minimized.
This comment has been minimized.
pitrou
Feb 1, 2020
Member
You should mark this test CPython-only, as it relies on reference counting. Use the @support.cpython_only
decorator.
if (0) { | ||
error: | ||
status = -1; | ||
} |
This comment has been minimized.
This comment has been minimized.
pitrou
Feb 1, 2020
Member
To make this less clumsy:
static int
dump(PicklerObject *self, PyObject *obj)
{
int status = -1;
// ...
if (save(self, obj, 0) < 0 ||
_Pickler_Write(self, &stop_op, 1) < 0 ||
_Pickler_CommitFrame(self) < 0)
goto error;
// Success
status = 0;
error:
self->framing = 0;
Py_CLEAR(self->reducer_override);
return status;
}
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Feb 1, 2020
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
pierreglaser commentedJan 30, 2020
•
edited by bedevere-bot
This also needs a backport to 3.8
https://bugs.python.org/issue39492