Skip to content

docs(easy): Document that heap types need to support garbage collection #116935

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

Closed
Fidget-Spinner opened this issue Mar 17, 2024 · 3 comments · Fixed by #118021
Closed

docs(easy): Document that heap types need to support garbage collection #116935

Fidget-Spinner opened this issue Mar 17, 2024 · 3 comments · Fixed by #118021
Labels
docs Documentation in the Doc dir easy

Comments

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Mar 17, 2024

Documentation

In https://docs.python.org/3/c-api/typeobj.html#c.Py_TPFLAGS_HEAPTYPE, it does not mention that the heap type must support GC. However this is actually the case. The type itself needs to be visited by the GC because it forms a reference cycle with its own module object. We should document this.

Linked PRs

@Fidget-Spinner Fidget-Spinner added docs Documentation in the Doc dir easy labels Mar 17, 2024
@neonene
Copy link
Contributor

neonene commented Mar 18, 2024

I think this is true when a heap type is created by PyType_From*() with a module explicitly specified. As to #116934, thread_handle_type in _threadmodule.c does not hold a module, so switching from tp_alloc() back to PyObject_New() at the object creation would also fix the refleaks when GC cannot be respected.

@savannahostrowski
Copy link
Member

I'd be happy to open a PR to update the docs but wanted to make sure I understand the comment above.

@neonene Are you suggesting that heap types wouldn't have this requirement if PyObject_New() was used, making this documentation update unnecessary? If so, is that a favourable or in progress change?

@neonene
Copy link
Contributor

neonene commented Apr 16, 2024

As long as not a few heap types work in Python without tp_traverse, I think the docs can require us to follow the GC-protocol as a current rule. If the docs really need to mention technical reasons, tp_dict and tp_mro would be stronger than ht_module.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 19, 2024
…lection (pythonGH-118021)

(cherry picked from commit 5d54436)

Co-authored-by: Savannah Ostrowski <[email protected]>
encukou pushed a commit that referenced this issue Apr 19, 2024
…llection (GH-118021) (GH-118092)

gh-116935: Document that heap types need to support garbage collection (GH-118021)
(cherry picked from commit 5d54436)

Co-authored-by: Savannah Ostrowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants