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-42972: Fully implement GC protocol for re types #26368

Merged
merged 2 commits into from May 27, 2021

Conversation

@erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented May 25, 2021

https://bugs.python.org/issue42972

@@ -1417,6 +1436,7 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
break;
}
}
PyObject_GC_Track(self);
Copy link
Contributor Author

@erlend-aasland erlend-aasland May 25, 2021

Choose a reason for hiding this comment

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

@pablogsal I'm unsure if this it the correct place to start tracking the newly created pattern object. My reasoning was that AFAICS, it seems to be fully initialised here, unless I've missed something.

Copy link
Member

@vstinner vstinner May 27, 2021

Choose a reason for hiding this comment

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

IMO it's the right place.

It must be called before the first DECREF(self), otherwise PyObject_GC_UnTrack() crash in dealloc.

Usually, it's better to only track an object once it's fully initialized, but here it's more convient to do it here to be able to simply call DECREF() on error. The bare minimum is that traverse must be crash when an object started to be tracked. I added a test in debug mode for that: see traverse(visit_validate) in PyObject_GC_Track().

Copy link
Member

@vstinner vstinner left a comment

I'm not sure that calling PyObject_ClearWeakRefs() in a clear function is safe. What do you think?

Modules/_sre.c Outdated Show resolved Hide resolved
Modules/_sre.c Outdated Show resolved Hide resolved
Modules/_sre.c Outdated Show resolved Hide resolved
@@ -1417,6 +1436,7 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
break;
}
}
PyObject_GC_Track(self);
Copy link
Member

@vstinner vstinner May 27, 2021

Choose a reason for hiding this comment

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

IMO it's the right place.

It must be called before the first DECREF(self), otherwise PyObject_GC_UnTrack() crash in dealloc.

Usually, it's better to only track an object once it's fully initialized, but here it's more convient to do it here to be able to simply call DECREF() on error. The bare minimum is that traverse must be crash when an object started to be tracked. I added a test in debug mode for that: see traverse(visit_validate) in PyObject_GC_Track().

Modules/_sre.c Outdated Show resolved Hide resolved
@erlend-aasland erlend-aasland requested a review from vstinner May 27, 2021
@vstinner vstinner merged commit fba42d1 into python:main May 27, 2021
11 checks passed
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented May 27, 2021

Thanks @erlend-aasland for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒🤖

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented May 27, 2021

GH-26411 is a backport of this pull request to the 3.10 branch.

miss-islington added a commit to miss-islington/cpython that referenced this issue May 27, 2021
(cherry picked from commit fba42d1)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
@erlend-aasland erlend-aasland deleted the bpo-42972/re branch May 27, 2021
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented May 27, 2021

Thanks @erlend-aasland for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒🤖 I'm not a witch! I'm not a witch!

miss-islington added a commit to miss-islington/cpython that referenced this issue May 27, 2021
(cherry picked from commit fba42d1)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented May 27, 2021

GH-26414 is a backport of this pull request to the 3.10 branch.

vstinner pushed a commit that referenced this issue May 28, 2021
)

(cherry picked from commit fba42d1)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants