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

[BUG]: [CPython 3.11] GC not implemented properly for objects with managed dictionaries #4092

Closed
3 tasks done
Fidget-Spinner opened this issue Jul 26, 2022 · 5 comments
Closed
3 tasks done

Comments

@Fidget-Spinner
Copy link

Fidget-Spinner commented Jul 26, 2022

Required prerequisites

Problem description

Pybind11 originally reported a CPython bug at python/cpython#92678. It was later found that the current solution for Py_TPFLAGS_MANAGED_DICT implemented by Pybind11 does not properly support GC for their dictionaries.

Suggestion: used the newly added (3.11b5) unstable functions:

  • _PyObject_VisitManagedDict
  • _PyObject_ClearManagedDict

to properly implement tp_clear and tp_traverse for types with Py_TPFLAGS_MANAGED_DICT set.

Functions were added in https://github.com/python/cpython/pull/95256/files.

Reproducible example code

No response

@Fidget-Spinner Fidget-Spinner added the triage New bug, unverified label Jul 26, 2022
@Fidget-Spinner Fidget-Spinner changed the title [BUG]: GC not implemented properly for objects with managed dictionaries in CPython 3.11 [BUG]: [CPython 3.11] GC not implemented properly for objects with managed dictionaries in CPython 3.11 Jul 26, 2022
@Fidget-Spinner Fidget-Spinner changed the title [BUG]: [CPython 3.11] GC not implemented properly for objects with managed dictionaries in CPython 3.11 [BUG]: [CPython 3.11] GC not implemented properly for objects with managed dictionaries Jul 26, 2022
@Fidget-Spinner
Copy link
Author

CC @Skylion007 and @henryiii

@Skylion007 Skylion007 added bug help wanted and removed triage New bug, unverified labels Aug 1, 2022
@Skylion007
Copy link
Collaborator

Yikes... and this is will be a 3.11 only fix since we want to switch APIs once the stable APIs from 3.12 are added....

@Skylion007
Copy link
Collaborator

I found another potential issue I am trying to address in this PR: #4106 . That atleast moves us to a somewhat stable get_dict / set_dict API.

@Fidget-Spinner
Copy link
Author

Not needed anymore. Fixed upstream in CPython.

@vstinner
Copy link
Contributor

Follow-up: the Py_TPFLAGS_MANAGED_DICT flag is set to late in make_static_property_type() causing an assertion error (Python debug build) or crash (Python release build) on Python 3.13: see #4970. I proposed a fix.

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

No branches or pull requests

3 participants