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

bpo-38113: Update the Python-ast.c generator to PEP384 #15957

Merged
merged 4 commits into from
Sep 11, 2019

Conversation

DinoV
Copy link
Contributor

@DinoV DinoV commented Sep 11, 2019

Summary: This mostly migrates Python-ast.c to PEP384 and removes all statics from the whole file. This modifies the generator itself that generates the Python-ast.c. It leaves in the usage of _PyObject_LookupAttr even though it's not fully PEP384 compatible (this could always be shimmed in by anyone who needs it).

https://bugs.python.org/issue38113

Summary: This fully migrates Python-ast.c to PEP384 and removes all statics from the whole file. This modifies the generator itself that generates the Python-ast.c
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
Parser/asdl_c.py Outdated
"(PyObject *)%s_type);")
self.emit(line % (t.name,), 1)
self.emit("isinstance = PyObject_IsInstance(obj, "
f"astmodulestate_global->{t.name}_type);", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use f-strings here. Some platforms like old Ubuntu have python3 3.5 or older. Travis CI is failing with a SyntaxError.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@ericsnowcurrently ericsnowcurrently merged commit ac46eb4 into python:master Sep 11, 2019
self.emit("if (init_identifiers() < 0) return 0;", 1)
self.emit("state->AST_type = PyType_FromSpec(&AST_type_spec);", 1)
self.emit("if (!state->AST_type) return 0;", 1)
self.emit("((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object, dict);", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still accessing the dict offset, we need to remove this by letting the type system handle it

ambv pushed a commit that referenced this pull request Sep 15, 2020
Partially revert commit ac46eb4:
"bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)".

Using a module state per module instance is causing subtle practical
problems.

For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.

Add _PyAST_Fini() to clear the state at exit.

The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions.
pablogsal pushed a commit to pablogsal/cpython that referenced this pull request Sep 15, 2020
Partially revert commit ac46eb4:
"bpo-38113: Update the Python-ast.c generator to PEP384 (pythongh-15957)".

Using a module state per module instance is causing subtle practical
problems.

For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.

Add _PyAST_Fini() to clear the state at exit.

The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions..
(cherry picked from commit e5fbe0c)

Co-authored-by: Victor Stinner <vstinner@python.org>
ambv pushed a commit that referenced this pull request Sep 15, 2020
…-22258)

Partially revert commit ac46eb4:
"bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)".

Using a module state per module instance is causing subtle practical
problems.

For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.

Add _PyAST_Fini() to clear the state at exit.

The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions..
(cherry picked from commit e5fbe0c)

Co-authored-by: Victor Stinner <vstinner@python.org>
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Partially revert commit ac46eb4:
"bpo-38113: Update the Python-ast.c generator to PEP384 (pythongh-15957)".

Using a module state per module instance is causing subtle practical
problems.

For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.

Add _PyAST_Fini() to clear the state at exit.

The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions.
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.

6 participants