From 31a75527db5b4f030d418c331116ace640dc1e40 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 26 Nov 2026 23:53:54 +0100 Subject: [PATCH 1/4] Avoid a reference count round trip when converting int arguments to Py_ssize_t Add _PyNumber_IndexAsSsize_t() and use it in Argument Clinic and in the 'n' format unit of PyArg_Parse. Also add a fast path for int to PyNumber_AsSsize_t(). Co-Authored-By: Claude Fable 5.2 --- Include/internal/pycore_abstract.h | 2 + Lib/test/clinic.test.c | 68 ++---- Modules/_ctypes/clinic/_ctypes.c.h | 52 ++-- Modules/_ctypes/clinic/callproc.c.h | 32 +-- Modules/_ctypes/clinic/cfield.c.h | 46 +--- Modules/_decimal/clinic/_decimal.c.h | 60 ++--- Modules/_io/clinic/bufferedio.c.h | 88 ++----- Modules/_io/clinic/bytesio.c.h | 30 +-- Modules/_io/clinic/iobase.c.h | 16 +- Modules/_io/clinic/stringio.c.h | 16 +- Modules/_io/clinic/textio.c.h | 30 +-- Modules/_sre/clinic/sre.c.h | 228 ++++-------------- .../_testinternalcapi/clinic/test_lock.c.h | 46 +--- Modules/_zstd/clinic/_zstdmodule.c.h | 32 +-- Modules/_zstd/clinic/decompressor.c.h | 18 +- Modules/clinic/_bisectmodule.c.h | 100 +++----- Modules/clinic/_bz2module.c.h | 18 +- Modules/clinic/_collectionsmodule.c.h | 46 +--- Modules/clinic/_elementtree.c.h | 18 +- Modules/clinic/_hashopenssl.c.h | 52 ++-- Modules/clinic/_interpqueuesmodule.c.h | 18 +- Modules/clinic/_json.c.h | 18 +- Modules/clinic/_lzmamodule.c.h | 18 +- Modules/clinic/_operator.c.h | 18 +- Modules/clinic/_ssl.c.h | 18 +- Modules/clinic/_struct.c.h | 60 ++--- Modules/clinic/_testclinic.c.h | 80 ++---- Modules/clinic/_testclinic_depr.c.h | 4 +- Modules/clinic/_testclinic_kwds.c.h | 4 +- Modules/clinic/_threadmodule.c.h | 18 +- Modules/clinic/arraymodule.c.h | 56 ++--- Modules/clinic/binascii.c.h | 32 +-- Modules/clinic/faulthandler.c.h | 60 ++--- Modules/clinic/itertoolsmodule.c.h | 138 ++++------- Modules/clinic/mmapmodule.c.h | 144 +++-------- Modules/clinic/posixmodule.c.h | 180 +++++--------- Modules/clinic/sha3module.c.h | 52 ++-- Modules/clinic/socketmodule.c.h | 130 +++------- Modules/clinic/unicodedata.c.h | 32 +-- Modules/clinic/zlibmodule.c.h | 80 ++---- Objects/abstract.c | 83 ++++--- Objects/clinic/bytearrayobject.c.h | 102 ++------ Objects/clinic/bytesobject.c.h | 60 ++--- Objects/clinic/listobject.c.h | 32 +-- Objects/clinic/longobject.c.h | 28 +-- Objects/clinic/memoryobject.c.h | 18 +- Objects/clinic/unicodeobject.c.h | 102 ++------ Objects/stringlib/clinic/transmogrify.h.h | 60 ++--- Python/clinic/_warnings.c.h | 18 +- Python/getargs.c | 8 +- Tools/clinic/libclinic/converters.py | 20 +- 51 files changed, 744 insertions(+), 1945 deletions(-) diff --git a/Include/internal/pycore_abstract.h b/Include/internal/pycore_abstract.h index 67c6fa7c0c4ed5b..cb387b4bead26cb 100644 --- a/Include/internal/pycore_abstract.h +++ b/Include/internal/pycore_abstract.h @@ -60,6 +60,8 @@ PyAPI_FUNC(int) _Py_convert_optional_to_non_negative_ssize_t(PyObject *, void *) // Export for 'math' shared extension. PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject *o); +PyAPI_FUNC(Py_ssize_t) _PyNumber_IndexAsSsize_t(PyObject *o); + typedef struct { PyObject *object; PySendResult kind; diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 3b59db65f23b6f6..dc98e57b956a0b8 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -1652,32 +1652,16 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - a = ival; + a = _PyNumber_IndexAsSsize_t(args[0]); + if (a == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - b = ival; + b = _PyNumber_IndexAsSsize_t(args[1]); + if (b == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -1688,22 +1672,14 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 4) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - d = ival; - if (d < 0) { - PyErr_SetString(PyExc_ValueError, - "d cannot be negative"); - goto exit; - } + d = _PyNumber_IndexAsSsize_t(args[3]); + if (d == -1 && PyErr_Occurred()) { + goto exit; + } + if (d < 0) { + PyErr_SetString(PyExc_ValueError, + "d cannot be negative"); + goto exit; } if (nargs < 5) { goto skip_optional; @@ -1714,17 +1690,9 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 6) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[5]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - f = ival; + f = _PyNumber_IndexAsSsize_t(args[5]); + if (f == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 7) { goto skip_optional; @@ -1743,7 +1711,7 @@ static PyObject * test_Py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b, Py_ssize_t c, Py_ssize_t d, Py_ssize_t e, Py_ssize_t f, Py_ssize_t g) -/*[clinic end generated code: output=4ae0a56a1447fba9 input=a25bac8ecf2890aa]*/ +/*[clinic end generated code: output=e4286b4ef87a92ab input=a25bac8ecf2890aa]*/ /*[clinic input] diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index 7a3c4bba9fc2090..673b725ce16b9ae 100644 --- a/Modules/_ctypes/clinic/_ctypes.c.h +++ b/Modules/_ctypes/clinic/_ctypes.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -121,22 +121,14 @@ CDataType_from_buffer(PyObject *type, PyTypeObject *cls, PyObject *const *args, if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - goto exit; - } + offset = _PyNumber_IndexAsSsize_t(args[1]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; + } + if (offset < 0) { + PyErr_SetString(PyExc_ValueError, + "offset cannot be negative"); + goto exit; } skip_optional: return_value = CDataType_from_buffer_impl(type, cls, obj, offset); @@ -179,22 +171,14 @@ CDataType_from_buffer_copy(PyObject *type, PyTypeObject *cls, PyObject *const *a if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - goto exit; - } + offset = _PyNumber_IndexAsSsize_t(args[1]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; + } + if (offset < 0) { + PyErr_SetString(PyExc_ValueError, + "offset cannot be negative"); + goto exit; } skip_optional: return_value = CDataType_from_buffer_copy_impl(type, cls, &buffer, offset); @@ -938,4 +922,4 @@ Pointer_bool(PyObject *self) #define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL}, -/*[clinic end generated code: output=5d9dd4bbae13cfca input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fbed245eac716dfb input=a9049054013a1b77]*/ diff --git a/Modules/_ctypes/clinic/callproc.c.h b/Modules/_ctypes/clinic/callproc.c.h index 82cb08ff00dfb03..d4ee05ac0a69c20 100644 --- a/Modules/_ctypes/clinic/callproc.c.h +++ b/Modules/_ctypes/clinic/callproc.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -562,17 +562,9 @@ _ctypes_byref(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[1]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(obj); @@ -684,17 +676,9 @@ _ctypes_resize(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } obj = (CDataObject *)args[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[1]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(obj); return_value = _ctypes_resize_impl(module, obj, size); @@ -793,4 +777,4 @@ PyDoc_STRVAR(_ctypes_buffer_info__doc__, #ifndef _CTYPES_DLLIST_METHODDEF #define _CTYPES_DLLIST_METHODDEF #endif /* !defined(_CTYPES_DLLIST_METHODDEF) */ -/*[clinic end generated code: output=615c411ddc01d0a4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=37057eac2b3577f2 input=a9049054013a1b77]*/ diff --git a/Modules/_ctypes/clinic/cfield.c.h b/Modules/_ctypes/clinic/cfield.c.h index 355e69803b1de2c..f9cdb6e45f700f2 100644 --- a/Modules/_ctypes/clinic/cfield.c.h +++ b/Modules/_ctypes/clinic/cfield.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -70,41 +70,17 @@ PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } name = fastargs[0]; proto = fastargs[1]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - byte_size = ival; + byte_size = _PyNumber_IndexAsSsize_t(fastargs[2]); + if (byte_size == -1 && PyErr_Occurred()) { + goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - byte_offset = ival; + byte_offset = _PyNumber_IndexAsSsize_t(fastargs[3]); + if (byte_offset == -1 && PyErr_Occurred()) { + goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[4]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(fastargs[4]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } _internal_use = PyObject_IsTrue(fastargs[5]); if (_internal_use < 0) { @@ -126,4 +102,4 @@ PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=7eb1621e22ea2e05 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4122d1912de8ec17 input=a9049054013a1b77]*/ diff --git a/Modules/_decimal/clinic/_decimal.c.h b/Modules/_decimal/clinic/_decimal.c.h index 8aa362b5258d7df..ce456cd184669f5 100644 --- a/Modules/_decimal/clinic/_decimal.c.h +++ b/Modules/_decimal/clinic/_decimal.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_decimal_Context_Etiny__doc__, @@ -70,17 +70,9 @@ _decimal_Context__unsafe_setprec(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - x = ival; + x = _PyNumber_IndexAsSsize_t(arg); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setprec_impl(self, x); @@ -109,17 +101,9 @@ _decimal_Context__unsafe_setemin(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - x = ival; + x = _PyNumber_IndexAsSsize_t(arg); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setemin_impl(self, x); @@ -148,17 +132,9 @@ _decimal_Context__unsafe_setemax(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - x = ival; + x = _PyNumber_IndexAsSsize_t(arg); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setemax_impl(self, x); @@ -349,17 +325,9 @@ _decimal_IEEEContext(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t bits; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bits = ival; + bits = _PyNumber_IndexAsSsize_t(arg); + if (bits == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_IEEEContext_impl(module, bits); @@ -6330,4 +6298,4 @@ _decimal_Context_same_quantum(PyObject *context, PyTypeObject *cls, PyObject *co #ifndef _DECIMAL_CONTEXT_APPLY_METHODDEF #define _DECIMAL_CONTEXT_APPLY_METHODDEF #endif /* !defined(_DECIMAL_CONTEXT_APPLY_METHODDEF) */ -/*[clinic end generated code: output=f9ddc00f5a7335c4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0cfed229bcfa29e7 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 0cedf4a9948e9da..17f2dbb86ad47e2 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_BadArgument() @@ -556,17 +556,9 @@ _io__Buffered_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[0]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -635,17 +627,9 @@ _io__Buffered_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; + n = _PyNumber_IndexAsSsize_t(args[0]); + if (n == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -913,17 +897,9 @@ _io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - buffer_size = ival; + buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (buffer_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size); @@ -993,17 +969,9 @@ _io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - buffer_size = ival; + buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (buffer_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size); @@ -1085,17 +1053,9 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (PyTuple_GET_SIZE(args) < 3) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2)); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - buffer_size = ival; + buffer_size = _PyNumber_IndexAsSsize_t(PyTuple_GET_ITEM(args, 2)); + if (buffer_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size); @@ -1451,17 +1411,9 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - buffer_size = ival; + buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (buffer_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size); @@ -1477,4 +1429,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) #define _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF {"closed", (getter)_io_BufferedRWPair_closed_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=1596bb353f00a1ea input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6654f42d328e1669 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index e48d71397367daf..f6053de1e3aabdf 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -337,17 +337,9 @@ _io_BytesIO_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[0]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -554,17 +546,9 @@ _io_BytesIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[0]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -856,4 +840,4 @@ _io_BytesIO___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) } #define _IO_BYTESIO_CLOSED_GETSETDEF {"closed", (getter)_io_BytesIO_closed_get, (setter)NULL, _io_BytesIO_closed__doc__}, -/*[clinic end generated code: output=b9d367ad8e0b44d2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=59fa44461bf22b2d input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index c7adafe1580ea9a..82b2625b94c7c88 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -519,17 +519,9 @@ _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; + n = _PyNumber_IndexAsSsize_t(args[0]); + if (n == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = _io__RawIOBase_read_impl(self, n); @@ -573,4 +565,4 @@ PyDoc_STRVAR(_io__RawIOBase_write__doc__, {"write", (PyCFunction)_io__RawIOBase_write, METH_O, _io__RawIOBase_write__doc__}, #define _IO__IOBASE_CLOSED_GETSETDEF {"closed", (getter)_io__IOBase_closed_get, (setter)NULL, _io__IOBase_closed__doc__}, -/*[clinic end generated code: output=fd729b0ef2ad52b8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c6e8fb15c12488c6 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index bda87205e6bb718..37e7f697cdb0029 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -217,17 +217,9 @@ _io_StringIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[0]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -554,4 +546,4 @@ _io_StringIO_newlines_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=38a0385529d9cbef input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fa7fedc7af389cc8 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 954fee5cd2d4bfb..6d20515fdb4bfe8 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -867,17 +867,9 @@ _io_TextIOWrapper_readline(PyObject *self, PyObject *const *args, Py_ssize_t nar if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[0]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -1276,17 +1268,9 @@ _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *arg, void *Py_UNUSED Py_TYPE(self)->tp_name); return -1; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - value = ival; + value = _PyNumber_IndexAsSsize_t(arg); + if (value == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl((textio *)self, value); @@ -1330,4 +1314,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=d96cd0f7c06f36f5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=490dea749ae81315 input=a9049054013a1b77]*/ diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index 9e6c91d09f59a41..91e5aafcb32fd2e 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_sre_getcodesize__doc__, @@ -225,33 +225,17 @@ _sre_SRE_Pattern_prefixmatch(PyObject *self, PyTypeObject *cls, PyObject *const goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_prefixmatch_impl((PatternObject *)self, cls, string, pos, endpos); @@ -321,33 +305,17 @@ _sre_SRE_Pattern_fullmatch(PyObject *self, PyTypeObject *cls, PyObject *const *a goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_fullmatch_impl((PatternObject *)self, cls, string, pos, endpos); @@ -419,33 +387,17 @@ _sre_SRE_Pattern_search(PyObject *self, PyTypeObject *cls, PyObject *const *args goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_search_impl((PatternObject *)self, cls, string, pos, endpos); @@ -514,33 +466,17 @@ _sre_SRE_Pattern_findall(PyObject *self, PyObject *const *args, Py_ssize_t nargs goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_findall_impl((PatternObject *)self, string, pos, endpos); @@ -612,33 +548,17 @@ _sre_SRE_Pattern_finditer(PyObject *self, PyTypeObject *cls, PyObject *const *ar goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_finditer_impl((PatternObject *)self, cls, string, pos, endpos); @@ -707,33 +627,17 @@ _sre_SRE_Pattern_scanner(PyObject *self, PyTypeObject *cls, PyObject *const *arg goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - pos = ival; + pos = _PyNumber_IndexAsSsize_t(args[1]); + if (pos == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - endpos = ival; + endpos = _PyNumber_IndexAsSsize_t(args[2]); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_scanner_impl((PatternObject *)self, cls, string, pos, endpos); @@ -800,17 +704,9 @@ _sre_SRE_Pattern_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_split_impl((PatternObject *)self, string, maxsplit); @@ -879,17 +775,9 @@ _sre_SRE_Pattern_sub(PyObject *self, PyTypeObject *cls, PyObject *const *args, P if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_sub_impl((PatternObject *)self, cls, repl, string, count); @@ -959,17 +847,9 @@ _sre_SRE_Pattern_subn(PyObject *self, PyTypeObject *cls, PyObject *const *args, if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_subn_impl((PatternObject *)self, cls, repl, string, count); @@ -1122,17 +1002,9 @@ _sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } code = args[2]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - groups = ival; + groups = _PyNumber_IndexAsSsize_t(args[3]); + if (groups == -1 && PyErr_Occurred()) { + goto exit; } if (!PyDict_Check(args[4])) { _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]); @@ -1597,4 +1469,4 @@ _sre_SRE_Scanner_search(PyObject *self, PyTypeObject *cls, PyObject *const *args #ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */ -/*[clinic end generated code: output=2e6c222a2eb0875e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f02efdf20391b9fe input=a9049054013a1b77]*/ diff --git a/Modules/_testinternalcapi/clinic/test_lock.c.h b/Modules/_testinternalcapi/clinic/test_lock.c.h index 6e989a777ac7f01..96594f1a7f15532 100644 --- a/Modules/_testinternalcapi/clinic/test_lock.c.h +++ b/Modules/_testinternalcapi/clinic/test_lock.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_testinternalcapi_benchmark_locks__doc__, @@ -40,17 +40,9 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss if (!_PyArg_CheckPositional("benchmark_locks", nargs, 1, 8)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - num_threads = ival; + num_threads = _PyNumber_IndexAsSsize_t(args[0]); + if (num_threads == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -83,32 +75,16 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss if (nargs < 6) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[5]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - total_iters = ival; + total_iters = _PyNumber_IndexAsSsize_t(args[5]); + if (total_iters == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 7) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[6]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - num_locks = ival; + num_locks = _PyNumber_IndexAsSsize_t(args[6]); + if (num_locks == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 8) { goto skip_optional; @@ -123,4 +99,4 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss exit: return return_value; } -/*[clinic end generated code: output=6cfed9fc081313ef input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ccc23e43bcf33f61 input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/_zstdmodule.c.h b/Modules/_zstd/clinic/_zstdmodule.c.h index feb0563b3228381..fcaaa5f7f58e998 100644 --- a/Modules/_zstd/clinic/_zstdmodule.c.h +++ b/Modules/_zstd/clinic/_zstdmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_zstd_train_dict__doc__, @@ -50,17 +50,9 @@ _zstd_train_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } samples_sizes = args[1]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - dict_size = ival; + dict_size = _PyNumber_IndexAsSsize_t(args[2]); + if (dict_size == -1 && PyErr_Occurred()) { + goto exit; } return_value = _zstd_train_dict_impl(module, samples_bytes, samples_sizes, dict_size); @@ -123,17 +115,9 @@ _zstd_finalize_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } samples_sizes = args[2]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - dict_size = ival; + dict_size = _PyNumber_IndexAsSsize_t(args[3]); + if (dict_size == -1 && PyErr_Occurred()) { + goto exit; } compression_level = PyLong_AsInt(args[4]); if (compression_level == -1 && PyErr_Occurred()) { @@ -426,4 +410,4 @@ _zstd_set_parameter_types(PyObject *module, PyObject *const *args, Py_ssize_t na exit: return return_value; } -/*[clinic end generated code: output=a6ad0ab41c507911 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f0e55d5d1823b104 input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/decompressor.c.h b/Modules/_zstd/clinic/decompressor.c.h index 83431363621ad64..b2f7f2e64e3b9fd 100644 --- a/Modules/_zstd/clinic/decompressor.c.h +++ b/Modules/_zstd/clinic/decompressor.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_zstd_ZstdDecompressor_new__doc__, @@ -185,17 +185,9 @@ _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_length = ival; + max_length = _PyNumber_IndexAsSsize_t(args[1]); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _zstd_ZstdDecompressor_decompress_impl((ZstdDecompressor *)self, &data, max_length); @@ -210,4 +202,4 @@ _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz } #define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, (setter)NULL, _zstd_ZstdDecompressor_unused_data__doc__}, -/*[clinic end generated code: output=91b84afb07b1188c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=709551c9dbe8b1b4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h index 454131faf4112b7..2753d01bce59445 100644 --- a/Modules/clinic/_bisectmodule.c.h +++ b/Modules/clinic/_bisectmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_bisect_bisect_right__doc__, @@ -82,22 +82,14 @@ _bisect_bisect_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, goto skip_optional_pos; } if (args[2]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - lo = ival; - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + lo = _PyNumber_IndexAsSsize_t(args[2]); + if (lo == -1 && PyErr_Occurred()) { + goto exit; + } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -197,22 +189,14 @@ _bisect_insort_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, goto skip_optional_pos; } if (args[2]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - lo = ival; - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + lo = _PyNumber_IndexAsSsize_t(args[2]); + if (lo == -1 && PyErr_Occurred()) { + goto exit; + } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -311,22 +295,14 @@ _bisect_bisect_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[2]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - lo = ival; - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + lo = _PyNumber_IndexAsSsize_t(args[2]); + if (lo == -1 && PyErr_Occurred()) { + goto exit; + } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -426,22 +402,14 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[2]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - lo = ival; - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + lo = _PyNumber_IndexAsSsize_t(args[2]); + if (lo == -1 && PyErr_Occurred()) { + goto exit; + } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -466,4 +434,4 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P exit: return return_value; } -/*[clinic end generated code: output=62345f14c5c01639 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f536007e380782a2 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index 30f2c7965e73ae1..0b7c9d1d8c4b483 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__, @@ -184,17 +184,9 @@ _bz2_BZ2Decompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_ if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_length = ival; + max_length = _PyNumber_IndexAsSsize_t(args[1]); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _bz2_BZ2Decompressor_decompress_impl((BZ2Decompressor *)self, &data, max_length); @@ -238,4 +230,4 @@ _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=1dce5396d592bad7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f99baa40d2003347 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 2966d68aa3813b5..56bbcd080327a7c 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -280,17 +280,9 @@ deque_rotate(PyObject *deque, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; + n = _PyNumber_IndexAsSsize_t(args[0]); + if (n == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(deque); @@ -434,17 +426,9 @@ deque_insert(PyObject *deque, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } value = args[1]; Py_BEGIN_CRITICAL_SECTION(deque); @@ -689,17 +673,9 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 0)); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(PyTuple_GET_ITEM(args, 0)); + if (index == -1 && PyErr_Occurred()) { + goto exit; } doc = PyTuple_GET_ITEM(args, 1); return_value = tuplegetter_new_impl(type, index, doc); @@ -707,4 +683,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=de400069cf6f11a4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=892d242738402543 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index afc9daa5288f2c5..c0f9a1201d2988a 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -775,17 +775,9 @@ _elementtree_Element_insert(PyObject *self, PyObject *const *args, Py_ssize_t na if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } if (!PyObject_TypeCheck(args[1], clinic_state()->Element_Type)) { _PyArg_BadArgument("insert", "argument 2", (clinic_state()->Element_Type)->tp_name, args[1]); @@ -1474,4 +1466,4 @@ _elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=d454d27e90eb399e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3d797b881a93154b input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index b99545b0eb33471..283cefa8ce9a0da 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UnsignedLong_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -140,22 +140,14 @@ _hashlib_HASHXOF_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; } return_value = _hashlib_HASHXOF_digest_impl((HASHobject *)self, length); @@ -218,22 +210,14 @@ _hashlib_HASHXOF_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nar if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; } return_value = _hashlib_HASHXOF_hexdigest_impl((HASHobject *)self, length); @@ -1977,4 +1961,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg #ifndef _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #define _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #endif /* !defined(_HASHLIB_OPENSSL_SHAKE_256_METHODDEF) */ -/*[clinic end generated code: output=608e8ac9483c9173 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=39fc661240264f2c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_interpqueuesmodule.c.h b/Modules/clinic/_interpqueuesmodule.c.h index 6f27ea73b8866fe..87821a6f92eaed4 100644 --- a/Modules/clinic/_interpqueuesmodule.c.h +++ b/Modules/clinic/_interpqueuesmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_interpqueues_create__doc__, @@ -68,17 +68,9 @@ _interpqueues_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsize = ival; + maxsize = _PyNumber_IndexAsSsize_t(args[0]); + if (maxsize == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -763,4 +755,4 @@ _interpqueues__register_heap_types(PyObject *module, PyObject *const *args, Py_s exit: return return_value; } -/*[clinic end generated code: output=7e56e5b0c684d294 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1857258e4bfdaa8a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_json.c.h b/Modules/clinic/_json.c.h index 79315078d44582d..98dd051df9a9f56 100644 --- a/Modules/clinic/_json.c.h +++ b/Modules/clinic/_json.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(py_scanstring__doc__, @@ -46,17 +46,9 @@ py_scanstring(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } pystr = args[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - end = ival; + end = _PyNumber_IndexAsSsize_t(args[1]); + if (end == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -282,4 +274,4 @@ encoder_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=19476c429c7246c1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3af1c5b3115d7887 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index bba107e8f806daf..fcdd4262f8c126b 100644 --- a/Modules/clinic/_lzmamodule.c.h +++ b/Modules/clinic/_lzmamodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__, @@ -142,17 +142,9 @@ _lzma_LZMADecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_length = ival; + max_length = _PyNumber_IndexAsSsize_t(args[1]); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _lzma_LZMADecompressor_decompress_impl((Decompressor *)self, &data, max_length); @@ -334,4 +326,4 @@ _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssiz return return_value; } -/*[clinic end generated code: output=ffc6d673d858048c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f0cfa06ed4dc2718 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index 48a8ea8c3379ab7..2222916e2db7417 100644 --- a/Modules/clinic/_operator.c.h +++ b/Modules/clinic/_operator.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_operator_truth__doc__, @@ -1445,17 +1445,9 @@ _operator_length_hint(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - default_value = ival; + default_value = _PyNumber_IndexAsSsize_t(args[1]); + if (default_value == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: _return_value = _operator_length_hint_impl(module, obj, default_value); @@ -1507,4 +1499,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na exit: return return_value; } -/*[clinic end generated code: output=972e2543c4fcf1ba input=a9049054013a1b77]*/ +/*[clinic end generated code: output=29f6c3456e0ce9ea input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 98a929b33def825..18d03bf33c5c501 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_Size_t_Converter() @@ -746,17 +746,9 @@ _ssl__SSLSocket_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyErr_SetString(PyExc_TypeError, "_ssl._SSLSocket.read requires 1 to 2 arguments"); goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - len = ival; + len = _PyNumber_IndexAsSsize_t(args[0]); + if (len == -1 && PyErr_Occurred()) { + goto exit; } if (nargs >= 2) { if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { @@ -3373,4 +3365,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, (setter)NULL, _ssl_SSLSession_has_ticket__doc__}, -/*[clinic end generated code: output=fb3476aa2f825376 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4a16d0beb8beb146 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index 22fec68a4e9ee63..a790f094cde8658 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(Struct__doc__, @@ -230,17 +230,9 @@ Struct_unpack_from(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[1]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = Struct_unpack_from_impl((PyStructObject *)self, &buffer, offset); @@ -347,17 +339,9 @@ Struct_pack_into(PyObject *self, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("pack_into", "argument 1", "read-write bytes-like object", args[0]); goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[1]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } values = args + 2; values_length = nargs - 2; @@ -522,17 +506,9 @@ pack_into(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("pack_into", "argument 2", "read-write bytes-like object", args[1]); goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[2]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } values = args + 3; values_length = nargs - 3; @@ -661,17 +637,9 @@ unpack_from(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[2]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unpack_from_impl(module, s_object, &buffer, offset); @@ -726,4 +694,4 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -/*[clinic end generated code: output=021b89d2d3c3c225 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=86b41e3c503d3a8b input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 4527ae213f021e3..086c1149fa3ebcd 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -1229,32 +1229,16 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - a = ival; + a = _PyNumber_IndexAsSsize_t(args[0]); + if (a == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - b = ival; + b = _PyNumber_IndexAsSsize_t(args[1]); + if (b == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -1265,22 +1249,14 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 4) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - d = ival; - if (d < 0) { - PyErr_SetString(PyExc_ValueError, - "d cannot be negative"); - goto exit; - } + d = _PyNumber_IndexAsSsize_t(args[3]); + if (d == -1 && PyErr_Occurred()) { + goto exit; + } + if (d < 0) { + PyErr_SetString(PyExc_ValueError, + "d cannot be negative"); + goto exit; } if (nargs < 5) { goto skip_optional; @@ -1291,22 +1267,14 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 6) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[5]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - f = ival; - if (f < 0) { - PyErr_SetString(PyExc_ValueError, - "f cannot be negative"); - goto exit; - } + f = _PyNumber_IndexAsSsize_t(args[5]); + if (f == -1 && PyErr_Occurred()) { + goto exit; + } + if (f < 0) { + PyErr_SetString(PyExc_ValueError, + "f cannot be negative"); + goto exit; } if (nargs < 7) { goto skip_optional; @@ -5378,4 +5346,4 @@ vc_kwds_vectorcall(PyObject *type, PyObject *const *args, return return_value; } -/*[clinic end generated code: output=2e36c6f796a4ca09 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=548c6ab1c73d4efe input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h index 1652e9223e54f94..b37df53461f31de 100644 --- a/Modules/clinic/_testclinic_depr.c.h +++ b/Modules/clinic/_testclinic_depr.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -2682,4 +2682,4 @@ depr_multi(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=abe0af8d8c637c36 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=66a4acb1e59782f4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_kwds.c.h b/Modules/clinic/_testclinic_kwds.c.h index 729ba1b6fa7c3da..3aa9e6b8b7ac111 100644 --- a/Modules/clinic/_testclinic_kwds.c.h +++ b/Modules/clinic/_testclinic_kwds.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -189,4 +189,4 @@ kwds_with_pos_only_and_stararg(PyObject *module, PyObject *args, PyObject *kwarg return return_value; } -/*[clinic end generated code: output=ad46500147228faf input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6d4c88f4f460b223 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_threadmodule.c.h b/Modules/clinic/_threadmodule.c.h index 090fdee8f6593e3..34d2a6d4148814c 100644 --- a/Modules/clinic/_threadmodule.c.h +++ b/Modules/clinic/_threadmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() static PyObject * @@ -1066,17 +1066,9 @@ _thread_stack_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - new_size = ival; + new_size = _PyNumber_IndexAsSsize_t(args[0]); + if (new_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = _thread_stack_size_impl(module, new_size); @@ -1272,4 +1264,4 @@ _thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb #endif /* !defined(_THREAD_SET_NAME_METHODDEF) */ #define _THREAD__THREADHANDLE_IDENT_GETSETDEF {"ident", (getter)_thread__ThreadHandle_ident_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=3bfc76a318c6579d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a3fd9715e7373886 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 41798e098389c2a..842d42ae588dd59 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -180,17 +180,9 @@ array_array_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - i = ival; + i = _PyNumber_IndexAsSsize_t(args[0]); + if (i == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = array_array_pop_impl((arrayobject *)self, i); @@ -252,17 +244,9 @@ array_array_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - i = ival; + i = _PyNumber_IndexAsSsize_t(args[0]); + if (i == -1 && PyErr_Occurred()) { + goto exit; } v = args[1]; return_value = array_array_insert_impl((arrayobject *)self, i, v); @@ -381,22 +365,14 @@ array_array_fromfile(PyObject *self, PyTypeObject *cls, PyObject *const *args, P goto exit; } f = args[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "n cannot be negative"); - goto exit; - } + n = _PyNumber_IndexAsSsize_t(args[1]); + if (n == -1 && PyErr_Occurred()) { + goto exit; + } + if (n < 0) { + PyErr_SetString(PyExc_ValueError, + "n cannot be negative"); + goto exit; } return_value = array_array_fromfile_impl((arrayobject *)self, cls, f, n); @@ -722,4 +698,4 @@ array_arrayiterator___setstate__(PyObject *self, PyObject *state) return return_value; } -/*[clinic end generated code: output=172a9af0316afc14 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f02e655f2f345382 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 0c5e35b1516da21..31a9e4bb2abaaea 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_Size_t_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -1221,17 +1221,9 @@ binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bytes_per_sep = ival; + bytes_per_sep = _PyNumber_IndexAsSsize_t(args[2]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep); @@ -1321,17 +1313,9 @@ binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bytes_per_sep = ival; + bytes_per_sep = _PyNumber_IndexAsSsize_t(args[2]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep); @@ -1703,4 +1687,4 @@ binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj return return_value; } -/*[clinic end generated code: output=ec23792754b04657 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=88565cb28608f74f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/faulthandler.c.h b/Modules/clinic/faulthandler.c.h index 07a9dd7dc561e12..c9029fcad404829 100644 --- a/Modules/clinic/faulthandler.c.h +++ b/Modules/clinic/faulthandler.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -91,17 +91,9 @@ faulthandler_dump_traceback_py(PyObject *module, PyObject *const *args, Py_ssize if (!noptargs) { goto skip_optional_kwonly; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_threads = ival; + max_threads = _PyNumber_IndexAsSsize_t(args[2]); + if (max_threads == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_kwonly: return_value = faulthandler_dump_traceback_py_impl(module, file, all_threads, max_threads); @@ -262,17 +254,9 @@ faulthandler_py_enable(PyObject *module, PyObject *const *args, Py_ssize_t nargs if (!noptargs) { goto skip_optional_kwonly; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_threads = ival; + max_threads = _PyNumber_IndexAsSsize_t(args[3]); + if (max_threads == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_kwonly: return_value = faulthandler_py_enable_impl(module, file, all_threads, c_stack, max_threads); @@ -423,17 +407,9 @@ faulthandler_dump_traceback_later(PyObject *module, PyObject *const *args, Py_ss if (!noptargs) { goto skip_optional_kwonly; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[4]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_threads = ival; + max_threads = _PyNumber_IndexAsSsize_t(args[4]); + if (max_threads == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_kwonly: return_value = faulthandler_dump_traceback_later_impl(module, timeout_obj, repeat, file, exit, max_threads); @@ -560,17 +536,9 @@ faulthandler_register_py(PyObject *module, PyObject *const *args, Py_ssize_t nar if (!noptargs) { goto skip_optional_kwonly; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[4]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_threads = ival; + max_threads = _PyNumber_IndexAsSsize_t(args[4]); + if (max_threads == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_kwonly: return_value = faulthandler_register_py_impl(module, signum, file, all_threads, chain, max_threads); @@ -782,4 +750,4 @@ faulthandler__raise_exception(PyObject *module, PyObject *const *args, Py_ssize_ #ifndef FAULTHANDLER__RAISE_EXCEPTION_METHODDEF #define FAULTHANDLER__RAISE_EXCEPTION_METHODDEF #endif /* !defined(FAULTHANDLER__RAISE_EXCEPTION_METHODDEF) */ -/*[clinic end generated code: output=14815a5f8afe813f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9bf8442c4c067e73 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h index 3fd1b7a2fc7b907..5fd3edc2e2d5b02 100644 --- a/Modules/clinic/itertoolsmodule.c.h +++ b/Modules/clinic/itertoolsmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -80,17 +80,9 @@ batched_new_helper(PyTypeObject *type, PyObject *const *args, goto exit; } iterable = fastargs[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; + n = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (n == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_kwonly; @@ -455,22 +447,14 @@ itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "n cannot be negative"); - goto exit; - } + n = _PyNumber_IndexAsSsize_t(args[1]); + if (n == -1 && PyErr_Occurred()) { + goto exit; + } + if (n < 0) { + PyErr_SetString(PyExc_ValueError, + "n cannot be negative"); + goto exit; } skip_optional: return_value = itertools_tee_impl(module, iterable, n); @@ -820,22 +804,14 @@ itertools_combinations_helper(PyTypeObject *type, PyObject *const *args, goto exit; } iterable = fastargs[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - r = ival; - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + r = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (r == -1 && PyErr_Occurred()) { + goto exit; + } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; } return_value = itertools_combinations_impl(type, iterable, r); @@ -871,22 +847,14 @@ itertools_combinations_vectorcall(PyObject *type, PyObject *const *args, NULL, kwnames); } iterable = args[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - r = ival; - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + r = _PyNumber_IndexAsSsize_t(args[1]); + if (r == -1 && PyErr_Occurred()) { + goto exit; + } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; } return_value = itertools_combinations_impl(_PyType_CAST(type), iterable, r); @@ -965,22 +933,14 @@ itertools_combinations_with_replacement_helper(PyTypeObject *type, PyObject *con goto exit; } iterable = fastargs[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(fastargs[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - r = ival; - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + r = _PyNumber_IndexAsSsize_t(fastargs[1]); + if (r == -1 && PyErr_Occurred()) { + goto exit; + } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; } return_value = itertools_combinations_with_replacement_impl(type, iterable, r); @@ -1016,22 +976,14 @@ itertools_combinations_with_replacement_vectorcall(PyObject *type, PyObject *con NULL, kwnames); } iterable = args[0]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - r = ival; - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + r = _PyNumber_IndexAsSsize_t(args[1]); + if (r == -1 && PyErr_Occurred()) { + goto exit; + } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; } return_value = itertools_combinations_with_replacement_impl(_PyType_CAST(type), iterable, r); @@ -1578,4 +1530,4 @@ zip_longest_next(PyObject *self) return return_value; } -/*[clinic end generated code: output=60939958c9c9348b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c4b61f8d7a14c9d7 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h index ece08c0fb6007c0..a3b44f6778596ac 100644 --- a/Modules/clinic/mmapmodule.c.h +++ b/Modules/clinic/mmapmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -330,17 +330,9 @@ mmap_mmap_resize(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t new_size; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - new_size = ival; + new_size = _PyNumber_IndexAsSsize_t(arg); + if (new_size == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = mmap_mmap_resize_impl((mmap_object *)self, new_size); @@ -433,33 +425,17 @@ mmap_mmap_flush(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_posonly; } noptargs--; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - offset = ival; + offset = _PyNumber_IndexAsSsize_t(args[0]); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional_posonly; } noptargs--; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[1]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_posonly: if (!noptargs) { @@ -499,17 +475,9 @@ mmap_mmap_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - dist = ival; + dist = _PyNumber_IndexAsSsize_t(args[0]); + if (dist == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -600,41 +568,17 @@ mmap_mmap_move(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("move", nargs, 3, 3)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - dest = ival; + dest = _PyNumber_IndexAsSsize_t(args[0]); + if (dest == -1 && PyErr_Occurred()) { + goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - src = ival; + src = _PyNumber_IndexAsSsize_t(args[1]); + if (src == -1 && PyErr_Occurred()) { + goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - cnt = ival; + cnt = _PyNumber_IndexAsSsize_t(args[2]); + if (cnt == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = mmap_mmap_move_impl((mmap_object *)self, dest, src, cnt); @@ -784,29 +728,13 @@ mmap_mmap__protect(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - start = ival; + start = _PyNumber_IndexAsSsize_t(args[1]); + if (start == -1 && PyErr_Occurred()) { + goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(args[2]); + if (length == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = mmap_mmap__protect_impl((mmap_object *)self, flNewProtect, start, length); @@ -850,17 +778,9 @@ mmap_mmap_madvise(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - start = ival; + start = _PyNumber_IndexAsSsize_t(args[1]); + if (start == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -967,4 +887,4 @@ mmap_ass_subscript(PyObject *self, PyObject *item, PyObject *value) #ifndef MMAP_MMAP_MADVISE_METHODDEF #define MMAP_MMAP_MADVISE_METHODDEF #endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */ -/*[clinic end generated code: output=90a906cde591ab92 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cc1d65746cfc1580 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index c2f183f70378367..69a06caabb2eaa9 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -5706,17 +5706,9 @@ os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (pid == (pid_t)(-1) && PyErr_Occurred()) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - signal = ival; + signal = _PyNumber_IndexAsSsize_t(args[1]); + if (signal == -1 && PyErr_Occurred()) { + goto exit; } return_value = os_kill_impl(module, pid, signal); @@ -7851,17 +7843,9 @@ os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (fd == -1 && PyErr_Occurred()) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(args[1]); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = os_read_impl(module, fd, length); @@ -8007,17 +7991,9 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (fd == -1 && PyErr_Occurred()) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(args[1]); + if (length == -1 && PyErr_Occurred()) { + goto exit; } if (!_Py_Off_t_Converter(args[2], &offset)) { goto exit; @@ -8326,22 +8302,14 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!_Py_Off_t_Converter(args[2], &offset)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + count = _PyNumber_IndexAsSsize_t(args[3]); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -8437,22 +8405,14 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } offobj = args[2]; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[3]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + count = _PyNumber_IndexAsSsize_t(args[3]); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; } return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); @@ -8930,22 +8890,14 @@ os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py if (dst == -1 && PyErr_Occurred()) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -9053,22 +9005,14 @@ os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k if (dst == -1 && PyErr_Occurred()) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -11519,22 +11463,14 @@ os_urandom(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t size; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; - if (size < 0) { - PyErr_SetString(PyExc_ValueError, - "size cannot be negative"); - goto exit; - } + size = _PyNumber_IndexAsSsize_t(arg); + if (size == -1 && PyErr_Occurred()) { + goto exit; + } + if (size < 0) { + PyErr_SetString(PyExc_ValueError, + "size cannot be negative"); + goto exit; } return_value = os_urandom_impl(module, size); @@ -12655,17 +12591,9 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(args[0]); + if (size == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -13763,4 +13691,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=077c57e5f93bd790 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b44461fd2db79d32 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha3module.c.h b/Modules/clinic/sha3module.c.h index 7fdc707626c3243..aebe28235fabc50 100644 --- a/Modules/clinic/sha3module.c.h +++ b/Modules/clinic/sha3module.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(py_sha3_new__doc__, @@ -224,22 +224,14 @@ _sha3_shake_128_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; } return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length); @@ -298,26 +290,18 @@ _sha3_shake_128_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t narg if (!args) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; } return_value = _sha3_shake_128_hexdigest_impl((SHA3object *)self, length); exit: return return_value; } -/*[clinic end generated code: output=78284adde71d590c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5a6dd6c2d3d0b271 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index 5a1a128b304f028..653d26012106365 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UInt16_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -452,17 +452,9 @@ _socket_socket_recv(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recv", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - recvlen = ival; + recvlen = _PyNumber_IndexAsSsize_t(args[0]); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -547,17 +539,9 @@ _socket_socket_recv_into(PyObject *s, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - recvlen = ival; + recvlen = _PyNumber_IndexAsSsize_t(args[1]); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -607,17 +591,9 @@ _socket_socket_recvfrom(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recvfrom", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - recvlen = ival; + recvlen = _PyNumber_IndexAsSsize_t(args[0]); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -703,17 +679,9 @@ _socket_socket_recvfrom_into(PyObject *s, PyObject *const *args, Py_ssize_t narg goto skip_optional_pos; } if (args[1]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - recvlen = ival; + recvlen = _PyNumber_IndexAsSsize_t(args[1]); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -788,32 +756,16 @@ _socket_socket_recvmsg(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recvmsg", nargs, 1, 3)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bufsize = ival; + bufsize = _PyNumber_IndexAsSsize_t(args[0]); + if (bufsize == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - ancbufsize = ival; + ancbufsize = _PyNumber_IndexAsSsize_t(args[1]); + if (ancbufsize == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -890,17 +842,9 @@ _socket_socket_recvmsg_into(PyObject *s, PyObject *const *args, Py_ssize_t nargs if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - ancbufsize = ival; + ancbufsize = _PyNumber_IndexAsSsize_t(args[1]); + if (ancbufsize == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -2244,17 +2188,9 @@ _socket_CMSG_LEN(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t length; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(arg); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = _socket_CMSG_LEN_impl(module, length); @@ -2290,17 +2226,9 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t length; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(arg); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = _socket_CMSG_SPACE_impl(module, length); @@ -2449,4 +2377,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=e6e677d3de0c63e4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3ea9ab7ef20ed0d8 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/unicodedata.c.h b/Modules/clinic/unicodedata.c.h index 5443893079b1af8..7a0291121ef766a 100644 --- a/Modules/clinic/unicodedata.c.h +++ b/Modules/clinic/unicodedata.c.h @@ -2,7 +2,7 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, @@ -657,32 +657,16 @@ unicodedata_iter_graphemes(PyObject *module, PyObject *const *args, Py_ssize_t n if (nargs < 2) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - start = ival; + start = _PyNumber_IndexAsSsize_t(args[1]); + if (start == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - end = ival; + end = _PyNumber_IndexAsSsize_t(args[2]); + if (end == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = unicodedata_iter_graphemes_impl(module, unistr, start, end); @@ -834,4 +818,4 @@ unicodedata_extended_pictographic(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=482a87df218f07c1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=03ace54ed1775071 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 023b178dc58fb5b..3fe8430643bae52 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(zlib_compress__doc__, @@ -178,22 +178,14 @@ zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bufsize = ival; - if (bufsize < 0) { - PyErr_SetString(PyExc_ValueError, - "bufsize cannot be negative"); - goto exit; - } + bufsize = _PyNumber_IndexAsSsize_t(args[2]); + if (bufsize == -1 && PyErr_Occurred()) { + goto exit; + } + if (bufsize < 0) { + PyErr_SetString(PyExc_ValueError, + "bufsize cannot be negative"); + goto exit; } skip_optional_pos: return_value = zlib_decompress_impl(module, &data, wbits, bufsize); @@ -548,22 +540,14 @@ zlib_Decompress_decompress(PyObject *self, PyTypeObject *cls, PyObject *const *a if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_length = ival; - if (max_length < 0) { - PyErr_SetString(PyExc_ValueError, - "max_length cannot be negative"); - goto exit; - } + max_length = _PyNumber_IndexAsSsize_t(args[1]); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; + } + if (max_length < 0) { + PyErr_SetString(PyExc_ValueError, + "max_length cannot be negative"); + goto exit; } skip_optional_pos: return_value = zlib_Decompress_decompress_impl((compobject *)self, cls, &data, max_length); @@ -824,17 +808,9 @@ zlib_Decompress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = zlib_Decompress_flush_impl((compobject *)self, cls, length); @@ -918,17 +894,9 @@ zlib__ZlibDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - max_length = ival; + max_length = _PyNumber_IndexAsSsize_t(args[1]); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = zlib__ZlibDecompressor_decompress_impl((ZlibDecompressor *)self, &data, max_length); @@ -1338,4 +1306,4 @@ zlib_crc32_combine(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=f4c3b5abac20df9b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0649f957a763763f input=a9049054013a1b77]*/ diff --git a/Objects/abstract.c b/Objects/abstract.c index 635e1e927f23370..f041e0e30ff28b1 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1473,54 +1473,67 @@ PyNumber_Index(PyObject *item) return result; } -/* Return an error on Overflow only if err is not NULL*/ - Py_ssize_t -PyNumber_AsSsize_t(PyObject *item, PyObject *err) +_PyNumber_IndexAsSsize_t(PyObject *item) { - Py_ssize_t result; - PyObject *runerr; + if (item != NULL && PyLong_Check(item)) { + /* Fast path: no new reference is needed. */ + return PyLong_AsSsize_t(item); + } PyObject *value = _PyNumber_Index(item); - if (value == NULL) + if (value == NULL) { return -1; + } + Py_ssize_t result = PyLong_AsSsize_t(value); + Py_DECREF(value); + return result; +} - /* We're done if PyLong_AsSsize_t() returns without error. */ - result = PyLong_AsSsize_t(value); - if (result != -1) - goto finish; - - PyThreadState *tstate = _PyThreadState_GET(); - runerr = _PyErr_Occurred(tstate); - if (!runerr) { - goto finish; +/* Convert the int 'value', the index of 'item', to a Py_ssize_t. + On overflow, clip the result if err is NULL, otherwise raise err. */ +static Py_ssize_t +index_as_ssize_t(PyObject *item, PyObject *value, PyObject *err) +{ + assert(PyLong_Check(value)); + Py_ssize_t result = PyLong_AsSsize_t(value); + if (result != -1) { + return result; } - /* Error handling code -- only manage OverflowError differently */ - if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { - goto finish; + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *runerr = _PyErr_Occurred(tstate); + /* Only OverflowError is handled differently. */ + if (!runerr || !PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { + return result; } _PyErr_Clear(tstate); - /* If no error-handling desired then the default clipping - is sufficient. */ if (!err) { - assert(PyLong_Check(value)); - /* Whether or not it is less than or equal to - zero is determined by the sign of ob_size - */ - if (_PyLong_IsNegative((PyLongObject *)value)) - result = PY_SSIZE_T_MIN; - else - result = PY_SSIZE_T_MAX; + /* No error handling desired: clip to the Py_ssize_t range. */ + return _PyLong_IsNegative((PyLongObject *)value) + ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX; + } + /* Otherwise replace the error with caller's error object. */ + _PyErr_Format(tstate, err, + "cannot fit '%.200s' into an index-sized integer", + Py_TYPE(item)->tp_name); + return -1; +} + +/* Return an error on Overflow only if err is not NULL*/ + +Py_ssize_t +PyNumber_AsSsize_t(PyObject *item, PyObject *err) +{ + if (item != NULL && PyLong_Check(item)) { + /* Fast path: no new reference is needed. */ + return index_as_ssize_t(item, item, err); } - else { - /* Otherwise replace the error with caller's error object. */ - _PyErr_Format(tstate, err, - "cannot fit '%.200s' into an index-sized integer", - Py_TYPE(item)->tp_name); + PyObject *value = _PyNumber_Index(item); + if (value == NULL) { + return -1; } - - finish: + Py_ssize_t result = index_as_ssize_t(item, value, err); Py_DECREF(value); return result; } diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 5445aa0166967a2..69f5dbd1168d05e 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_runtime.h" // _Py_SINGLETON() @@ -778,17 +778,9 @@ bytearray_resize(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t size; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - size = ival; + size = _PyNumber_IndexAsSsize_t(arg); + if (size == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = bytearray_resize_impl((PyByteArrayObject *)self, size); @@ -1029,17 +1021,9 @@ bytearray_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1130,17 +1114,9 @@ bytearray_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1290,17 +1266,9 @@ bytearray_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1362,17 +1330,9 @@ bytearray_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } if (!_getbytevalue(args[1], &item)) { goto exit; @@ -1474,17 +1434,9 @@ bytearray_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -1938,17 +1890,9 @@ bytearray_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bytes_per_sep = ival; + bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -2037,4 +1981,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=b8e659fe4b2f770e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=983dab0d45700f6c input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index c96cd94425c1d18..f830f36a18b7dc3 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -98,17 +98,9 @@ bytes_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *k goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_split_impl((PyBytesObject *)self, sep, maxsplit); @@ -269,17 +261,9 @@ bytes_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_rsplit_impl((PyBytesObject *)self, sep, maxsplit); @@ -864,17 +848,9 @@ bytes_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_replace_impl((PyBytesObject *)self, &old, &new, count); @@ -1333,17 +1309,9 @@ bytes_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bytes_per_sep = ival; + bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_hex_impl((PyBytesObject *)self, sep, bytes_per_sep); @@ -1497,4 +1465,4 @@ bytes_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=0d49a97b9e2eef5b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=16e2d748f31ad751 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 359b9c202694472..a9b1db1d89a5e79 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -92,17 +92,9 @@ list_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } object = args[1]; Py_BEGIN_CRITICAL_SECTION(self); @@ -233,17 +225,9 @@ list_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; + index = _PyNumber_IndexAsSsize_t(args[0]); + if (index == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -528,4 +512,4 @@ list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl((PyListObject *)self); } -/*[clinic end generated code: output=9eab9551fc4cea1c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3971f91f7d5bb703 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index 52ecaffa1f4cf35..29debb939a8c584 100644 --- a/Objects/clinic/longobject.c.h +++ b/Objects/clinic/longobject.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -330,22 +330,14 @@ int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * goto skip_optional_pos; } if (args[0]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + length = _PyNumber_IndexAsSsize_t(args[0]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -493,4 +485,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) { return int_is_integer_impl(self); } -/*[clinic end generated code: output=d95766fb7ff46963 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e835437267a7c4d2 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index bb81e11e9a0ce20..8261a253198ed06 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -502,17 +502,9 @@ memoryview_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - bytes_per_sep = ival; + bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = memoryview_hex_impl((PyMemoryViewObject *)self, sep, bytes_per_sep); @@ -588,4 +580,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=cdca13a132752f15 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7e4568eeb9f13257 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index f214fa42fa1a594..7cc7415090e1fe0 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -113,17 +113,9 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -757,17 +749,9 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -977,17 +961,9 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec if (!noptargs) { goto skip_optional_pos; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; + count = _PyNumber_IndexAsSsize_t(args[2]); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_replace_impl(self, old, new, count); @@ -1199,17 +1175,9 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -1302,17 +1270,9 @@ unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_split_impl(self, sep, maxsplit); @@ -1428,17 +1388,9 @@ unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; + maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_rsplit_impl(self, sep, maxsplit); @@ -1646,17 +1598,9 @@ unicode_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(arg); + if (width == -1 && PyErr_Occurred()) { + goto exit; } return_value = unicode_zfill_impl(self, width); @@ -1897,4 +1841,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=80d039a395f835c3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6d38f779d89f1fcc input=a9049054013a1b77]*/ diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index 588fc101dbb5e3e..da1eaf7feead6e0 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(stringlib_expandtabs__doc__, @@ -101,17 +101,9 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -171,17 +163,9 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -241,17 +225,9 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(args[0]); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -307,21 +283,13 @@ stringlib_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; + width = _PyNumber_IndexAsSsize_t(arg); + if (width == -1 && PyErr_Occurred()) { + goto exit; } return_value = stringlib_zfill_impl(self, width); exit: return return_value; } -/*[clinic end generated code: output=8363b4b6cdaad556 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=75c521d89a08ddf4 input=a9049054013a1b77]*/ diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index a64418be0a830ba..6333d036f3affff 100644 --- a/Python/clinic/_warnings.c.h +++ b/Python/clinic/_warnings.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(warnings_acquire_lock__doc__, @@ -126,17 +126,9 @@ warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec } } if (args[2]) { - { - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - stacklevel = ival; + stacklevel = _PyNumber_IndexAsSsize_t(args[2]); + if (stacklevel == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -284,4 +276,4 @@ warnings_filters_mutated_lock_held(PyObject *module, PyObject *Py_UNUSED(ignored { return warnings_filters_mutated_lock_held_impl(module); } -/*[clinic end generated code: output=fc026d6a21e12170 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=65b9b5e4aca87788 input=a9049054013a1b77]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 70bd54a23e939ce..b0d1a2ea46764c1 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -830,14 +830,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, case 'n': /* Py_ssize_t */ { - PyObject *iobj; Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *); - Py_ssize_t ival = -1; - iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } + Py_ssize_t ival = _PyNumber_IndexAsSsize_t(arg); if (ival == -1 && PyErr_Occurred()) RETURN_ERR_OCCURRED; *p = ival; diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index 014486f7f469def..b1dab4aefd0a7fd 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -468,15 +468,22 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st argname=argname, ) if self.format_unit == 'n': - if limited_capi: - PyNumber_Index = 'PyNumber_Index' - else: - PyNumber_Index = '_PyNumber_Index' - self.add_include('pycore_abstract.h', '_PyNumber_Index()') + if not limited_capi: + self.add_include('pycore_abstract.h', + '_PyNumber_IndexAsSsize_t()') + return self.format_code(""" + {paramname} = _PyNumber_IndexAsSsize_t({argname}); + if ({paramname} == -1 && PyErr_Occurred()) {{{{ + goto exit; + }}}}{non_negative_check} + """, + argname=argname, + non_negative_check=non_negative_check, + ) return self.format_code(""" {{{{ Py_ssize_t ival = -1; - PyObject *iobj = {PyNumber_Index}({argname}); + PyObject *iobj = PyNumber_Index({argname}); if (iobj != NULL) {{{{ ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -488,7 +495,6 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st }}}} """, argname=argname, - PyNumber_Index=PyNumber_Index, non_negative_check=non_negative_check, ) if not limited_capi: From aeba29e2a6b2a5549ac5aab9bd65e533a2696036 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 27 Nov 2026 16:31:25 +0100 Subject: [PATCH 2/4] Use _PyNumber_IndexAsSsize_t() in mmap and memoryview Co-Authored-By: Claude Fable 5.2 --- Modules/mmapmodule.c | 23 +++-------------------- Objects/memoryobject.c | 17 +---------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 06099a3b8b2e0be..c012958d2b5f4c7 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -139,23 +139,6 @@ typedef struct { #include "clinic/mmapmodule.c.h" -/* Return a Py_ssize_t from the object arg. This conversion logic is similar - to what AC uses for `Py_ssize_t` arguments. - - Returns -1 on error. Use PyErr_Occurred() to disambiguate. -*/ -static Py_ssize_t -_As_Py_ssize_t(PyObject *arg) { - assert(arg != NULL); - Py_ssize_t ival = -1; - PyObject *iobj = _PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - return ival; -} - static void mmap_object_dealloc(PyObject *op) { @@ -603,13 +586,13 @@ mmap_gfind_lock_held(mmap_object *self, Py_buffer *view, PyObject *start_obj, CHECK_VALID(NULL); if (start_obj != Py_None) { - start = _As_Py_ssize_t(start_obj); + start = _PyNumber_IndexAsSsize_t(start_obj); if (start == -1 && PyErr_Occurred()) { return NULL; } if (end_obj != Py_None) { - end = _As_Py_ssize_t(end_obj); + end = _PyNumber_IndexAsSsize_t(end_obj); if (end == -1 && PyErr_Occurred()) { return NULL; } @@ -1383,7 +1366,7 @@ mmap_mmap_madvise_impl(mmap_object *self, int option, Py_ssize_t start, if (length_obj == Py_None) { length = self->size; } else { - length = _As_Py_ssize_t(length_obj); + length = _PyNumber_IndexAsSsize_t(length_obj); if (length == -1 && PyErr_Occurred()) { return NULL; } diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index d695d8cac2fedab..5da9dad3cd53fc3 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1946,21 +1946,6 @@ pylong_as_llu(PyObject *item) return llu; } -static Py_ssize_t -pylong_as_zd(PyObject *item) -{ - PyObject *tmp; - Py_ssize_t zd; - - tmp = _PyNumber_Index(item); - if (tmp == NULL) - return -1; - - zd = PyLong_AsSsize_t(tmp); - Py_DECREF(tmp); - return zd; -} - static size_t pylong_as_zu(PyObject *item) { @@ -2187,7 +2172,7 @@ pack_single(PyMemoryViewObject *self, char *ptr, PyObject *item, const char *fmt /* ssize_t and size_t */ case 'n': - zd = pylong_as_zd(item); + zd = _PyNumber_IndexAsSsize_t(item); if (zd == -1 && PyErr_Occurred()) goto err_occurred; CHECK_RELEASED_INT_AGAIN(self); From ca4cba074ba75d519df98845e0fc7781161afb91 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 1 Dec 2026 00:15:27 +0100 Subject: [PATCH 3/4] Use PyNumber_AsSsize_t() with an int fast path instead of a new helper Co-Authored-By: Claude Fable 5.2 --- Include/internal/pycore_abstract.h | 2 - Lib/test/clinic.test.c | 20 ++--- Lib/test/test_zlib.py | 6 +- Modules/_ctypes/clinic/_ctypes.c.h | 27 +++--- Modules/_ctypes/clinic/callproc.c.h | 7 +- Modules/_ctypes/clinic/cfield.c.h | 9 +- Modules/_decimal/clinic/_decimal.c.h | 11 ++- Modules/_io/clinic/bufferedio.c.h | 16 ++-- Modules/_io/clinic/bytesio.c.h | 6 +- Modules/_io/clinic/iobase.c.h | 4 +- Modules/_io/clinic/stringio.c.h | 4 +- Modules/_io/clinic/textio.c.h | 6 +- Modules/_sre/clinic/sre.c.h | 35 ++++---- Modules/_struct.c | 1 + .../_testinternalcapi/clinic/test_lock.c.h | 9 +- Modules/_zstd/clinic/_zstdmodule.c.h | 7 +- Modules/_zstd/clinic/decompressor.c.h | 5 +- Modules/arraymodule.c | 1 + Modules/clinic/_bisectmodule.c.h | 52 +++++------ Modules/clinic/_bz2module.c.h | 5 +- Modules/clinic/_collectionsmodule.c.h | 9 +- Modules/clinic/_elementtree.c.h | 5 +- Modules/clinic/_hashopenssl.c.h | 27 +++--- Modules/clinic/_interpqueuesmodule.c.h | 5 +- Modules/clinic/_json.c.h | 5 +- Modules/clinic/_lzmamodule.c.h | 5 +- Modules/clinic/_operator.c.h | 5 +- Modules/clinic/_ssl.c.h | 5 +- Modules/clinic/_struct.c.h | 11 ++- Modules/clinic/_testclinic.c.h | 32 +++---- Modules/clinic/_testclinic_depr.c.h | 4 +- Modules/clinic/_testclinic_kwds.c.h | 4 +- Modules/clinic/_threadmodule.c.h | 5 +- Modules/clinic/arraymodule.c.h | 19 ++-- Modules/clinic/binascii.c.h | 7 +- Modules/clinic/faulthandler.c.h | 11 ++- Modules/clinic/itertoolsmodule.c.h | 65 +++++++------- Modules/clinic/mmapmodule.c.h | 23 +++-- Modules/clinic/posixmodule.c.h | 71 ++++++++------- Modules/clinic/sha3module.c.h | 27 +++--- Modules/clinic/socketmodule.c.h | 21 +++-- Modules/clinic/unicodedata.c.h | 7 +- Modules/clinic/zlibmodule.c.h | 31 ++++--- Modules/mmapmodule.c | 6 +- Objects/abstract.c | 87 +++++++++---------- Objects/clinic/bytearrayobject.c.h | 17 ++-- Objects/clinic/bytesobject.c.h | 11 ++- Objects/clinic/listobject.c.h | 7 +- Objects/clinic/longobject.c.h | 15 ++-- Objects/clinic/memoryobject.c.h | 5 +- Objects/clinic/unicodeobject.c.h | 17 ++-- Objects/longobject.c | 1 + Objects/memoryobject.c | 2 +- Objects/stringlib/clinic/transmogrify.h.h | 11 ++- Python/clinic/_warnings.c.h | 5 +- Python/getargs.c | 2 +- Tools/clinic/libclinic/converters.py | 28 +----- 57 files changed, 394 insertions(+), 457 deletions(-) diff --git a/Include/internal/pycore_abstract.h b/Include/internal/pycore_abstract.h index cb387b4bead26cb..67c6fa7c0c4ed5b 100644 --- a/Include/internal/pycore_abstract.h +++ b/Include/internal/pycore_abstract.h @@ -60,8 +60,6 @@ PyAPI_FUNC(int) _Py_convert_optional_to_non_negative_ssize_t(PyObject *, void *) // Export for 'math' shared extension. PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject *o); -PyAPI_FUNC(Py_ssize_t) _PyNumber_IndexAsSsize_t(PyObject *o); - typedef struct { PyObject *object; PySendResult kind; diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index dc98e57b956a0b8..432a642fc5ac70e 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -1652,14 +1652,14 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 1) { goto skip_optional; } - a = _PyNumber_IndexAsSsize_t(args[0]); + a = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (a == -1 && PyErr_Occurred()) { goto exit; } if (nargs < 2) { goto skip_optional; } - b = _PyNumber_IndexAsSsize_t(args[1]); + b = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (b == -1 && PyErr_Occurred()) { goto exit; } @@ -1672,15 +1672,15 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 4) { goto skip_optional; } - d = _PyNumber_IndexAsSsize_t(args[3]); + d = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (d == -1 && PyErr_Occurred()) { goto exit; } - if (d < 0) { - PyErr_SetString(PyExc_ValueError, - "d cannot be negative"); - goto exit; - } + if (d < 0) { + PyErr_SetString(PyExc_ValueError, + "d cannot be negative"); + goto exit; + } if (nargs < 5) { goto skip_optional; } @@ -1690,7 +1690,7 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na if (nargs < 6) { goto skip_optional; } - f = _PyNumber_IndexAsSsize_t(args[5]); + f = PyNumber_AsSsize_t(args[5], PyExc_OverflowError); if (f == -1 && PyErr_Occurred()) { goto exit; } @@ -1711,7 +1711,7 @@ static PyObject * test_Py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b, Py_ssize_t c, Py_ssize_t d, Py_ssize_t e, Py_ssize_t f, Py_ssize_t g) -/*[clinic end generated code: output=e4286b4ef87a92ab input=a25bac8ecf2890aa]*/ +/*[clinic end generated code: output=4f744bf0d897e01c input=a25bac8ecf2890aa]*/ /*[clinic input] diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 3243448043b5c21..e877807cf95287b 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -337,11 +337,11 @@ def test_decompressobj_badflush(self): @support.cpython_only def test_overflow(self): - with self.assertRaisesRegex(OverflowError, 'int too large'): + with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"): zlib.decompress(b'', 15, sys.maxsize + 1) - with self.assertRaisesRegex(OverflowError, 'int too large'): + with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"): zlib.decompressobj().decompress(b'', sys.maxsize + 1) - with self.assertRaisesRegex(OverflowError, 'int too large'): + with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"): zlib.decompressobj().flush(sys.maxsize + 1) @support.cpython_only diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index 673b725ce16b9ae..c0b62077eded683 100644 --- a/Modules/_ctypes/clinic/_ctypes.c.h +++ b/Modules/_ctypes/clinic/_ctypes.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -121,15 +120,15 @@ CDataType_from_buffer(PyObject *type, PyTypeObject *cls, PyObject *const *args, if (nargs < 2) { goto skip_optional; } - offset = _PyNumber_IndexAsSsize_t(args[1]); + offset = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - goto exit; - } + if (offset < 0) { + PyErr_SetString(PyExc_ValueError, + "offset cannot be negative"); + goto exit; + } skip_optional: return_value = CDataType_from_buffer_impl(type, cls, obj, offset); @@ -171,15 +170,15 @@ CDataType_from_buffer_copy(PyObject *type, PyTypeObject *cls, PyObject *const *a if (nargs < 2) { goto skip_optional; } - offset = _PyNumber_IndexAsSsize_t(args[1]); + offset = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - goto exit; - } + if (offset < 0) { + PyErr_SetString(PyExc_ValueError, + "offset cannot be negative"); + goto exit; + } skip_optional: return_value = CDataType_from_buffer_copy_impl(type, cls, &buffer, offset); @@ -922,4 +921,4 @@ Pointer_bool(PyObject *self) #define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL}, -/*[clinic end generated code: output=fbed245eac716dfb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=793593f53dd481a1 input=a9049054013a1b77]*/ diff --git a/Modules/_ctypes/clinic/callproc.c.h b/Modules/_ctypes/clinic/callproc.c.h index d4ee05ac0a69c20..f39de1bf02d8ec9 100644 --- a/Modules/_ctypes/clinic/callproc.c.h +++ b/Modules/_ctypes/clinic/callproc.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -562,7 +561,7 @@ _ctypes_byref(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - offset = _PyNumber_IndexAsSsize_t(args[1]); + offset = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -676,7 +675,7 @@ _ctypes_resize(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } obj = (CDataObject *)args[0]; - size = _PyNumber_IndexAsSsize_t(args[1]); + size = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -777,4 +776,4 @@ PyDoc_STRVAR(_ctypes_buffer_info__doc__, #ifndef _CTYPES_DLLIST_METHODDEF #define _CTYPES_DLLIST_METHODDEF #endif /* !defined(_CTYPES_DLLIST_METHODDEF) */ -/*[clinic end generated code: output=37057eac2b3577f2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=30c160c7d1fe4547 input=a9049054013a1b77]*/ diff --git a/Modules/_ctypes/clinic/cfield.c.h b/Modules/_ctypes/clinic/cfield.c.h index f9cdb6e45f700f2..4563b0c5fbb3de3 100644 --- a/Modules/_ctypes/clinic/cfield.c.h +++ b/Modules/_ctypes/clinic/cfield.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -70,15 +69,15 @@ PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } name = fastargs[0]; proto = fastargs[1]; - byte_size = _PyNumber_IndexAsSsize_t(fastargs[2]); + byte_size = PyNumber_AsSsize_t(fastargs[2], PyExc_OverflowError); if (byte_size == -1 && PyErr_Occurred()) { goto exit; } - byte_offset = _PyNumber_IndexAsSsize_t(fastargs[3]); + byte_offset = PyNumber_AsSsize_t(fastargs[3], PyExc_OverflowError); if (byte_offset == -1 && PyErr_Occurred()) { goto exit; } - index = _PyNumber_IndexAsSsize_t(fastargs[4]); + index = PyNumber_AsSsize_t(fastargs[4], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -102,4 +101,4 @@ PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=4122d1912de8ec17 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f0e5a4d1e8236428 input=a9049054013a1b77]*/ diff --git a/Modules/_decimal/clinic/_decimal.c.h b/Modules/_decimal/clinic/_decimal.c.h index ce456cd184669f5..25ce73804324794 100644 --- a/Modules/_decimal/clinic/_decimal.c.h +++ b/Modules/_decimal/clinic/_decimal.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_decimal_Context_Etiny__doc__, @@ -70,7 +69,7 @@ _decimal_Context__unsafe_setprec(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - x = _PyNumber_IndexAsSsize_t(arg); + x = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (x == -1 && PyErr_Occurred()) { goto exit; } @@ -101,7 +100,7 @@ _decimal_Context__unsafe_setemin(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - x = _PyNumber_IndexAsSsize_t(arg); + x = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (x == -1 && PyErr_Occurred()) { goto exit; } @@ -132,7 +131,7 @@ _decimal_Context__unsafe_setemax(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t x; - x = _PyNumber_IndexAsSsize_t(arg); + x = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (x == -1 && PyErr_Occurred()) { goto exit; } @@ -325,7 +324,7 @@ _decimal_IEEEContext(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t bits; - bits = _PyNumber_IndexAsSsize_t(arg); + bits = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (bits == -1 && PyErr_Occurred()) { goto exit; } @@ -6298,4 +6297,4 @@ _decimal_Context_same_quantum(PyObject *context, PyTypeObject *cls, PyObject *co #ifndef _DECIMAL_CONTEXT_APPLY_METHODDEF #define _DECIMAL_CONTEXT_APPLY_METHODDEF #endif /* !defined(_DECIMAL_CONTEXT_APPLY_METHODDEF) */ -/*[clinic end generated code: output=0cfed229bcfa29e7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c03dbb492658d47f input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 17f2dbb86ad47e2..00152c8b74fb9dc 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_BadArgument() @@ -556,7 +556,7 @@ _io__Buffered_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - size = _PyNumber_IndexAsSsize_t(args[0]); + size = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -627,7 +627,7 @@ _io__Buffered_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - n = _PyNumber_IndexAsSsize_t(args[0]); + n = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } @@ -897,7 +897,7 @@ _io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + buffer_size = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (buffer_size == -1 && PyErr_Occurred()) { goto exit; } @@ -969,7 +969,7 @@ _io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + buffer_size = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (buffer_size == -1 && PyErr_Occurred()) { goto exit; } @@ -1053,7 +1053,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (PyTuple_GET_SIZE(args) < 3) { goto skip_optional; } - buffer_size = _PyNumber_IndexAsSsize_t(PyTuple_GET_ITEM(args, 2)); + buffer_size = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 2), PyExc_OverflowError); if (buffer_size == -1 && PyErr_Occurred()) { goto exit; } @@ -1411,7 +1411,7 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) if (!noptargs) { goto skip_optional_pos; } - buffer_size = _PyNumber_IndexAsSsize_t(fastargs[1]); + buffer_size = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (buffer_size == -1 && PyErr_Occurred()) { goto exit; } @@ -1429,4 +1429,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) #define _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF {"closed", (getter)_io_BufferedRWPair_closed_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=6654f42d328e1669 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=901ead01a5201538 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index f6053de1e3aabdf..c9258d2dc1f13f9 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -337,7 +337,7 @@ _io_BytesIO_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - size = _PyNumber_IndexAsSsize_t(args[0]); + size = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -546,7 +546,7 @@ _io_BytesIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - pos = _PyNumber_IndexAsSsize_t(args[0]); + pos = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -840,4 +840,4 @@ _io_BytesIO___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) } #define _IO_BYTESIO_CLOSED_GETSETDEF {"closed", (getter)_io_BytesIO_closed_get, (setter)NULL, _io_BytesIO_closed__doc__}, -/*[clinic end generated code: output=59fa44461bf22b2d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a721dad172febd8a input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index 82b2625b94c7c88..a5980809baedcaa 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -519,7 +519,7 @@ _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - n = _PyNumber_IndexAsSsize_t(args[0]); + n = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } @@ -565,4 +565,4 @@ PyDoc_STRVAR(_io__RawIOBase_write__doc__, {"write", (PyCFunction)_io__RawIOBase_write, METH_O, _io__RawIOBase_write__doc__}, #define _IO__IOBASE_CLOSED_GETSETDEF {"closed", (getter)_io__IOBase_closed_get, (setter)NULL, _io__IOBase_closed__doc__}, -/*[clinic end generated code: output=c6e8fb15c12488c6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=17a7966b93718c00 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 37e7f697cdb0029..0660b8514431a50 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -217,7 +217,7 @@ _io_StringIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - pos = _PyNumber_IndexAsSsize_t(args[0]); + pos = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -546,4 +546,4 @@ _io_StringIO_newlines_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=fa7fedc7af389cc8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0540255c876577ea input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 6d20515fdb4bfe8..e5bdf5e8e128647 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -867,7 +867,7 @@ _io_TextIOWrapper_readline(PyObject *self, PyObject *const *args, Py_ssize_t nar if (nargs < 1) { goto skip_optional; } - size = _PyNumber_IndexAsSsize_t(args[0]); + size = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -1268,7 +1268,7 @@ _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *arg, void *Py_UNUSED Py_TYPE(self)->tp_name); return -1; } - value = _PyNumber_IndexAsSsize_t(arg); + value = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (value == -1 && PyErr_Occurred()) { goto exit; } @@ -1314,4 +1314,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=490dea749ae81315 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=65e59d4741f3931e input=a9049054013a1b77]*/ diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index 91e5aafcb32fd2e..b42f62416eb18c1 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_sre_getcodesize__doc__, @@ -225,7 +224,7 @@ _sre_SRE_Pattern_prefixmatch(PyObject *self, PyTypeObject *cls, PyObject *const goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -233,7 +232,7 @@ _sre_SRE_Pattern_prefixmatch(PyObject *self, PyTypeObject *cls, PyObject *const goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -305,7 +304,7 @@ _sre_SRE_Pattern_fullmatch(PyObject *self, PyTypeObject *cls, PyObject *const *a goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -313,7 +312,7 @@ _sre_SRE_Pattern_fullmatch(PyObject *self, PyTypeObject *cls, PyObject *const *a goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -387,7 +386,7 @@ _sre_SRE_Pattern_search(PyObject *self, PyTypeObject *cls, PyObject *const *args goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -395,7 +394,7 @@ _sre_SRE_Pattern_search(PyObject *self, PyTypeObject *cls, PyObject *const *args goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -466,7 +465,7 @@ _sre_SRE_Pattern_findall(PyObject *self, PyObject *const *args, Py_ssize_t nargs goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -474,7 +473,7 @@ _sre_SRE_Pattern_findall(PyObject *self, PyObject *const *args, Py_ssize_t nargs goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -548,7 +547,7 @@ _sre_SRE_Pattern_finditer(PyObject *self, PyTypeObject *cls, PyObject *const *ar goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -556,7 +555,7 @@ _sre_SRE_Pattern_finditer(PyObject *self, PyTypeObject *cls, PyObject *const *ar goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -627,7 +626,7 @@ _sre_SRE_Pattern_scanner(PyObject *self, PyTypeObject *cls, PyObject *const *arg goto skip_optional_pos; } if (args[1]) { - pos = _PyNumber_IndexAsSsize_t(args[1]); + pos = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (pos == -1 && PyErr_Occurred()) { goto exit; } @@ -635,7 +634,7 @@ _sre_SRE_Pattern_scanner(PyObject *self, PyTypeObject *cls, PyObject *const *arg goto skip_optional_pos; } } - endpos = _PyNumber_IndexAsSsize_t(args[2]); + endpos = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (endpos == -1 && PyErr_Occurred()) { goto exit; } @@ -704,7 +703,7 @@ _sre_SRE_Pattern_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!noptargs) { goto skip_optional_pos; } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -775,7 +774,7 @@ _sre_SRE_Pattern_sub(PyObject *self, PyTypeObject *cls, PyObject *const *args, P if (!noptargs) { goto skip_optional_pos; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } @@ -847,7 +846,7 @@ _sre_SRE_Pattern_subn(PyObject *self, PyTypeObject *cls, PyObject *const *args, if (!noptargs) { goto skip_optional_pos; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } @@ -1002,7 +1001,7 @@ _sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } code = args[2]; - groups = _PyNumber_IndexAsSsize_t(args[3]); + groups = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (groups == -1 && PyErr_Occurred()) { goto exit; } @@ -1469,4 +1468,4 @@ _sre_SRE_Scanner_search(PyObject *self, PyTypeObject *cls, PyObject *const *args #ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */ -/*[clinic end generated code: output=f02efdf20391b9fe input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e2d2203d848b073e input=a9049054013a1b77]*/ diff --git a/Modules/_struct.c b/Modules/_struct.c index fad026ac8a4652e..4a1fcf51e6cdb37 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -8,6 +8,7 @@ #endif #include "Python.h" +#include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_bytesobject.h" // _PyBytesWriter #include "pycore_lock.h" // _PyOnceFlag_CallOnce() #include "pycore_long.h" // _PyLong_AsByteArray() diff --git a/Modules/_testinternalcapi/clinic/test_lock.c.h b/Modules/_testinternalcapi/clinic/test_lock.c.h index 96594f1a7f15532..af727362016acea 100644 --- a/Modules/_testinternalcapi/clinic/test_lock.c.h +++ b/Modules/_testinternalcapi/clinic/test_lock.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_testinternalcapi_benchmark_locks__doc__, @@ -40,7 +39,7 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss if (!_PyArg_CheckPositional("benchmark_locks", nargs, 1, 8)) { goto exit; } - num_threads = _PyNumber_IndexAsSsize_t(args[0]); + num_threads = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (num_threads == -1 && PyErr_Occurred()) { goto exit; } @@ -75,14 +74,14 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss if (nargs < 6) { goto skip_optional; } - total_iters = _PyNumber_IndexAsSsize_t(args[5]); + total_iters = PyNumber_AsSsize_t(args[5], PyExc_OverflowError); if (total_iters == -1 && PyErr_Occurred()) { goto exit; } if (nargs < 7) { goto skip_optional; } - num_locks = _PyNumber_IndexAsSsize_t(args[6]); + num_locks = PyNumber_AsSsize_t(args[6], PyExc_OverflowError); if (num_locks == -1 && PyErr_Occurred()) { goto exit; } @@ -99,4 +98,4 @@ _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ss exit: return return_value; } -/*[clinic end generated code: output=ccc23e43bcf33f61 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=63f14f81a70cff81 input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/_zstdmodule.c.h b/Modules/_zstd/clinic/_zstdmodule.c.h index fcaaa5f7f58e998..848cbaa811acab2 100644 --- a/Modules/_zstd/clinic/_zstdmodule.c.h +++ b/Modules/_zstd/clinic/_zstdmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_zstd_train_dict__doc__, @@ -50,7 +49,7 @@ _zstd_train_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } samples_sizes = args[1]; - dict_size = _PyNumber_IndexAsSsize_t(args[2]); + dict_size = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (dict_size == -1 && PyErr_Occurred()) { goto exit; } @@ -115,7 +114,7 @@ _zstd_finalize_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } samples_sizes = args[2]; - dict_size = _PyNumber_IndexAsSsize_t(args[3]); + dict_size = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (dict_size == -1 && PyErr_Occurred()) { goto exit; } @@ -410,4 +409,4 @@ _zstd_set_parameter_types(PyObject *module, PyObject *const *args, Py_ssize_t na exit: return return_value; } -/*[clinic end generated code: output=f0e55d5d1823b104 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=039d808a7bc5ed21 input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/decompressor.c.h b/Modules/_zstd/clinic/decompressor.c.h index b2f7f2e64e3b9fd..3b62df3c4b5221c 100644 --- a/Modules/_zstd/clinic/decompressor.c.h +++ b/Modules/_zstd/clinic/decompressor.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_zstd_ZstdDecompressor_new__doc__, @@ -185,7 +184,7 @@ _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - max_length = _PyNumber_IndexAsSsize_t(args[1]); + max_length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (max_length == -1 && PyErr_Occurred()) { goto exit; } @@ -202,4 +201,4 @@ _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz } #define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, (setter)NULL, _zstd_ZstdDecompressor_unused_data__doc__}, -/*[clinic end generated code: output=709551c9dbe8b1b4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b54a300f4cb078ce input=a9049054013a1b77]*/ diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 64dacd1b8f1f616..2818740b154deb4 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -8,6 +8,7 @@ #endif #include "Python.h" +#include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_bytesobject.h" // _PyBytes_RepeatBuffer #include "pycore_call.h" // _PyObject_CallMethod() #include "pycore_ceval.h" // _PyEval_GetBuiltin() diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h index 2753d01bce59445..85fb1addf66e1fd 100644 --- a/Modules/clinic/_bisectmodule.c.h +++ b/Modules/clinic/_bisectmodule.c.h @@ -6,7 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_bisect_bisect_right__doc__, @@ -82,15 +82,15 @@ _bisect_bisect_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, goto skip_optional_pos; } if (args[2]) { - lo = _PyNumber_IndexAsSsize_t(args[2]); + lo = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (lo == -1 && PyErr_Occurred()) { goto exit; } - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; + } if (!--noptargs) { goto skip_optional_pos; } @@ -189,15 +189,15 @@ _bisect_insort_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, goto skip_optional_pos; } if (args[2]) { - lo = _PyNumber_IndexAsSsize_t(args[2]); + lo = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (lo == -1 && PyErr_Occurred()) { goto exit; } - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; + } if (!--noptargs) { goto skip_optional_pos; } @@ -295,15 +295,15 @@ _bisect_bisect_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[2]) { - lo = _PyNumber_IndexAsSsize_t(args[2]); + lo = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (lo == -1 && PyErr_Occurred()) { goto exit; } - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; + } if (!--noptargs) { goto skip_optional_pos; } @@ -402,15 +402,15 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[2]) { - lo = _PyNumber_IndexAsSsize_t(args[2]); + lo = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (lo == -1 && PyErr_Occurred()) { goto exit; } - if (lo < 0) { - PyErr_SetString(PyExc_ValueError, - "lo cannot be negative"); - goto exit; - } + if (lo < 0) { + PyErr_SetString(PyExc_ValueError, + "lo cannot be negative"); + goto exit; + } if (!--noptargs) { goto skip_optional_pos; } @@ -434,4 +434,4 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P exit: return return_value; } -/*[clinic end generated code: output=f536007e380782a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=69a0e522ae0afb3a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index 0b7c9d1d8c4b483..1ee07216ed8271e 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__, @@ -184,7 +183,7 @@ _bz2_BZ2Decompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_ if (!noptargs) { goto skip_optional_pos; } - max_length = _PyNumber_IndexAsSsize_t(args[1]); + max_length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (max_length == -1 && PyErr_Occurred()) { goto exit; } @@ -230,4 +229,4 @@ _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=f99baa40d2003347 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cb42718b421df534 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 56bbcd080327a7c..0a88690d53ccaf3 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -280,7 +279,7 @@ deque_rotate(PyObject *deque, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - n = _PyNumber_IndexAsSsize_t(args[0]); + n = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } @@ -426,7 +425,7 @@ deque_insert(PyObject *deque, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -673,7 +672,7 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) { goto exit; } - index = _PyNumber_IndexAsSsize_t(PyTuple_GET_ITEM(args, 0)); + index = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 0), PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -683,4 +682,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=892d242738402543 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=72e4bbe7244960be input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index c0f9a1201d2988a..17c3e1d8e9030ff 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -775,7 +774,7 @@ _elementtree_Element_insert(PyObject *self, PyObject *const *args, Py_ssize_t na if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -1466,4 +1465,4 @@ _elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=3d797b881a93154b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e592dddd4135fcbc input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index 283cefa8ce9a0da..eb23ef13e6a95bd 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UnsignedLong_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -140,15 +139,15 @@ _hashlib_HASHXOF_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; + } return_value = _hashlib_HASHXOF_digest_impl((HASHobject *)self, length); exit: @@ -210,15 +209,15 @@ _hashlib_HASHXOF_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nar if (!args) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; + } return_value = _hashlib_HASHXOF_hexdigest_impl((HASHobject *)self, length); exit: @@ -1961,4 +1960,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg #ifndef _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #define _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #endif /* !defined(_HASHLIB_OPENSSL_SHAKE_256_METHODDEF) */ -/*[clinic end generated code: output=39fc661240264f2c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=194fd4aecc4ffee6 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_interpqueuesmodule.c.h b/Modules/clinic/_interpqueuesmodule.c.h index 87821a6f92eaed4..04a611625e4e68e 100644 --- a/Modules/clinic/_interpqueuesmodule.c.h +++ b/Modules/clinic/_interpqueuesmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_interpqueues_create__doc__, @@ -68,7 +67,7 @@ _interpqueues_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - maxsize = _PyNumber_IndexAsSsize_t(args[0]); + maxsize = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (maxsize == -1 && PyErr_Occurred()) { goto exit; } @@ -755,4 +754,4 @@ _interpqueues__register_heap_types(PyObject *module, PyObject *const *args, Py_s exit: return return_value; } -/*[clinic end generated code: output=1857258e4bfdaa8a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=88e7e544642f0254 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_json.c.h b/Modules/clinic/_json.c.h index 98dd051df9a9f56..576d735b63cb7af 100644 --- a/Modules/clinic/_json.c.h +++ b/Modules/clinic/_json.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(py_scanstring__doc__, @@ -46,7 +45,7 @@ py_scanstring(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } pystr = args[0]; - end = _PyNumber_IndexAsSsize_t(args[1]); + end = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (end == -1 && PyErr_Occurred()) { goto exit; } @@ -274,4 +273,4 @@ encoder_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=3af1c5b3115d7887 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d988e409865fc8b0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index fcdd4262f8c126b..fc056448cc14600 100644 --- a/Modules/clinic/_lzmamodule.c.h +++ b/Modules/clinic/_lzmamodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__, @@ -142,7 +141,7 @@ _lzma_LZMADecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - max_length = _PyNumber_IndexAsSsize_t(args[1]); + max_length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (max_length == -1 && PyErr_Occurred()) { goto exit; } @@ -326,4 +325,4 @@ _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssiz return return_value; } -/*[clinic end generated code: output=f0cfa06ed4dc2718 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bbdf17b2f4fcbdf5 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index 2222916e2db7417..21766e4bb2bb727 100644 --- a/Modules/clinic/_operator.c.h +++ b/Modules/clinic/_operator.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_operator_truth__doc__, @@ -1445,7 +1444,7 @@ _operator_length_hint(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - default_value = _PyNumber_IndexAsSsize_t(args[1]); + default_value = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (default_value == -1 && PyErr_Occurred()) { goto exit; } @@ -1499,4 +1498,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na exit: return return_value; } -/*[clinic end generated code: output=29f6c3456e0ce9ea input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c1be0078a30c2173 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 18d03bf33c5c501..15276f9261354b7 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_Size_t_Converter() @@ -746,7 +745,7 @@ _ssl__SSLSocket_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyErr_SetString(PyExc_TypeError, "_ssl._SSLSocket.read requires 1 to 2 arguments"); goto exit; } - len = _PyNumber_IndexAsSsize_t(args[0]); + len = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (len == -1 && PyErr_Occurred()) { goto exit; } @@ -3365,4 +3364,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, (setter)NULL, _ssl_SSLSession_has_ticket__doc__}, -/*[clinic end generated code: output=4a16d0beb8beb146 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=80123f3849fe55ec input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index a790f094cde8658..fd5bcaae265a9c5 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(Struct__doc__, @@ -230,7 +229,7 @@ Struct_unpack_from(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb if (!noptargs) { goto skip_optional_pos; } - offset = _PyNumber_IndexAsSsize_t(args[1]); + offset = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -339,7 +338,7 @@ Struct_pack_into(PyObject *self, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("pack_into", "argument 1", "read-write bytes-like object", args[0]); goto exit; } - offset = _PyNumber_IndexAsSsize_t(args[1]); + offset = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -506,7 +505,7 @@ pack_into(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("pack_into", "argument 2", "read-write bytes-like object", args[1]); goto exit; } - offset = _PyNumber_IndexAsSsize_t(args[2]); + offset = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -637,7 +636,7 @@ unpack_from(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!noptargs) { goto skip_optional_pos; } - offset = _PyNumber_IndexAsSsize_t(args[2]); + offset = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -694,4 +693,4 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -/*[clinic end generated code: output=86b41e3c503d3a8b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4cee7b7d13e65104 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 086c1149fa3ebcd..d1121a7d4754598 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -1229,14 +1229,14 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - a = _PyNumber_IndexAsSsize_t(args[0]); + a = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (a == -1 && PyErr_Occurred()) { goto exit; } if (nargs < 2) { goto skip_optional; } - b = _PyNumber_IndexAsSsize_t(args[1]); + b = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (b == -1 && PyErr_Occurred()) { goto exit; } @@ -1249,15 +1249,15 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 4) { goto skip_optional; } - d = _PyNumber_IndexAsSsize_t(args[3]); + d = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (d == -1 && PyErr_Occurred()) { goto exit; } - if (d < 0) { - PyErr_SetString(PyExc_ValueError, - "d cannot be negative"); - goto exit; - } + if (d < 0) { + PyErr_SetString(PyExc_ValueError, + "d cannot be negative"); + goto exit; + } if (nargs < 5) { goto skip_optional; } @@ -1267,15 +1267,15 @@ py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 6) { goto skip_optional; } - f = _PyNumber_IndexAsSsize_t(args[5]); + f = PyNumber_AsSsize_t(args[5], PyExc_OverflowError); if (f == -1 && PyErr_Occurred()) { goto exit; } - if (f < 0) { - PyErr_SetString(PyExc_ValueError, - "f cannot be negative"); - goto exit; - } + if (f < 0) { + PyErr_SetString(PyExc_ValueError, + "f cannot be negative"); + goto exit; + } if (nargs < 7) { goto skip_optional; } @@ -5346,4 +5346,4 @@ vc_kwds_vectorcall(PyObject *type, PyObject *const *args, return return_value; } -/*[clinic end generated code: output=548c6ab1c73d4efe input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9fb766c3bad3159a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h index b37df53461f31de..947e77717676fd3 100644 --- a/Modules/clinic/_testclinic_depr.c.h +++ b/Modules/clinic/_testclinic_depr.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -2682,4 +2682,4 @@ depr_multi(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=66a4acb1e59782f4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1cba4df60f8a54f6 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_kwds.c.h b/Modules/clinic/_testclinic_kwds.c.h index 3aa9e6b8b7ac111..233c6ecd283821f 100644 --- a/Modules/clinic/_testclinic_kwds.c.h +++ b/Modules/clinic/_testclinic_kwds.c.h @@ -5,7 +5,7 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_UnsignedShort_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -189,4 +189,4 @@ kwds_with_pos_only_and_stararg(PyObject *module, PyObject *args, PyObject *kwarg return return_value; } -/*[clinic end generated code: output=6d4c88f4f460b223 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bdb39a6d91fb59bb input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_threadmodule.c.h b/Modules/clinic/_threadmodule.c.h index 34d2a6d4148814c..e9544761e40f599 100644 --- a/Modules/clinic/_threadmodule.c.h +++ b/Modules/clinic/_threadmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() static PyObject * @@ -1066,7 +1065,7 @@ _thread_stack_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - new_size = _PyNumber_IndexAsSsize_t(args[0]); + new_size = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (new_size == -1 && PyErr_Occurred()) { goto exit; } @@ -1264,4 +1263,4 @@ _thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb #endif /* !defined(_THREAD_SET_NAME_METHODDEF) */ #define _THREAD__THREADHANDLE_IDENT_GETSETDEF {"ident", (getter)_thread__ThreadHandle_ident_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=a3fd9715e7373886 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=760b0251ceee4ff5 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 842d42ae588dd59..73da05001b1657f 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -180,7 +179,7 @@ array_array_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - i = _PyNumber_IndexAsSsize_t(args[0]); + i = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (i == -1 && PyErr_Occurred()) { goto exit; } @@ -244,7 +243,7 @@ array_array_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - i = _PyNumber_IndexAsSsize_t(args[0]); + i = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (i == -1 && PyErr_Occurred()) { goto exit; } @@ -365,15 +364,15 @@ array_array_fromfile(PyObject *self, PyTypeObject *cls, PyObject *const *args, P goto exit; } f = args[0]; - n = _PyNumber_IndexAsSsize_t(args[1]); + n = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } - if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "n cannot be negative"); - goto exit; - } + if (n < 0) { + PyErr_SetString(PyExc_ValueError, + "n cannot be negative"); + goto exit; + } return_value = array_array_fromfile_impl((arrayobject *)self, cls, f, n); exit: @@ -698,4 +697,4 @@ array_arrayiterator___setstate__(PyObject *self, PyObject *state) return return_value; } -/*[clinic end generated code: output=f02e655f2f345382 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e6b6ba61c788414d input=a9049054013a1b77]*/ diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 31a9e4bb2abaaea..fb871651cdd522a 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_Size_t_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -1221,7 +1220,7 @@ binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb goto skip_optional_pos; } } - bytes_per_sep = _PyNumber_IndexAsSsize_t(args[2]); + bytes_per_sep = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (bytes_per_sep == -1 && PyErr_Occurred()) { goto exit; } @@ -1313,7 +1312,7 @@ binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb goto skip_optional_pos; } } - bytes_per_sep = _PyNumber_IndexAsSsize_t(args[2]); + bytes_per_sep = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (bytes_per_sep == -1 && PyErr_Occurred()) { goto exit; } @@ -1687,4 +1686,4 @@ binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj return return_value; } -/*[clinic end generated code: output=88565cb28608f74f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9a088b9a940341de input=a9049054013a1b77]*/ diff --git a/Modules/clinic/faulthandler.c.h b/Modules/clinic/faulthandler.c.h index c9029fcad404829..5ea56d6dbdc2af5 100644 --- a/Modules/clinic/faulthandler.c.h +++ b/Modules/clinic/faulthandler.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -91,7 +90,7 @@ faulthandler_dump_traceback_py(PyObject *module, PyObject *const *args, Py_ssize if (!noptargs) { goto skip_optional_kwonly; } - max_threads = _PyNumber_IndexAsSsize_t(args[2]); + max_threads = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (max_threads == -1 && PyErr_Occurred()) { goto exit; } @@ -254,7 +253,7 @@ faulthandler_py_enable(PyObject *module, PyObject *const *args, Py_ssize_t nargs if (!noptargs) { goto skip_optional_kwonly; } - max_threads = _PyNumber_IndexAsSsize_t(args[3]); + max_threads = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (max_threads == -1 && PyErr_Occurred()) { goto exit; } @@ -407,7 +406,7 @@ faulthandler_dump_traceback_later(PyObject *module, PyObject *const *args, Py_ss if (!noptargs) { goto skip_optional_kwonly; } - max_threads = _PyNumber_IndexAsSsize_t(args[4]); + max_threads = PyNumber_AsSsize_t(args[4], PyExc_OverflowError); if (max_threads == -1 && PyErr_Occurred()) { goto exit; } @@ -536,7 +535,7 @@ faulthandler_register_py(PyObject *module, PyObject *const *args, Py_ssize_t nar if (!noptargs) { goto skip_optional_kwonly; } - max_threads = _PyNumber_IndexAsSsize_t(args[4]); + max_threads = PyNumber_AsSsize_t(args[4], PyExc_OverflowError); if (max_threads == -1 && PyErr_Occurred()) { goto exit; } @@ -750,4 +749,4 @@ faulthandler__raise_exception(PyObject *module, PyObject *const *args, Py_ssize_ #ifndef FAULTHANDLER__RAISE_EXCEPTION_METHODDEF #define FAULTHANDLER__RAISE_EXCEPTION_METHODDEF #endif /* !defined(FAULTHANDLER__RAISE_EXCEPTION_METHODDEF) */ -/*[clinic end generated code: output=9bf8442c4c067e73 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c6d571cab841dff3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h index 5fd3edc2e2d5b02..f034b90f1d70547 100644 --- a/Modules/clinic/itertoolsmodule.c.h +++ b/Modules/clinic/itertoolsmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -80,7 +79,7 @@ batched_new_helper(PyTypeObject *type, PyObject *const *args, goto exit; } iterable = fastargs[0]; - n = _PyNumber_IndexAsSsize_t(fastargs[1]); + n = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } @@ -447,15 +446,15 @@ itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - n = _PyNumber_IndexAsSsize_t(args[1]); + n = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (n == -1 && PyErr_Occurred()) { goto exit; } - if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "n cannot be negative"); - goto exit; - } + if (n < 0) { + PyErr_SetString(PyExc_ValueError, + "n cannot be negative"); + goto exit; + } skip_optional: return_value = itertools_tee_impl(module, iterable, n); @@ -804,15 +803,15 @@ itertools_combinations_helper(PyTypeObject *type, PyObject *const *args, goto exit; } iterable = fastargs[0]; - r = _PyNumber_IndexAsSsize_t(fastargs[1]); + r = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (r == -1 && PyErr_Occurred()) { goto exit; } - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; + } return_value = itertools_combinations_impl(type, iterable, r); exit: @@ -847,15 +846,15 @@ itertools_combinations_vectorcall(PyObject *type, PyObject *const *args, NULL, kwnames); } iterable = args[0]; - r = _PyNumber_IndexAsSsize_t(args[1]); + r = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (r == -1 && PyErr_Occurred()) { goto exit; } - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; + } return_value = itertools_combinations_impl(_PyType_CAST(type), iterable, r); exit: @@ -933,15 +932,15 @@ itertools_combinations_with_replacement_helper(PyTypeObject *type, PyObject *con goto exit; } iterable = fastargs[0]; - r = _PyNumber_IndexAsSsize_t(fastargs[1]); + r = PyNumber_AsSsize_t(fastargs[1], PyExc_OverflowError); if (r == -1 && PyErr_Occurred()) { goto exit; } - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; + } return_value = itertools_combinations_with_replacement_impl(type, iterable, r); exit: @@ -976,15 +975,15 @@ itertools_combinations_with_replacement_vectorcall(PyObject *type, PyObject *con NULL, kwnames); } iterable = args[0]; - r = _PyNumber_IndexAsSsize_t(args[1]); + r = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (r == -1 && PyErr_Occurred()) { goto exit; } - if (r < 0) { - PyErr_SetString(PyExc_ValueError, - "r cannot be negative"); - goto exit; - } + if (r < 0) { + PyErr_SetString(PyExc_ValueError, + "r cannot be negative"); + goto exit; + } return_value = itertools_combinations_with_replacement_impl(_PyType_CAST(type), iterable, r); exit: @@ -1530,4 +1529,4 @@ zip_longest_next(PyObject *self) return return_value; } -/*[clinic end generated code: output=c4b61f8d7a14c9d7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9236985828bf107f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h index a3b44f6778596ac..75c48d587a6b006 100644 --- a/Modules/clinic/mmapmodule.c.h +++ b/Modules/clinic/mmapmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -330,7 +329,7 @@ mmap_mmap_resize(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t new_size; - new_size = _PyNumber_IndexAsSsize_t(arg); + new_size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (new_size == -1 && PyErr_Occurred()) { goto exit; } @@ -425,7 +424,7 @@ mmap_mmap_flush(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_posonly; } noptargs--; - offset = _PyNumber_IndexAsSsize_t(args[0]); + offset = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (offset == -1 && PyErr_Occurred()) { goto exit; } @@ -433,7 +432,7 @@ mmap_mmap_flush(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_posonly; } noptargs--; - size = _PyNumber_IndexAsSsize_t(args[1]); + size = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -475,7 +474,7 @@ mmap_mmap_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { goto exit; } - dist = _PyNumber_IndexAsSsize_t(args[0]); + dist = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (dist == -1 && PyErr_Occurred()) { goto exit; } @@ -568,15 +567,15 @@ mmap_mmap_move(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("move", nargs, 3, 3)) { goto exit; } - dest = _PyNumber_IndexAsSsize_t(args[0]); + dest = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (dest == -1 && PyErr_Occurred()) { goto exit; } - src = _PyNumber_IndexAsSsize_t(args[1]); + src = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (src == -1 && PyErr_Occurred()) { goto exit; } - cnt = _PyNumber_IndexAsSsize_t(args[2]); + cnt = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (cnt == -1 && PyErr_Occurred()) { goto exit; } @@ -728,11 +727,11 @@ mmap_mmap__protect(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } } } - start = _PyNumber_IndexAsSsize_t(args[1]); + start = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (start == -1 && PyErr_Occurred()) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[2]); + length = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -778,7 +777,7 @@ mmap_mmap_madvise(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 2) { goto skip_optional; } - start = _PyNumber_IndexAsSsize_t(args[1]); + start = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (start == -1 && PyErr_Occurred()) { goto exit; } @@ -887,4 +886,4 @@ mmap_ass_subscript(PyObject *self, PyObject *item, PyObject *value) #ifndef MMAP_MMAP_MADVISE_METHODDEF #define MMAP_MMAP_MADVISE_METHODDEF #endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */ -/*[clinic end generated code: output=cc1d65746cfc1580 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=affe2a69874a3cb1 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 69a06caabb2eaa9..e05333e6f428ad2 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -5706,7 +5705,7 @@ os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (pid == (pid_t)(-1) && PyErr_Occurred()) { goto exit; } - signal = _PyNumber_IndexAsSsize_t(args[1]); + signal = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (signal == -1 && PyErr_Occurred()) { goto exit; } @@ -7843,7 +7842,7 @@ os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (fd == -1 && PyErr_Occurred()) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[1]); + length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -7991,7 +7990,7 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (fd == -1 && PyErr_Occurred()) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[1]); + length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -8302,15 +8301,15 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!_Py_Off_t_Converter(args[2], &offset)) { goto exit; } - count = _PyNumber_IndexAsSsize_t(args[3]); + count = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } if (!noptargs) { goto skip_optional_pos; } @@ -8405,15 +8404,15 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } offobj = args[2]; - count = _PyNumber_IndexAsSsize_t(args[3]); + count = PyNumber_AsSsize_t(args[3], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); exit: @@ -8890,15 +8889,15 @@ os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py if (dst == -1 && PyErr_Occurred()) { goto exit; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } if (!noptargs) { goto skip_optional_pos; } @@ -9005,15 +9004,15 @@ os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k if (dst == -1 && PyErr_Occurred()) { goto exit; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } - if (count < 0) { - PyErr_SetString(PyExc_ValueError, - "count cannot be negative"); - goto exit; - } + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } if (!noptargs) { goto skip_optional_pos; } @@ -11463,15 +11462,15 @@ os_urandom(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t size; - size = _PyNumber_IndexAsSsize_t(arg); + size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } - if (size < 0) { - PyErr_SetString(PyExc_ValueError, - "size cannot be negative"); - goto exit; - } + if (size < 0) { + PyErr_SetString(PyExc_ValueError, + "size cannot be negative"); + goto exit; + } return_value = os_urandom_impl(module, size); exit: @@ -12591,7 +12590,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject if (!args) { goto exit; } - size = _PyNumber_IndexAsSsize_t(args[0]); + size = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -13691,4 +13690,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=b44461fd2db79d32 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4e7920ecf053a231 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha3module.c.h b/Modules/clinic/sha3module.c.h index aebe28235fabc50..c78ca15fb58afd4 100644 --- a/Modules/clinic/sha3module.c.h +++ b/Modules/clinic/sha3module.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(py_sha3_new__doc__, @@ -224,15 +223,15 @@ _sha3_shake_128_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, if (!args) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; + } return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length); exit: @@ -290,18 +289,18 @@ _sha3_shake_128_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t narg if (!args) { goto exit; } - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; + } return_value = _sha3_shake_128_hexdigest_impl((SHA3object *)self, length); exit: return return_value; } -/*[clinic end generated code: output=5a6dd6c2d3d0b271 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4215537b85d00a40 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index 653d26012106365..19593c6871e80e1 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_long.h" // _PyLong_UInt16_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -452,7 +451,7 @@ _socket_socket_recv(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recv", nargs, 1, 2)) { goto exit; } - recvlen = _PyNumber_IndexAsSsize_t(args[0]); + recvlen = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (recvlen == -1 && PyErr_Occurred()) { goto exit; } @@ -539,7 +538,7 @@ _socket_socket_recv_into(PyObject *s, PyObject *const *args, Py_ssize_t nargs, P goto skip_optional_pos; } if (args[1]) { - recvlen = _PyNumber_IndexAsSsize_t(args[1]); + recvlen = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (recvlen == -1 && PyErr_Occurred()) { goto exit; } @@ -591,7 +590,7 @@ _socket_socket_recvfrom(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recvfrom", nargs, 1, 2)) { goto exit; } - recvlen = _PyNumber_IndexAsSsize_t(args[0]); + recvlen = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (recvlen == -1 && PyErr_Occurred()) { goto exit; } @@ -679,7 +678,7 @@ _socket_socket_recvfrom_into(PyObject *s, PyObject *const *args, Py_ssize_t narg goto skip_optional_pos; } if (args[1]) { - recvlen = _PyNumber_IndexAsSsize_t(args[1]); + recvlen = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (recvlen == -1 && PyErr_Occurred()) { goto exit; } @@ -756,14 +755,14 @@ _socket_socket_recvmsg(PyObject *s, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("recvmsg", nargs, 1, 3)) { goto exit; } - bufsize = _PyNumber_IndexAsSsize_t(args[0]); + bufsize = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (bufsize == -1 && PyErr_Occurred()) { goto exit; } if (nargs < 2) { goto skip_optional; } - ancbufsize = _PyNumber_IndexAsSsize_t(args[1]); + ancbufsize = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (ancbufsize == -1 && PyErr_Occurred()) { goto exit; } @@ -842,7 +841,7 @@ _socket_socket_recvmsg_into(PyObject *s, PyObject *const *args, Py_ssize_t nargs if (nargs < 2) { goto skip_optional; } - ancbufsize = _PyNumber_IndexAsSsize_t(args[1]); + ancbufsize = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (ancbufsize == -1 && PyErr_Occurred()) { goto exit; } @@ -2188,7 +2187,7 @@ _socket_CMSG_LEN(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t length; - length = _PyNumber_IndexAsSsize_t(arg); + length = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -2226,7 +2225,7 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t length; - length = _PyNumber_IndexAsSsize_t(arg); + length = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -2377,4 +2376,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=3ea9ab7ef20ed0d8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cd947955f8f9214c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/unicodedata.c.h b/Modules/clinic/unicodedata.c.h index 7a0291121ef766a..812010af04ee8d6 100644 --- a/Modules/clinic/unicodedata.c.h +++ b/Modules/clinic/unicodedata.c.h @@ -2,7 +2,6 @@ preserve [clinic start generated code]*/ -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, @@ -657,14 +656,14 @@ unicodedata_iter_graphemes(PyObject *module, PyObject *const *args, Py_ssize_t n if (nargs < 2) { goto skip_optional; } - start = _PyNumber_IndexAsSsize_t(args[1]); + start = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (start == -1 && PyErr_Occurred()) { goto exit; } if (nargs < 3) { goto skip_optional; } - end = _PyNumber_IndexAsSsize_t(args[2]); + end = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (end == -1 && PyErr_Occurred()) { goto exit; } @@ -818,4 +817,4 @@ unicodedata_extended_pictographic(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=03ace54ed1775071 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=13549f0196144c13 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 3fe8430643bae52..13db4df1eaf8b20 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(zlib_compress__doc__, @@ -178,15 +177,15 @@ zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj goto skip_optional_pos; } } - bufsize = _PyNumber_IndexAsSsize_t(args[2]); + bufsize = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (bufsize == -1 && PyErr_Occurred()) { goto exit; } - if (bufsize < 0) { - PyErr_SetString(PyExc_ValueError, - "bufsize cannot be negative"); - goto exit; - } + if (bufsize < 0) { + PyErr_SetString(PyExc_ValueError, + "bufsize cannot be negative"); + goto exit; + } skip_optional_pos: return_value = zlib_decompress_impl(module, &data, wbits, bufsize); @@ -540,15 +539,15 @@ zlib_Decompress_decompress(PyObject *self, PyTypeObject *cls, PyObject *const *a if (!noptargs) { goto skip_optional_pos; } - max_length = _PyNumber_IndexAsSsize_t(args[1]); + max_length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (max_length == -1 && PyErr_Occurred()) { goto exit; } - if (max_length < 0) { - PyErr_SetString(PyExc_ValueError, - "max_length cannot be negative"); - goto exit; - } + if (max_length < 0) { + PyErr_SetString(PyExc_ValueError, + "max_length cannot be negative"); + goto exit; + } skip_optional_pos: return_value = zlib_Decompress_decompress_impl((compobject *)self, cls, &data, max_length); @@ -808,7 +807,7 @@ zlib_Decompress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, if (nargs < 1) { goto skip_optional; } - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } @@ -894,7 +893,7 @@ zlib__ZlibDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz if (!noptargs) { goto skip_optional_pos; } - max_length = _PyNumber_IndexAsSsize_t(args[1]); + max_length = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (max_length == -1 && PyErr_Occurred()) { goto exit; } @@ -1306,4 +1305,4 @@ zlib_crc32_combine(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=0649f957a763763f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e7a387933dc0b242 input=a9049054013a1b77]*/ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c012958d2b5f4c7..f8de321d58eb7ae 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -586,13 +586,13 @@ mmap_gfind_lock_held(mmap_object *self, Py_buffer *view, PyObject *start_obj, CHECK_VALID(NULL); if (start_obj != Py_None) { - start = _PyNumber_IndexAsSsize_t(start_obj); + start = PyNumber_AsSsize_t(start_obj, PyExc_OverflowError); if (start == -1 && PyErr_Occurred()) { return NULL; } if (end_obj != Py_None) { - end = _PyNumber_IndexAsSsize_t(end_obj); + end = PyNumber_AsSsize_t(end_obj, PyExc_OverflowError); if (end == -1 && PyErr_Occurred()) { return NULL; } @@ -1366,7 +1366,7 @@ mmap_mmap_madvise_impl(mmap_object *self, int option, Py_ssize_t start, if (length_obj == Py_None) { length = self->size; } else { - length = _PyNumber_IndexAsSsize_t(length_obj); + length = PyNumber_AsSsize_t(length_obj, PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { return NULL; } diff --git a/Objects/abstract.c b/Objects/abstract.c index f041e0e30ff28b1..cce16321c494c18 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1473,67 +1473,60 @@ PyNumber_Index(PyObject *item) return result; } +/* Return an error on Overflow only if err is not NULL*/ + Py_ssize_t -_PyNumber_IndexAsSsize_t(PyObject *item) +PyNumber_AsSsize_t(PyObject *item, PyObject *err) { - if (item != NULL && PyLong_Check(item)) { - /* Fast path: no new reference is needed. */ - return PyLong_AsSsize_t(item); + Py_ssize_t result; + PyObject *runerr; + if (item != NULL && PyLong_Check(item) + && _PyLong_IsCompact((PyLongObject *)item)) + { + /* Fast path: a compact int always fits, no new reference needed. */ + return _PyLong_CompactValue((PyLongObject *)item); } PyObject *value = _PyNumber_Index(item); - if (value == NULL) { + if (value == NULL) return -1; - } - Py_ssize_t result = PyLong_AsSsize_t(value); - Py_DECREF(value); - return result; -} -/* Convert the int 'value', the index of 'item', to a Py_ssize_t. - On overflow, clip the result if err is NULL, otherwise raise err. */ -static Py_ssize_t -index_as_ssize_t(PyObject *item, PyObject *value, PyObject *err) -{ - assert(PyLong_Check(value)); - Py_ssize_t result = PyLong_AsSsize_t(value); - if (result != -1) { - return result; - } + /* We're done if PyLong_AsSsize_t() returns without error. */ + result = PyLong_AsSsize_t(value); + if (result != -1) + goto finish; PyThreadState *tstate = _PyThreadState_GET(); - PyObject *runerr = _PyErr_Occurred(tstate); - /* Only OverflowError is handled differently. */ - if (!runerr || !PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { - return result; + runerr = _PyErr_Occurred(tstate); + if (!runerr) { + goto finish; + } + + /* Error handling code -- only manage OverflowError differently */ + if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { + goto finish; } _PyErr_Clear(tstate); + /* If no error-handling desired then the default clipping + is sufficient. */ if (!err) { - /* No error handling desired: clip to the Py_ssize_t range. */ - return _PyLong_IsNegative((PyLongObject *)value) - ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX; - } - /* Otherwise replace the error with caller's error object. */ - _PyErr_Format(tstate, err, - "cannot fit '%.200s' into an index-sized integer", - Py_TYPE(item)->tp_name); - return -1; -} - -/* Return an error on Overflow only if err is not NULL*/ - -Py_ssize_t -PyNumber_AsSsize_t(PyObject *item, PyObject *err) -{ - if (item != NULL && PyLong_Check(item)) { - /* Fast path: no new reference is needed. */ - return index_as_ssize_t(item, item, err); + assert(PyLong_Check(value)); + /* Whether or not it is less than or equal to + zero is determined by the sign of ob_size + */ + if (_PyLong_IsNegative((PyLongObject *)value)) + result = PY_SSIZE_T_MIN; + else + result = PY_SSIZE_T_MAX; } - PyObject *value = _PyNumber_Index(item); - if (value == NULL) { - return -1; + else { + /* Otherwise replace the error with caller's error object. */ + _PyErr_Format(tstate, err, + "cannot fit '%.200s' into an index-sized integer", + Py_TYPE(item)->tp_name); } - Py_ssize_t result = index_as_ssize_t(item, value, err); + + finish: Py_DECREF(value); return result; } diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 69f5dbd1168d05e..696424ae9a940b1 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -5,7 +5,6 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_runtime.h" // _Py_SINGLETON() @@ -778,7 +777,7 @@ bytearray_resize(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t size; - size = _PyNumber_IndexAsSsize_t(arg); + size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { goto exit; } @@ -1021,7 +1020,7 @@ bytearray_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj if (!noptargs) { goto skip_optional_pos; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } @@ -1114,7 +1113,7 @@ bytearray_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -1266,7 +1265,7 @@ bytearray_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -1330,7 +1329,7 @@ bytearray_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -1434,7 +1433,7 @@ bytearray_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -1890,7 +1889,7 @@ bytearray_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + bytes_per_sep = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (bytes_per_sep == -1 && PyErr_Occurred()) { goto exit; } @@ -1981,4 +1980,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=983dab0d45700f6c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7661925edf2428d1 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index f830f36a18b7dc3..6141b0de5f23c92 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -98,7 +97,7 @@ bytes_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *k goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -261,7 +260,7 @@ bytes_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -848,7 +847,7 @@ bytes_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (!noptargs) { goto skip_optional_pos; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } @@ -1309,7 +1308,7 @@ bytes_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn goto skip_optional_pos; } } - bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + bytes_per_sep = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (bytes_per_sep == -1 && PyErr_Occurred()) { goto exit; } @@ -1465,4 +1464,4 @@ bytes_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=16e2d748f31ad751 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=170e9b6af7c1d571 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index a9b1db1d89a5e79..91d012d34a8dfb0 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -92,7 +91,7 @@ list_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -225,7 +224,7 @@ list_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - index = _PyNumber_IndexAsSsize_t(args[0]); + index = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (index == -1 && PyErr_Occurred()) { goto exit; } @@ -512,4 +511,4 @@ list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl((PyListObject *)self); } -/*[clinic end generated code: output=3971f91f7d5bb703 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b9a399d4c7d577a4 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index 29debb939a8c584..be6b6ff97c40a9c 100644 --- a/Objects/clinic/longobject.c.h +++ b/Objects/clinic/longobject.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -330,15 +329,15 @@ int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * goto skip_optional_pos; } if (args[0]) { - length = _PyNumber_IndexAsSsize_t(args[0]); + length = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { goto exit; } - if (length < 0) { - PyErr_SetString(PyExc_ValueError, - "length cannot be negative"); - goto exit; - } + if (length < 0) { + PyErr_SetString(PyExc_ValueError, + "length cannot be negative"); + goto exit; + } if (!--noptargs) { goto skip_optional_pos; } @@ -485,4 +484,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) { return int_is_integer_impl(self); } -/*[clinic end generated code: output=e835437267a7c4d2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=70dfcada7cc3394e input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index 8261a253198ed06..312b8b9982af8db 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -502,7 +501,7 @@ memoryview_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - bytes_per_sep = _PyNumber_IndexAsSsize_t(args[1]); + bytes_per_sep = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (bytes_per_sep == -1 && PyErr_Occurred()) { goto exit; } @@ -580,4 +579,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=7e4568eeb9f13257 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8e067b740de80373 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 7cc7415090e1fe0..c759eeb9c05481b 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -113,7 +112,7 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -749,7 +748,7 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -961,7 +960,7 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObjec if (!noptargs) { goto skip_optional_pos; } - count = _PyNumber_IndexAsSsize_t(args[2]); + count = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { goto exit; } @@ -1175,7 +1174,7 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -1270,7 +1269,7 @@ unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -1388,7 +1387,7 @@ unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject goto skip_optional_pos; } } - maxsplit = _PyNumber_IndexAsSsize_t(args[1]); + maxsplit = PyNumber_AsSsize_t(args[1], PyExc_OverflowError); if (maxsplit == -1 && PyErr_Occurred()) { goto exit; } @@ -1598,7 +1597,7 @@ unicode_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - width = _PyNumber_IndexAsSsize_t(arg); + width = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -1841,4 +1840,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=6d38f779d89f1fcc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=832b5d1622ff6657 input=a9049054013a1b77]*/ diff --git a/Objects/longobject.c b/Objects/longobject.c index b48328efa2f1b7c..fa0627f223d920d 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3,6 +3,7 @@ /* XXX The functional organization of this file is terrible */ #include "Python.h" +#include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_bitutils.h" // _Py_popcount32() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_call.h" // _PyObject_MakeTpCall diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 5da9dad3cd53fc3..5f3699a4dc9ada9 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -2172,7 +2172,7 @@ pack_single(PyMemoryViewObject *self, char *ptr, PyObject *item, const char *fmt /* ssize_t and size_t */ case 'n': - zd = _PyNumber_IndexAsSsize_t(item); + zd = PyNumber_AsSsize_t(item, PyExc_OverflowError); if (zd == -1 && PyErr_Occurred()) goto err_occurred; CHECK_RELEASED_INT_AGAIN(self); diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index da1eaf7feead6e0..9748cd53bd978ed 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(stringlib_expandtabs__doc__, @@ -101,7 +100,7 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -163,7 +162,7 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -225,7 +224,7 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { goto exit; } - width = _PyNumber_IndexAsSsize_t(args[0]); + width = PyNumber_AsSsize_t(args[0], PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -283,7 +282,7 @@ stringlib_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - width = _PyNumber_IndexAsSsize_t(arg); + width = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (width == -1 && PyErr_Occurred()) { goto exit; } @@ -292,4 +291,4 @@ stringlib_zfill(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=75c521d89a08ddf4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=73e46317dbfbb715 input=a9049054013a1b77]*/ diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index 6333d036f3affff..b5aa830d0c7486f 100644 --- a/Python/clinic/_warnings.c.h +++ b/Python/clinic/_warnings.c.h @@ -6,7 +6,6 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_abstract.h" // _PyNumber_IndexAsSsize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(warnings_acquire_lock__doc__, @@ -126,7 +125,7 @@ warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec } } if (args[2]) { - stacklevel = _PyNumber_IndexAsSsize_t(args[2]); + stacklevel = PyNumber_AsSsize_t(args[2], PyExc_OverflowError); if (stacklevel == -1 && PyErr_Occurred()) { goto exit; } @@ -276,4 +275,4 @@ warnings_filters_mutated_lock_held(PyObject *module, PyObject *Py_UNUSED(ignored { return warnings_filters_mutated_lock_held_impl(module); } -/*[clinic end generated code: output=65b9b5e4aca87788 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=739833b3c7c383d7 input=a9049054013a1b77]*/ diff --git a/Python/getargs.c b/Python/getargs.c index b0d1a2ea46764c1..4c3d44dc516e809 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -831,7 +831,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, case 'n': /* Py_ssize_t */ { Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *); - Py_ssize_t ival = _PyNumber_IndexAsSsize_t(arg); + Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (ival == -1 && PyErr_Occurred()) RETURN_ERR_OCCURRED; *p = ival; diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index b1dab4aefd0a7fd..390c3b49c64ae1e 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -468,31 +468,11 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st argname=argname, ) if self.format_unit == 'n': - if not limited_capi: - self.add_include('pycore_abstract.h', - '_PyNumber_IndexAsSsize_t()') - return self.format_code(""" - {paramname} = _PyNumber_IndexAsSsize_t({argname}); - if ({paramname} == -1 && PyErr_Occurred()) {{{{ - goto exit; - }}}}{non_negative_check} - """, - argname=argname, - non_negative_check=non_negative_check, - ) return self.format_code(""" - {{{{ - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index({argname}); - if (iobj != NULL) {{{{ - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - }}}} - if (ival == -1 && PyErr_Occurred()) {{{{ - goto exit; - }}}} - {paramname} = ival;{non_negative_check} - }}}} + {paramname} = PyNumber_AsSsize_t({argname}, PyExc_OverflowError); + if ({paramname} == -1 && PyErr_Occurred()) {{{{ + goto exit; + }}}}{non_negative_check} """, argname=argname, non_negative_check=non_negative_check, From 4feebbd7cf991245217ecb1d77e333be1e32fe0e Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 1 Dec 2026 00:31:30 +0100 Subject: [PATCH 4/4] Add NEWS entry --- .../2026-12-01-00-00-00.gh-issue-162749.aS9zQk.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-12-01-00-00-00.gh-issue-162749.aS9zQk.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-12-01-00-00-00.gh-issue-162749.aS9zQk.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-12-01-00-00-00.gh-issue-162749.aS9zQk.rst new file mode 100644 index 000000000000000..d67931fe86fc33c --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-12-01-00-00-00.gh-issue-162749.aS9zQk.rst @@ -0,0 +1,4 @@ +Speed up conversion of :class:`int` arguments to ``Py_ssize_t`` in functions +using Argument Clinic or the ``n`` format unit of :c:func:`PyArg_ParseTuple`. +When the value does not fit, the :exc:`OverflowError` message is now +``cannot fit 'int' into an index-sized integer``.