-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
bpo-41796: Make _ast module state per interpreter #23024
Conversation
The ast module internal state is now per interpreter. * Rename "astmodulestate" to "struct ast_state" * Add pycore_ast.h internal header: the ast_state structure is now declared in pycore_ast.h. * Add PyInterpreterState.ast (struct ast_state) * Remove get_ast_state() * Rename get_global_ast_state() to get_ast_state() * PyAST_obj2mod() now handles get_ast_state() failures
In short, this change replaces
|
Oh, I missed test_peg_generator. I should now be fixed with my second commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Windows regen file (regen.vcxproj
) be updated as well?
@isidentical: Thanks for the review. I addressed your review. Please review the updated PR. |
@lysnikolaou: "Should the Windows regen file (regen.vcxproj) be updated as well?" Oh, I didn't know this project. Thanks, I updated it. |
I merged my PR. Thanks for the useful review @lysnikolaou and @isidentical! I dislike having to declare the struct ast_state once in pycore_ast.h and once in Python-ast.c, but Python-ast.c is a strange beast which is used outside Python without Py_BUILD_CORE. So declaring the structure twice is a practical solution for that. @encukou used a different solution: use a pointer to an opaque structure in the PyInterpreterState, and allocate the structure on the heap memory when it's initialized. That would avoid to declare the structure twice. But I chose to follow the current trend of declaring all structures in pycore_interp.h and have a large unique and flat PyInterpreter structure (no pointer indirection). Maybe tomorrow we should revisit this design to have something more flexible, to not have to declare everything in pycore_interp.h. The best would be to be able to have a real module state, but I was biten multiple times by the C API which requires the AST module state, whereas the C API isn't directly related to a module. I tried a solution using an import and we got a crash with Mercurial lazy import, etc. |
|
I am relatively sure that this commit introduced reference leaks in the test suite: https://buildbot.python.org/all/#/builders/205/builds/83 OK See also https://bugs.python.org/issue42250 |
The ast module internal state is now per interpreter. * Rename "astmodulestate" to "struct ast_state" * Add pycore_ast.h internal header: the ast_state structure is now declared in pycore_ast.h. * Add PyInterpreterState.ast (struct ast_state) * Remove get_ast_state() * Rename get_global_ast_state() to get_ast_state() * PyAST_obj2mod() now handles get_ast_state() failures
The ast module internal state is now per interpreter.
declared in pycore_ast.h.
https://bugs.python.org/issue41796