From c7308076966c1c55bc117ce9f7a7f49ac96acfa6 Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Mon, 24 Apr 2023 09:52:28 +0200 Subject: 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. --- docs/markdown/Builtin-options.md | 17 +++++++++++------ docs/markdown/Python-module.md | 5 +++++ .../snippets/python_extension_module_limited_api.md | 5 +++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 docs/markdown/snippets/python_extension_module_limited_api.md (limited to 'docs/markdown') diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index fed893e10..ca4fd14c0 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -370,12 +370,13 @@ install prefix. For example: if the install prefix is `/usr` and the ### Python module -| Option | Default value | Possible values | Description | -| ------ | ------------- | ----------------- | ----------- | -| bytecompile | 0 | integer from -1 to 2 | What bytecode optimization level to use (Since 1.2.0) | -| install_env | prefix | {auto,prefix,system,venv} | Which python environment to install to (Since 0.62.0) | -| platlibdir | | Directory path | Directory for site-specific, platform-specific files (Since 0.60.0) | -| purelibdir | | Directory path | Directory for site-specific, non-platform-specific files (Since 0.60.0) | +| Option | Default value | Possible values | Description | +| ------ | ------------- | ----------------- | ----------- | +| bytecompile | 0 | integer from -1 to 2 | What bytecode optimization level to use (Since 1.2.0) | +| install_env | prefix | {auto,prefix,system,venv} | Which python environment to install to (Since 0.62.0) | +| platlibdir | | Directory path | Directory for site-specific, platform-specific files (Since 0.60.0) | +| purelibdir | | Directory path | Directory for site-specific, non-platform-specific files (Since 0.60.0) | +| allow_limited_api | true | true, false | Disables project-wide use of the Python Limited API (Since 1.3.0) | *Since 0.60.0* The `python.platlibdir` and `python.purelibdir` options are used by the python module methods `python.install_sources()` and @@ -405,3 +406,7 @@ python bytecode. Bytecode has 3 optimization levels: To this, Meson adds level `-1`, which is to not attempt to compile bytecode at all. + +*Since 1.3.0* The `python.allow_limited_api` option affects whether the +`limited_api` keyword argument of the `extension_module` method is respected. +If set to `false`, the effect of the `limited_api` argument is disabled. diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md index f67262abf..05ae57de2 100644 --- a/docs/markdown/Python-module.md +++ b/docs/markdown/Python-module.md @@ -101,6 +101,11 @@ the addition of the following: `/usr/lib/site-packages`. When subdir is passed to this method, it will be appended to that location. This keyword argument is mutually exclusive with `install_dir` +- `limited_api`: *since 1.3.0* A string containing the Python version + of the [Py_LIMITED_API](https://docs.python.org/3/c-api/stable.html) that + the extension targets. For example, '3.7' to target Python 3.7's version of + the limited API. This behavior can be disabled by setting the value of + `python.allow_limited_api`. See [Python module options](Builtin-options.md#python-module). Additionally, the following diverge from [[shared_module]]'s default behavior: diff --git a/docs/markdown/snippets/python_extension_module_limited_api.md b/docs/markdown/snippets/python_extension_module_limited_api.md new file mode 100644 index 000000000..f5da9699d --- /dev/null +++ b/docs/markdown/snippets/python_extension_module_limited_api.md @@ -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`. -- cgit v1.2.3