Skip to content

Commit 1796c19

Browse files
gh-108494: Argument Clinic: inline parsing code for positional-only parameters in the limited C API (GH-108622)
1 parent 5584609 commit 1796c19

File tree

13 files changed

+555
-307
lines changed

13 files changed

+555
-307
lines changed

Modules/_io/clinic/bufferedio.c.h

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/bytesio.c.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/fileio.c.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/winconsoleio.c.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_multiprocessing/multiprocessing.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ class HANDLE_converter(CConverter):
1414
type = "HANDLE"
1515
format_unit = '"F_HANDLE"'
1616
17-
def parse_arg(self, argname, displayname):
18-
return """
17+
def parse_arg(self, argname, displayname, *, limited_capi):
18+
return self.format_code("""
1919
{paramname} = PyLong_AsVoidPtr({argname});
2020
if (!{paramname} && PyErr_Occurred()) {{{{
2121
goto exit;
2222
}}}}
23-
""".format(argname=argname, paramname=self.parser_name)
23+
""",
24+
argname=argname)
2425
2526
[python start generated code]*/
26-
/*[python end generated code: output=da39a3ee5e6b4b0d input=3e537d244034affb]*/
27+
/*[python end generated code: output=da39a3ee5e6b4b0d input=3cf0318efc6a8772]*/
2728

2829
/*[clinic input]
2930
module _multiprocessing

Modules/_posixsubprocess.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ class pid_t_converter(CConverter):
8787
type = 'pid_t'
8888
format_unit = '" _Py_PARSE_PID "'
8989
90-
def parse_arg(self, argname, displayname):
91-
return """
90+
def parse_arg(self, argname, displayname, *, limited_capi):
91+
return self.format_code("""
9292
{paramname} = PyLong_AsPid({argname});
9393
if ({paramname} == -1 && PyErr_Occurred()) {{{{
9494
goto exit;
9595
}}}}
96-
""".format(argname=argname, paramname=self.parser_name)
96+
""",
97+
argname=argname)
9798
[python start generated code]*/
98-
/*[python end generated code: output=da39a3ee5e6b4b0d input=5af1c116d56cbb5a]*/
99+
/*[python end generated code: output=da39a3ee5e6b4b0d input=c94349aa1aad151d]*/
99100

100101
#include "clinic/_posixsubprocess.c.h"
101102

Modules/_struct.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,20 @@ class cache_struct_converter(CConverter):
110110
c_default = "NULL"
111111
broken_limited_capi = True
112112
113-
def parse_arg(self, argname, displayname):
114-
return """
113+
def parse_arg(self, argname, displayname, *, limited_capi):
114+
assert not limited_capi
115+
return self.format_code("""
115116
if (!{converter}(module, {argname}, &{paramname})) {{{{
116117
goto exit;
117118
}}}}
118-
""".format(argname=argname, paramname=self.name,
119-
converter=self.converter)
119+
""",
120+
argname=argname,
121+
converter=self.converter)
120122
121123
def cleanup(self):
122124
return "Py_XDECREF(%s);\n" % self.name
123125
[python start generated code]*/
124-
/*[python end generated code: output=da39a3ee5e6b4b0d input=14e83804f599ed8f]*/
126+
/*[python end generated code: output=da39a3ee5e6b4b0d input=c33b27d6b06006c6]*/
125127

126128
static int cache_struct_converter(PyObject *, PyObject *, PyStructObject **);
127129

Modules/clinic/_testclinic_limited.c.h

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/overlapped.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
class pointer_converter(CConverter):
3939
format_unit = '"F_POINTER"'
4040
41-
def parse_arg(self, argname, displayname):
42-
return """
41+
def parse_arg(self, argname, displayname, *, limited_capi):
42+
return self.format_code("""
4343
{paramname} = PyLong_AsVoidPtr({argname});
4444
if (!{paramname} && PyErr_Occurred()) {{{{
4545
goto exit;
4646
}}}}
47-
""".format(argname=argname, paramname=self.parser_name)
47+
""",
48+
argname=argname)
4849
4950
class OVERLAPPED_converter(pointer_converter):
5051
type = 'OVERLAPPED *'
@@ -55,21 +56,22 @@ class HANDLE_converter(pointer_converter):
5556
class ULONG_PTR_converter(pointer_converter):
5657
type = 'ULONG_PTR'
5758
58-
def parse_arg(self, argname, displayname):
59-
return """
59+
def parse_arg(self, argname, displayname, *, limited_capi):
60+
return self.format_code("""
6061
{paramname} = (uintptr_t)PyLong_AsVoidPtr({argname});
6162
if (!{paramname} && PyErr_Occurred()) {{{{
6263
goto exit;
6364
}}}}
64-
""".format(argname=argname, paramname=self.parser_name)
65+
""",
66+
argname=argname)
6567
6668
class DWORD_converter(unsigned_long_converter):
6769
type = 'DWORD'
6870
6971
class BOOL_converter(int_converter):
7072
type = 'BOOL'
7173
[python start generated code]*/
72-
/*[python end generated code: output=da39a3ee5e6b4b0d input=8a07ea3018f4cec8]*/
74+
/*[python end generated code: output=da39a3ee5e6b4b0d input=436f4440630a304c]*/
7375

7476
/*[clinic input]
7577
module _overlapped

Modules/resource.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ class pid_t_converter(CConverter):
2323
type = 'pid_t'
2424
format_unit = '" _Py_PARSE_PID "'
2525
26-
def parse_arg(self, argname, displayname):
27-
return """
26+
def parse_arg(self, argname, displayname, *, limited_capi):
27+
return self.format_code("""
2828
{paramname} = PyLong_AsPid({argname});
2929
if ({paramname} == -1 && PyErr_Occurred()) {{{{
3030
goto exit;
3131
}}}}
32-
""".format(argname=argname, paramname=self.parser_name)
32+
""",
33+
argname=argname)
3334
[python start generated code]*/
34-
/*[python end generated code: output=da39a3ee5e6b4b0d input=5af1c116d56cbb5a]*/
35+
/*[python end generated code: output=da39a3ee5e6b4b0d input=c94349aa1aad151d]*/
3536

3637
#include "clinic/resource.c.h"
3738

0 commit comments

Comments
 (0)