From e38d94ed7a1852ddf1b9d640a7653c6e7bb26a09 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 6 Nov 2024 21:30:06 +0200 Subject: [PATCH] Polishing. --- Modules/clinic/_testclinic.c.h | 10 +++++----- Modules/gcmodule.c | 4 +--- Tools/clinic/libclinic/converter.py | 2 +- Tools/clinic/libclinic/converters.py | 6 ------ Tools/clinic/libclinic/parse_args.py | 2 +- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 641a5e303e68c0..0f5ae5ec869753 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -3160,7 +3160,7 @@ posonly_req_opt_varpos_array(PyObject *module, PyObject *const *args, Py_ssize_t } b = args[1]; skip_optional: - __clinic_args = args + Py_MIN(nargs, 2); + __clinic_args = nargs > 2 ? args + 2 : args; args_length = Py_MAX(0, nargs - 2); return_value = posonly_req_opt_varpos_array_impl(module, a, b, __clinic_args, args_length); @@ -3223,7 +3223,7 @@ posonly_poskw_varpos_array(PyObject *module, PyObject *const *args, Py_ssize_t n } a = fastargs[0]; b = fastargs[1]; - __clinic_args = args + Py_MIN(nargs, 2); + __clinic_args = nargs > 2 ? args + 2 : args; args_length = Py_MAX(0, nargs - 2); return_value = posonly_poskw_varpos_array_impl(module, a, b, __clinic_args, args_length); @@ -4214,7 +4214,7 @@ posonly_req_opt_varpos_array_no_fastcall(PyTypeObject *type, PyObject *args, PyO } b = PyTuple_GET_ITEM(args, 1); skip_optional: - __clinic_args = _PyTuple_ITEMS(args) + Py_MIN(PyTuple_GET_SIZE(args), 2); + __clinic_args = PyTuple_GET_SIZE(args) > 2 ? _PyTuple_ITEMS(args) + 2 : _PyTuple_ITEMS(args); args_length = Py_MAX(0, PyTuple_GET_SIZE(args) - 2); return_value = posonly_req_opt_varpos_array_no_fastcall_impl(type, a, b, __clinic_args, args_length); @@ -4271,11 +4271,11 @@ posonly_poskw_varpos_array_no_fastcall(PyTypeObject *type, PyObject *args, PyObj } a = fastargs[0]; b = fastargs[1]; - __clinic_args = _PyTuple_ITEMS(args) + Py_MIN(PyTuple_GET_SIZE(args), 2); + __clinic_args = PyTuple_GET_SIZE(args) > 2 ? _PyTuple_ITEMS(args) + 2 : _PyTuple_ITEMS(args); args_length = Py_MAX(0, PyTuple_GET_SIZE(args) - 2); return_value = posonly_poskw_varpos_array_no_fastcall_impl(type, a, b, __clinic_args, args_length); exit: return return_value; } -/*[clinic end generated code: output=d6902bae9f418590 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ed3408af146a746c input=a9049054013a1b77]*/ diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index c7a80a86d2a2ce..ad13496b06deaf 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -230,9 +230,7 @@ gc_get_referrers_impl(PyObject *module, PyObject *objs) } PyInterpreterState *interp = _PyInterpreterState_GET(); - PyObject *result = _PyGC_GetReferrers(interp, objs); - - return result; + return _PyGC_GetReferrers(interp, objs); } /* Append obj to list; return true if error (out of memory), false if OK. */ diff --git a/Tools/clinic/libclinic/converter.py b/Tools/clinic/libclinic/converter.py index 8ef0bf0f6490e7..2c93dda3541030 100644 --- a/Tools/clinic/libclinic/converter.py +++ b/Tools/clinic/libclinic/converter.py @@ -312,7 +312,7 @@ def render(self, parameter: Parameter, data: CRenderData) -> None: def length_name(self) -> str: """Computes the name of the associated "length" variable.""" assert self.length is not None - return self.parser_name.removeprefix(libclinic.CLINIC_PREFIX) + "_length" + return self.name + "_length" # Why is this one broken out separately? # For "positional-only" function parsing, diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index 98571cb8f4b17b..2d103c941cbf23 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -1237,9 +1237,6 @@ class varpos_tuple_converter(CConverter): format_unit = '' c_default = 'NULL' - def converter_init(self) -> None: - pass - def cleanup(self) -> str: return f"""Py_XDECREF({self.parser_name});\n""" @@ -1252,9 +1249,6 @@ class varpos_array_converter(CConverter): length = True c_ignored_default = '' - def converter_init(self) -> None: - pass - def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None: raise AssertionError('should never be called') diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py index ef53b2aca5b431..2ce4e7512148d2 100644 --- a/Tools/clinic/libclinic/parse_args.py +++ b/Tools/clinic/libclinic/parse_args.py @@ -461,7 +461,7 @@ def _parse_vararg(self) -> str: size = 'nargs' if self.fastcall else 'PyTuple_GET_SIZE(args)' if self.max_pos: if min(self.pos_only, self.min_pos) < self.max_pos: - start = f'{start} + Py_MIN({size}, {self.max_pos})' + start = f'{size} > {self.max_pos} ? {start} + {self.max_pos} : {start}' size = f'Py_MAX(0, {size} - {self.max_pos})' else: start = f'{start} + {self.max_pos}'