Skip to content

Commit 5222084

Browse files
committed
gh-108494: AC: Document How to use the Limited C API
Remove also the --limited command line option. Now the limited C API is only used if the source code contains "#define Py_LIMITED_API".
1 parent cf7ba83 commit 5222084

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Doc/howto/clinic.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,17 @@ blocks embedded in Python files look slightly different. They look like this:
19051905
#/*[python checksum:...]*/
19061906
19071907
1908+
How to use the Limited C API
1909+
----------------------------
1910+
1911+
If a C source code contains ``#define Py_LIMITED_API``, the generated C code
1912+
will use the :ref:`Limited API <limited-c-api>` to parse arguments. Private
1913+
functions are not used in this case and the code parsing arguments can be a
1914+
less efficient depending on the parameters (types, number, etc.).
1915+
1916+
.. versionadded:: 3.13
1917+
1918+
19081919
.. _clinic-howto-override-signature:
19091920

19101921
How to override the generated signature

Lib/test/test_clinic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def expect_parsing_failure(
692692
):
693693
errmsg = re.escape(dedent(expected_error).strip())
694694
with self.assertRaisesRegex(clinic.ClinicError, errmsg):
695-
clinic.parse_file(filename, limited_capi=False)
695+
clinic.parse_file(filename)
696696

697697
def test_parse_file_no_extension(self) -> None:
698698
self.expect_parsing_failure(

Tools/clinic/clinic.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,6 @@ def __repr__(self) -> str:
26112611
def parse_file(
26122612
filename: str,
26132613
*,
2614-
limited_capi: bool,
26152614
output: str | None = None,
26162615
verify: bool = True,
26172616
) -> None:
@@ -2635,8 +2634,9 @@ def parse_file(
26352634
if not find_start_re.search(raw):
26362635
return
26372636

2638-
if LIMITED_CAPI_REGEX.search(raw):
2639-
limited_capi = True
2637+
# Use the limited C API if "#define Py_LIMITED_API" in found
2638+
# in the source code
2639+
limited_capi = bool(LIMITED_CAPI_REGEX.search(raw))
26402640

26412641
assert isinstance(language, CLanguage)
26422642
clinic = Clinic(language,
@@ -6096,8 +6096,6 @@ def create_cli() -> argparse.ArgumentParser:
60966096
cmdline.add_argument("--exclude", type=str, action="append",
60976097
help=("a file to exclude in --make mode; "
60986098
"can be given multiple times"))
6099-
cmdline.add_argument("--limited", dest="limited_capi", action='store_true',
6100-
help="use the Limited C API")
61016099
cmdline.add_argument("filename", metavar="FILE", type=str, nargs="*",
61026100
help="the list of files to process")
61036101
return cmdline
@@ -6188,8 +6186,7 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
61886186
continue
61896187
if ns.verbose:
61906188
print(path)
6191-
parse_file(path,
6192-
verify=not ns.force, limited_capi=ns.limited_capi)
6189+
parse_file(path, verify=not ns.force)
61936190
return
61946191

61956192
if not ns.filename:
@@ -6201,8 +6198,7 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
62016198
for filename in ns.filename:
62026199
if ns.verbose:
62036200
print(filename)
6204-
parse_file(filename, output=ns.output,
6205-
verify=not ns.force, limited_capi=ns.limited_capi)
6201+
parse_file(filename, output=ns.output, verify=not ns.force)
62066202

62076203

62086204
def main(argv: list[str] | None = None) -> NoReturn:

0 commit comments

Comments
 (0)