Skip to content

Commit 2928e5d

Browse files
vstinnerAlexWaygooderlend-aasland
authored
gh-108494: Argument Clinic: Document how to generate code that uses the limited C API (#108584)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
1 parent e012cf7 commit 2928e5d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Doc/howto/clinic.rst

+22-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ process a single source file, like this:
158158
The CLI supports the following options:
159159

160160
.. program:: ./Tools/clinic/clinic.py [-h] [-f] [-o OUTPUT] [-v] \
161-
[--converters] [--make] [--srcdir SRCDIR] [FILE ...]
161+
[--converters] [--make] [--srcdir SRCDIR] [--limited] [FILE ...]
162162

163163
.. option:: -h, --help
164164

@@ -193,6 +193,11 @@ The CLI supports the following options:
193193
A file to exclude in :option:`--make` mode.
194194
This option can be given multiple times.
195195

196+
.. option:: --limited
197+
198+
Use the :ref:`Limited API <limited-c-api>` to parse arguments in the generated C code.
199+
See :ref:`clinic-howto-limited-capi`.
200+
196201
.. option:: FILE ...
197202

198203
The list of files to process.
@@ -1905,6 +1910,22 @@ blocks embedded in Python files look slightly different. They look like this:
19051910
#/*[python checksum:...]*/
19061911
19071912
1913+
.. _clinic-howto-limited-capi:
1914+
1915+
How to use the Limited C API
1916+
----------------------------
1917+
1918+
If Argument Clinic :term:`input` is located within a C source file
1919+
that contains ``#define Py_LIMITED_API``, Argument Clinic will generate C code
1920+
that uses the :ref:`Limited API <limited-c-api>` to parse arguments. The
1921+
advantage of this is that the generated code will not use private functions.
1922+
However, this *can* result in Argument Clinic generating less efficient code
1923+
in some cases. The extent of the performance penalty will depend
1924+
on the parameters (types, number, etc.).
1925+
1926+
.. versionadded:: 3.13
1927+
1928+
19081929
.. _clinic-howto-override-signature:
19091930

19101931
How to override the generated signature
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
:ref:`Argument Clinic <howto-clinic>` now has a partial support of the
2-
:ref:`Limited API <limited-c-api>`. Patch by Victor Stinner.
2+
:ref:`Limited API <limited-c-api>`: see :ref:`clinic-howto-limited-capi`.
3+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)