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

fix: call 'PyObject_ClearWeakRefs' unconditionally #324

Merged
merged 7 commits into from
Oct 21, 2024

Conversation

tseaver
Copy link
Member

@tseaver tseaver commented Sep 5, 2024

Toward #323.

@stollero Could you test with this patch to see if it fixes #323?

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

@tseaver Do we also need to call PyObject_ClearWeakRefs in the tp_dealloc functions for the other types that use BASETYPE_FLAGS?

@tseaver
Copy link
Member Author

tseaver commented Sep 6, 2024

@davisagli

Do we also need to call PyObject_ClearWeakRefs in the tp_dealloc functions for the other types that use BASETYPE_FLAGS?

7ca6275 tries to comply across the board. PTAL.

@davisagli
Copy link
Member

@tseaver The tests pass, but some errors are logged when I run tox -e py311:

Exception ignored in tp_clear of: <class 'dict'>
Traceback (most recent call last):
  File "/Users/davisagli/Plone/zope.interface/src/zope/interface/ro.py", line 289, in __init__
    def __init__(self, C, memo):

SystemError: Objects/weakrefobject.c:951: bad argument to internal function
Exception ignored in tp_clear of: <class 'dict'>
Traceback (most recent call last):
  File "/Users/davisagli/Plone/zope.interface/src/zope/interface/ro.py", line 289, in __init__
    def __init__(self, C, memo):

SystemError: Objects/weakrefobject.c:951: bad argument to internal function
...................................................Exception ignored in tp_clear of: <class 'dict'>
Traceback (most recent call last):
  File "/Users/davisagli/Plone/zope.interface/src/zope/interface/ro.py", line 247, in __init__
    def __init__(self, C, mro):

SystemError: Objects/weakrefobject.c:951: bad argument to internal function

That comes from here: https://github.com/python/cpython/blob/3.11/Objects/weakrefobject.c#L951

Apart from SB, the other types only have Py_TPFLAGS_MANAGED_WEAKREF (via BASETYPE_FLAGS) when USE_EXPLICIT_WEAKREFLIST is 0 (in Python 3.12+) so we should probably also use that condition for calling PyObject_ClearWeakRefs here.

Or else take Py_TPFLAGS_MANAGED_WEAKREF back out of BASETYPE_FLAGS and only add it for SpecificationBase

@dataflake
Copy link
Member

@tseaver knock knock - do you have a little time to finish this?

@davisagli
Copy link
Member

@tseaver @dataflake I updated this branch with my second suggestion from above, which resolves the errors I mentioned.

@dataflake
Copy link
Member

I can't say much about the C code changes because that's not my expertise, but if it fixes the issues it's OK for merging.

@tseaver
Copy link
Member Author

tseaver commented Oct 21, 2024

@davisagli 2524dc6 LGTM -- thanks for taking up my slack!

@tseaver tseaver merged commit 8f42047 into master Oct 21, 2024
53 checks passed
@tseaver tseaver deleted the tseaver-323-weak_ref_clearance branch October 21, 2024 16:51
@mauritsvanrees
Copy link
Member

Plone gives a segmentation fault when used with Zope 5.11. This PR fixes it. Can we have a release please?

I might be able to make a release myself, at least I should have PyPI rights. But I am not sure how that goes with the C code, so I might unknowingly break something.

BTW, after Zope 5.11 was released I reported that the Plone tests passed, but apparently this segfault managed to hide itself...

@dataflake
Copy link
Member

I cannot do a release, I am traveling without access to a computer.

@mauritsvanrees
Copy link
Member

I wanted to try, but apparently I don't have rights to upload to PyPI anyway, which surprises me as I am part of the zope pypi organisation.
Oh well, I can wait.

@davisagli
Copy link
Member

@mauritsvanrees @dataflake I released zope.interface 7.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal Python error: Bus error/Segmentation fault with 7.0.3
4 participants