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

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

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

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().

@erlend-aasland erlend-aasland added the needs backport to 3.10 only security fixes label May 25, 2021
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

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

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
@vstinner vstinner merged commit fba42d1 into python:main May 27, 2021
@miss-islington
Copy link
Contributor

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

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request 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 17:41
@vstinner vstinner added the needs backport to 3.10 only security fixes label May 27, 2021
@miss-islington
Copy link
Contributor

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 pushed a commit to miss-islington/cpython that referenced this pull request May 27, 2021
(cherry picked from commit fba42d1)

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

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

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 27, 2021
vstinner pushed a commit that referenced this pull request 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
Development

Successfully merging this pull request may close these issues.

5 participants