mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-110964: Remove private _PyArg functions (#110966)
Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
This commit is contained in:
parent
054f496bd4
commit
be5e8a0103
166 changed files with 511 additions and 229 deletions
|
|
@ -1344,6 +1344,8 @@ class CLanguage(Language):
|
|||
""",
|
||||
indent=4))
|
||||
else:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_CheckPositional()')
|
||||
parser_code = [normalize_snippet(f"""
|
||||
if (!_PyArg_CheckPositional("{{name}}", {nargs}, {min_pos}, {max_args})) {{{{
|
||||
goto exit;
|
||||
|
|
@ -1401,6 +1403,8 @@ class CLanguage(Language):
|
|||
if limited_capi:
|
||||
fastcall = False
|
||||
if fastcall:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_ParseStack()')
|
||||
parser_code = [normalize_snippet("""
|
||||
if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}",
|
||||
{parse_arguments})) {{
|
||||
|
|
@ -1429,6 +1433,11 @@ class CLanguage(Language):
|
|||
|
||||
has_optional_kw = (max(pos_only, min_pos) + min_kw_only < len(converters) - int(vararg != NO_VARARG))
|
||||
if vararg == NO_VARARG:
|
||||
# FIXME: refactor the code to not declare args_declaration
|
||||
# if limited_capi is true
|
||||
if not limited_capi:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_UnpackKeywords()')
|
||||
args_declaration = "_PyArg_UnpackKeywords", "%s, %s, %s" % (
|
||||
min_pos,
|
||||
max_pos,
|
||||
|
|
@ -1436,6 +1445,9 @@ class CLanguage(Language):
|
|||
)
|
||||
nargs = "nargs"
|
||||
else:
|
||||
if not limited_capi:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_UnpackKeywordsWithVararg()')
|
||||
args_declaration = "_PyArg_UnpackKeywordsWithVararg", "%s, %s, %s, %s" % (
|
||||
min_pos,
|
||||
max_pos,
|
||||
|
|
@ -1574,6 +1586,8 @@ class CLanguage(Language):
|
|||
declarations += "\nPy_ssize_t nargs = PyTuple_Size(args);"
|
||||
|
||||
elif fastcall:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_ParseStackAndKeywords()')
|
||||
parser_code = [normalize_snippet("""
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser{parse_arguments_comma}
|
||||
{parse_arguments})) {{
|
||||
|
|
@ -1581,6 +1595,8 @@ class CLanguage(Language):
|
|||
}}
|
||||
""", indent=4)]
|
||||
else:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_ParseTupleAndKeywordsFast()')
|
||||
parser_code = [normalize_snippet("""
|
||||
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
|
||||
{parse_arguments})) {{
|
||||
|
|
@ -1626,12 +1642,16 @@ class CLanguage(Language):
|
|||
|
||||
if not parses_keywords:
|
||||
declarations = '{base_type_ptr}'
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_NoKeywords()')
|
||||
fields.insert(0, normalize_snippet("""
|
||||
if ({self_type_check}!_PyArg_NoKeywords("{name}", kwargs)) {{
|
||||
goto exit;
|
||||
}}
|
||||
""", indent=4))
|
||||
if not parses_positional:
|
||||
clinic.add_include('pycore_modsupport.h',
|
||||
'_PyArg_NoPositional()')
|
||||
fields.insert(0, normalize_snippet("""
|
||||
if ({self_type_check}!_PyArg_NoPositional("{name}", args)) {{
|
||||
goto exit;
|
||||
|
|
@ -3500,6 +3520,8 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||
else:
|
||||
if expected_literal:
|
||||
expected = f'"{expected}"'
|
||||
if clinic is not None:
|
||||
clinic.add_include('pycore_modsupport.h', '_PyArg_BadArgument()')
|
||||
return f'_PyArg_BadArgument("{{{{name}}}}", "{displayname}", {expected}, {{argname}});'
|
||||
|
||||
def format_code(self, fmt: str, *,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue