GeezerVison is showing github.com — bpo-45459: Add pytypedefs.h header file by vstinner · Pull Request #31527 · python/cpython
Conversation
vstinner
commented
Feb 23, 2022
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Move forward declarations of Python C API types to a new pytypedefs.h
header file to solve interdependency issues between header files.
pytypedefs.h contains forward declarations of the following types:
- PyCodeObject
- PyFrameObject
- PyGetSetDef
- PyInterpreterState
- PyLongObject
- PyMemberDef
- PyMethodDef
- PyModuleDef
- PyObject
- PyThreadState
- PyTypeObject
https://bugs.python.org/issue45459
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Move forward declarations of Python C API types to a new pytypedefs.h
header file to solve interdependency issues between header files.
pytypedefs.h contains forward declarations of the following types:
* PyCodeObject
* PyFrameObject
* PyGetSetDef
* PyInterpreterState
* PyLongObject
* PyMemberDef
* PyMethodDef
* PyModuleDef
* PyObject
* PyThreadState
* PyTypeObject
|
Last years, more and more interdependencies have been added. Examples:
- pybuffer.h uses
PyObject before it's defined by object.h (included later).
- object.h must forward declare
PyModuleDef since it's used before it's defined by moduleobject.h (included after object.h).
- object.h uses
struct PyMethodDef which is defined later by methodobject.h (included after object.h). object.h has to use struct PyMethodDef instead of PyMethodDef to solve the interdpendency issue.
This PR cleans up header files by moving forward declarations at the top of Python.h.
With this PR, it becomes possible to use type names like PyObject or PyModuleDef rather than using structure names like struct _object or struct PyModuleDef. I didn't make this change in this PR to keep it easier to review. I created GH-31528 draft PR (see the second commit of this PR) to use type names.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Feb 23, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
If you don't want to go this way, I wrote the bare minimum fix for the clang compiler warning: GH-31539.
But as I wrote in my previous comment, IMO it's now time to cleanup these forward declarations to have a sane way to fix this issuse in a single place. There are too many scattered forward declarations in the Python C API.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
If you don't want to go this way, I wrote the bare minimum fix for the clang compiler warning: #31539.
Defining types in multiple header files is tricky. At my first attempt, I defined PyObject inside #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030b0000 and it didn't work when building xxlimited35 which targets the limited C API version 3.5...
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This looks nice and clean. AFAICS, there is no downside; approved post-merge :)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
asvetlov
pushed a commit
that referenced
this pull request
Feb 26, 2022
Move forward declarations of Python C API types to a new pytypedefs.h
header file to solve interdependency issues between header files.
pytypedefs.h contains forward declarations of the following types:
* PyCodeObject
* PyFrameObject
* PyGetSetDef
* PyInterpreterState
* PyLongObject
* PyMemberDef
* PyMethodDef
* PyModuleDef
* PyObject
* PyThreadState
* PyTypeObject
itamaro
added a commit
to itamaro/cpython
that referenced
this pull request
May 24, 2022
pythonGH-31527 moved this typedef to `Include/pytypedefs.h`, so this comment should point at the correct location
vstinner
pushed a commit
that referenced
this pull request
Jul 9, 2022
GH-31527 moved this typedef to `Include/pytypedefs.h`, so this comment
should point at the correct location
Reviewers
corona10
corona10 approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|