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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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

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
2 participants