Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5205,19 +5205,16 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("Test", kwargs)) {
goto exit;
}
__clinic_args = Py_NewRef(args);
__clinic_args = args;
return_value = Test___init___impl((TestObj *)self, __clinic_args);

exit:
/* Cleanup for args */
Py_XDECREF(__clinic_args);

return return_value;
}

static int
Test___init___impl(TestObj *self, PyObject *args)
/*[clinic end generated code: output=0e5836c40dbc2397 input=a615a4485c0fc3e2]*/
/*[clinic end generated code: output=9bc0cdebce4c710f input=a615a4485c0fc3e2]*/

/*[clinic input]
@vectorcall
Expand Down
22 changes: 5 additions & 17 deletions Modules/clinic/_csv.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Modules/clinic/_elementtree.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Modules/clinic/_interpretersmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 7 additions & 23 deletions Modules/clinic/_testclinic_kwds.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Modules/clinic/_zoneinfo.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Modules/clinic/atexitmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Objects/clinic/namespaceobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Objects/clinic/structseq.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Tools/clinic/libclinic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,16 @@ class varpos_tuple_converter(VarPosCConverter):
type = 'PyObject *'
c_init_default = 'NULL'

@property
def borrowed(self) -> bool:
f = self.function
return (not f.fastcall and not f.vectorcall
# skip self, next is this converter
and list(f.parameters.values())[1].is_vararg())

def cleanup(self) -> str:
if self.borrowed:
return ''
return f"""Py_XDECREF({self.parser_name});\n"""

def parse_vararg(self, *, pos_only: int, min_pos: int, max_pos: int,
Expand Down Expand Up @@ -1400,6 +1409,8 @@ def parse_vararg(self, *, pos_only: int, min_pos: int, max_pos: int,
goto exit;
}}}}
"""
elif self.borrowed:
return f"{paramname} = args;\n"
else:
return f"{paramname} = Py_NewRef(args);\n"

Expand Down Expand Up @@ -1446,6 +1457,9 @@ class var_keyword_dict_converter(VarKeywordCConverter):
c_init_default = 'NULL'

def cleanup(self) -> str:
# Only the vectorcall builds a dict.
if not self.function.vectorcall:
return ''
return f'Py_XDECREF({self.parser_name});\n'

def parse_var_keyword(self, *, stackargs: bool) -> str:
Expand All @@ -1460,4 +1474,6 @@ def parse_var_keyword(self, *, stackargs: bool) -> str:
}}}}
}}}}
"""
if not self.function.vectorcall:
return f"{param_name} = kwargs;\n"
return f"{param_name} = Py_XNewRef(kwargs);\n"
6 changes: 6 additions & 0 deletions Tools/clinic/libclinic/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ def methoddef_flags(self) -> str | None:
flags.append('METH_COEXIST')
return '|'.join(flags)

@property
def fastcall(self) -> bool:
# __new__, __init__ and **kwargs get a tuple and a dict.
return not (self.disable_fastcall or self.kind.new_or_init or
any(p.is_var_keyword() for p in self.parameters.values()))

@property
def docstring_line_width(self) -> int:
"""Return the maximum line width for docstring lines.
Expand Down
9 changes: 1 addition & 8 deletions Tools/clinic/libclinic/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,7 @@ def __init__(self, func: Function, codegen: CodeGen) -> None:
self.codegen.add_include('pycore_critical_section.h',
'Py_BEGIN_CRITICAL_SECTION()')

# Use fastcall if not disabled, except if in a __new__ or
# __init__ method, or if there is a **kwargs parameter.
if self.func.disable_fastcall:
self.fastcall = False
elif self.var_keyword is not None:
self.fastcall = False
else:
self.fastcall = not self.is_new_or_init()
self.fastcall = self.func.fastcall

self.pos_only = 0
self.min_pos = 0
Expand Down
Loading