Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39492: Fix a reference cycle between reducer_override and a Pickler instance #18266

Open
wants to merge 3 commits into
base: master
from

Conversation

@pierreglaser
Copy link
Contributor

pierreglaser commented Jan 30, 2020

This also needs a backport to 3.8

https://bugs.python.org/issue39492

@pierreglaser

This comment has been minimized.

Copy link
Contributor Author

pierreglaser commented Jan 31, 2020

@pitrou if you want to take a look.

Copy link
Member

pitrou left a comment

Thank you for noticing and for the fix.

self->framing = 0;
return 0;
Py_CLEAR(self->reducer_override);

This comment has been minimized.

Copy link
@pitrou

pitrou Feb 1, 2020

Member

You should add a comment explaining why this is necessary.

pass

collect = threading.Event()
_ = weakref.ref(f, lambda obj: collect.set())

This comment has been minimized.

Copy link
@pitrou

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.

Copy link
@pitrou

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.

Copy link
@pitrou

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;
}
@bedevere-bot

This comment has been minimized.

Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.