-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Add 'limited_api' kwarg to extension_module
This commit adds a new keyword arg to extension_module() that enables a user to target the Python Limited API, declaring the version of the limited API that they wish to target. Two new unittests have been added to test this functionality.
- Loading branch information
Showing
15 changed files
with
264 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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
5 changes: 5 additions & 0 deletions
5
docs/markdown/snippets/python_extension_module_limited_api.md
This file contains 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,5 @@ | ||
## Support targeting Python's limited C API | ||
|
||
The Python module's `extension_module` function has gained the ability | ||
to build extensions which target Python's limited C API via a new keyword | ||
argument: `limited_api`. |
This file contains 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 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 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 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 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
10 changes: 10 additions & 0 deletions
10
test cases/python/10 extmodule limited api disabled/meson.build
This file contains 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,10 @@ | ||
project('Python limited api disabled', 'c', | ||
default_options : ['buildtype=release', 'werror=true', 'python.allow_limited_api=false']) | ||
|
||
py_mod = import('python') | ||
py = py_mod.find_installation() | ||
|
||
module = py.extension_module('my_module', | ||
'module.c', | ||
limited_api: '3.7', | ||
) |
17 changes: 17 additions & 0 deletions
17
test cases/python/10 extmodule limited api disabled/module.c
This file contains 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,17 @@ | ||
#include <Python.h> | ||
|
||
#if defined(Py_LIMITED_API) | ||
#error "Py_LIMITED_API's definition by Meson should have been disabled." | ||
#endif | ||
|
||
static struct PyModuleDef my_module = { | ||
PyModuleDef_HEAD_INIT, | ||
"my_module", | ||
NULL, | ||
-1, | ||
NULL | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit_my_module(void) { | ||
return PyModule_Create(&my_module); | ||
} |
This file contains 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,19 @@ | ||
#include <Python.h> | ||
|
||
#ifndef Py_LIMITED_API | ||
#error Py_LIMITED_API must be defined. | ||
#elif Py_LIMITED_API != 0x03070000 | ||
#error Wrong value for Py_LIMITED_API | ||
#endif | ||
|
||
static struct PyModuleDef limited_module = { | ||
PyModuleDef_HEAD_INIT, | ||
"limited_api_test", | ||
NULL, | ||
-1, | ||
NULL | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit_limited(void) { | ||
return PyModule_Create(&limited_module); | ||
} |
Oops, something went wrong.