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

Initialize ob_type for class type objects early #115

Merged
merged 1 commit into from
Nov 18, 2017

Conversation

markbt
Copy link
Collaborator

@markbt markbt commented Nov 16, 2017

When creating classes, the ob_type field of the class's PyTypeObject
is statically initialized to NULL, and then becomes dynamically
initialized to &PyType_Type when PyType_Ready() is called. This is
too late. If GC occurs during the initialization of the class before
PyType_Ready() is called, then the garbage collector will encounter
the NULL ob_type and segfault.

The Python docs say this field should be dynamically initialized to
&PyType_Type before doing any more class initialization.

When creating classes, the `ob_type` field of the class's `PyTypeObject`
is statically initialized to `NULL`, and then becomes dynamically
initialized to `&PyType_Type` when `PyType_Ready()` is called.  This is
too late.  If GC occurs during the initialization of the class before
`PyType_Ready()` is called, then the garbage collector will encounter
the `NULL` `ob_type` and segfault.

The Python docs say this field should be dynamically initialized to
`&PyType_Type` before doing any more class initialization.
@dgrunwald dgrunwald merged commit ccdfacd into dgrunwald:master Nov 18, 2017
@quark-zju quark-zju mentioned this pull request Jan 27, 2018
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.

2 participants