-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-111506: Add _Py_OPAQUE_PYOBJECT to hide PyObject layout & related API #136505
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2639997
Allow Py_LIMITED_API for (Py_GIL_DISABLED && _Py_OPAQUE_PYOBJECT)
encukou 7ff56f4
Hide some API if _Py_OPAQUE_PYOBJECT is defined
encukou 33d9ae7
Add test for _Py_OPAQUE_PYOBJECT
encukou 781e2ab
Apply suggestions from code review
vstinner 08d963d
Merge in the main branch to solve conflict
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Workaround for testing _Py_OPAQUE_PYOBJECT. | ||
// See end of 'extension.c' | ||
|
||
|
||
#undef _Py_OPAQUE_PYOBJECT | ||
#undef Py_LIMITED_API | ||
#include "Python.h" | ||
|
||
|
||
// (repeated definition to avoid creating a header) | ||
extern PyObject *testcext_create_moduledef( | ||
const char *name, const char *doc, | ||
PyMethodDef *methods, PyModuleDef_Slot *slots); | ||
|
||
PyObject *testcext_create_moduledef( | ||
const char *name, const char *doc, | ||
PyMethodDef *methods, PyModuleDef_Slot *slots) { | ||
|
||
static struct PyModuleDef _testcext_module = { | ||
PyModuleDef_HEAD_INIT, | ||
}; | ||
if (!_testcext_module.m_name) { | ||
_testcext_module.m_name = name; | ||
_testcext_module.m_doc = doc; | ||
_testcext_module.m_methods = methods; | ||
_testcext_module.m_slots = slots; | ||
} | ||
return PyModuleDef_Init(&_testcext_module); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ def main(): | |
std = os.environ.get("CPYTHON_TEST_STD", "") | ||
module_name = os.environ["CPYTHON_TEST_EXT_NAME"] | ||
limited = bool(os.environ.get("CPYTHON_TEST_LIMITED", "")) | ||
opaque = bool(os.environ.get("CPYTHON_TEST_OPAQUE_PYOBJECT", "")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to rename opaque to opaque_pyobject. |
||
|
||
sources = [SOURCE] | ||
|
||
cflags = list(CFLAGS) | ||
cflags.append(f'-DMODULE_NAME={module_name}') | ||
|
@@ -75,6 +78,12 @@ def main(): | |
version = sys.hexversion | ||
cflags.append(f'-DPy_LIMITED_API={version:#x}') | ||
|
||
# Define _Py_OPAQUE_PYOBJECT macro | ||
if opaque: | ||
version = sys.hexversion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. version is not used, it can be removed. |
||
cflags.append(f'-D_Py_OPAQUE_PYOBJECT') | ||
sources.append('create_moduledef.c') | ||
|
||
# On Windows, add PCbuild\amd64\ to include and library directories | ||
include_dirs = [] | ||
library_dirs = [] | ||
|
@@ -99,7 +108,7 @@ def main(): | |
|
||
ext = Extension( | ||
module_name, | ||
sources=[SOURCE], | ||
sources=sources, | ||
extra_compile_args=cflags, | ||
include_dirs=include_dirs, | ||
library_dirs=library_dirs) | ||
|
Oops, something went wrong.
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.
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.
I suggest to rename "opaque" to "opaque_pyobject" (also in _check_build).