diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 988294379ff6ec0..c17cf44f0f3af4e 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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[1], PyExc_OverflowError); + if (b == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -1688,23 +1672,15 @@ 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; + 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 (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_AsSsize_t(args[5], PyExc_OverflowError); + 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=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/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``. diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index 7a3c4bba9fc2090..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -121,23 +120,15 @@ 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; + 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; } - } skip_optional: return_value = CDataType_from_buffer_impl(type, cls, obj, offset); @@ -179,23 +170,15 @@ 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; + 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; } - } skip_optional: return_value = CDataType_from_buffer_copy_impl(type, cls, &buffer, offset); @@ -938,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=5d9dd4bbae13cfca 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 82cb08ff00dfb03..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -562,17 +561,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_AsSsize_t(args[1], PyExc_OverflowError); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(obj); @@ -684,17 +675,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_AsSsize_t(args[1], PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(obj); return_value = _ctypes_resize_impl(module, obj, size); @@ -793,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=615c411ddc01d0a4 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 355e69803b1de2c..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -70,41 +69,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_AsSsize_t(fastargs[2], PyExc_OverflowError); + 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_AsSsize_t(fastargs[3], PyExc_OverflowError); + 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_AsSsize_t(fastargs[4], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } _internal_use = PyObject_IsTrue(fastargs[5]); if (_internal_use < 0) { @@ -126,4 +101,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=f0e5a4d1e8236428 input=a9049054013a1b77]*/ diff --git a/Modules/_decimal/clinic/_decimal.c.h b/Modules/_decimal/clinic/_decimal.c.h index 8aa362b5258d7df..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_decimal_Context_Etiny__doc__, @@ -70,17 +69,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_AsSsize_t(arg, PyExc_OverflowError); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setprec_impl(self, x); @@ -109,17 +100,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_AsSsize_t(arg, PyExc_OverflowError); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setemin_impl(self, x); @@ -148,17 +131,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_AsSsize_t(arg, PyExc_OverflowError); + if (x == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_Context__unsafe_setemax_impl(self, x); @@ -349,17 +324,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_AsSsize_t(arg, PyExc_OverflowError); + if (bits == -1 && PyErr_Occurred()) { + goto exit; } return_value = _decimal_IEEEContext_impl(module, bits); @@ -6330,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=f9ddc00f5a7335c4 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 0cedf4a9948e9da..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_Index() +#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,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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(fastargs[1], PyExc_OverflowError); + 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_AsSsize_t(fastargs[1], PyExc_OverflowError); + 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_AsSsize_t(PyTuple_GET_ITEM(args, 2), PyExc_OverflowError); + 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_AsSsize_t(fastargs[1], PyExc_OverflowError); + 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=901ead01a5201538 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index e48d71397367daf..c9258d2dc1f13f9 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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[0], PyExc_OverflowError); + 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=a721dad172febd8a input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index c7adafe1580ea9a..a5980809baedcaa 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_AsSsize_t(args[0], PyExc_OverflowError); + 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=17a7966b93718c00 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index bda87205e6bb718..0660b8514431a50 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_AsSsize_t(args[0], PyExc_OverflowError); + 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=0540255c876577ea input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 954fee5cd2d4bfb..e5bdf5e8e128647 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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(arg, PyExc_OverflowError); + 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=65e59d4741f3931e input=a9049054013a1b77]*/ diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index 9e6c91d09f59a41..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_sre_getcodesize__doc__, @@ -225,33 +224,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +304,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +386,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +465,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + if (endpos == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_findall_impl((PatternObject *)self, string, pos, endpos); @@ -612,33 +547,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +626,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +703,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _sre_SRE_Pattern_split_impl((PatternObject *)self, string, maxsplit); @@ -879,17 +774,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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +846,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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +1001,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_AsSsize_t(args[3], PyExc_OverflowError); + if (groups == -1 && PyErr_Occurred()) { + goto exit; } if (!PyDict_Check(args[4])) { _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]); @@ -1597,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=2e6c222a2eb0875e 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 6e989a777ac7f01..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_testinternalcapi_benchmark_locks__doc__, @@ -40,17 +39,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_AsSsize_t(args[0], PyExc_OverflowError); + if (num_threads == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -83,32 +74,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_AsSsize_t(args[5], PyExc_OverflowError); + 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_AsSsize_t(args[6], PyExc_OverflowError); + if (num_locks == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 8) { goto skip_optional; @@ -123,4 +98,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=63f14f81a70cff81 input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/_zstdmodule.c.h b/Modules/_zstd/clinic/_zstdmodule.c.h index feb0563b3228381..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_zstd_train_dict__doc__, @@ -50,17 +49,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_AsSsize_t(args[2], PyExc_OverflowError); + if (dict_size == -1 && PyErr_Occurred()) { + goto exit; } return_value = _zstd_train_dict_impl(module, samples_bytes, samples_sizes, dict_size); @@ -123,17 +114,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_AsSsize_t(args[3], PyExc_OverflowError); + if (dict_size == -1 && PyErr_Occurred()) { + goto exit; } compression_level = PyLong_AsInt(args[4]); if (compression_level == -1 && PyErr_Occurred()) { @@ -426,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=a6ad0ab41c507911 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 83431363621ad64..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_zstd_ZstdDecompressor_new__doc__, @@ -185,17 +184,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_AsSsize_t(args[1], PyExc_OverflowError); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _zstd_ZstdDecompressor_decompress_impl((ZstdDecompressor *)self, &data, max_length); @@ -210,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=91b84afb07b1188c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b54a300f4cb078ce input=a9049054013a1b77]*/ diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 31d19f7c178af85..47905f1c3b6e5bb 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 454131faf4112b7..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_Index() +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_bisect_bisect_right__doc__, @@ -82,23 +82,15 @@ _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; + 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 (!--noptargs) { goto skip_optional_pos; } @@ -197,23 +189,15 @@ _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; + 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 (!--noptargs) { goto skip_optional_pos; } @@ -311,23 +295,15 @@ _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; + 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 (!--noptargs) { goto skip_optional_pos; } @@ -426,23 +402,15 @@ _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; + 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 (!--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=69a0e522ae0afb3a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index 30f2c7965e73ae1..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_Index() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__, @@ -184,17 +183,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_AsSsize_t(args[1], PyExc_OverflowError); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _bz2_BZ2Decompressor_decompress_impl((BZ2Decompressor *)self, &data, max_length); @@ -238,4 +229,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=cb42718b421df534 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 2966d68aa3813b5..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -280,17 +279,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_AsSsize_t(args[0], PyExc_OverflowError); + if (n == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(deque); @@ -434,17 +425,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_AsSsize_t(args[0], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } value = args[1]; Py_BEGIN_CRITICAL_SECTION(deque); @@ -689,17 +672,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_AsSsize_t(PyTuple_GET_ITEM(args, 0), PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } doc = PyTuple_GET_ITEM(args, 1); return_value = tuplegetter_new_impl(type, index, doc); @@ -707,4 +682,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=72e4bbe7244960be input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index 452b56c3272a7e3..7aca3834be47cb2 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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -772,17 +771,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_AsSsize_t(args[0], PyExc_OverflowError); + 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]); @@ -1471,4 +1462,4 @@ _elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=fc56f4c3b3331182 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a4dd3611779242c3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index b99545b0eb33471..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_Index() #include "pycore_long.h" // _PyLong_UnsignedLong_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -140,23 +139,15 @@ _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; + 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; } - } return_value = _hashlib_HASHXOF_digest_impl((HASHobject *)self, length); exit: @@ -218,23 +209,15 @@ _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; + 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; } - } return_value = _hashlib_HASHXOF_hexdigest_impl((HASHobject *)self, length); exit: @@ -1977,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=608e8ac9483c9173 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 6f27ea73b8866fe..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(_interpqueues_create__doc__, @@ -68,17 +67,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_AsSsize_t(args[0], PyExc_OverflowError); + if (maxsize == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -763,4 +754,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=88e7e544642f0254 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_json.c.h b/Modules/clinic/_json.c.h index 79315078d44582d..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(py_scanstring__doc__, @@ -46,17 +45,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_AsSsize_t(args[1], PyExc_OverflowError); + if (end == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -282,4 +273,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=d988e409865fc8b0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index bba107e8f806daf..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_Index() #include "pycore_modsupport.h" // _PyArg_BadArgument() PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__, @@ -142,17 +141,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_AsSsize_t(args[1], PyExc_OverflowError); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = _lzma_LZMADecompressor_decompress_impl((Decompressor *)self, &data, max_length); @@ -334,4 +325,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=bbdf17b2f4fcbdf5 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index 0bd7314bf14f070..f861c3b460ea665 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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_tuple.h" // _PyTuple_ITEMS() @@ -1446,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_AsSsize_t(args[1], PyExc_OverflowError); + if (default_value == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: _return_value = _operator_length_hint_impl(module, obj, default_value); @@ -1604,4 +1595,4 @@ attrgetter_type_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=a009773fbb99d7f3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5190f27b9386eccb input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 98a929b33def825..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_Index() #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 +745,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_AsSsize_t(args[0], PyExc_OverflowError); + if (len == -1 && PyErr_Occurred()) { + goto exit; } if (nargs >= 2) { if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { @@ -3373,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=fb3476aa2f825376 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 22fec68a4e9ee63..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(Struct__doc__, @@ -230,17 +229,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_AsSsize_t(args[1], PyExc_OverflowError); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = Struct_unpack_from_impl((PyStructObject *)self, &buffer, offset); @@ -347,17 +338,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_AsSsize_t(args[1], PyExc_OverflowError); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } values = args + 2; values_length = nargs - 2; @@ -522,17 +505,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_AsSsize_t(args[2], PyExc_OverflowError); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } values = args + 3; values_length = nargs - 3; @@ -661,17 +636,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_AsSsize_t(args[2], PyExc_OverflowError); + if (offset == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unpack_from_impl(module, s_object, &buffer, offset); @@ -726,4 +693,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=4cee7b7d13e65104 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 4df9d476756892c..c74f813842491c8 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" // _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,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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[1], PyExc_OverflowError); + if (b == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -1265,23 +1249,15 @@ 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; + 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 (nargs < 5) { goto skip_optional; } @@ -1291,23 +1267,15 @@ 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; + 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 (nargs < 7) { goto skip_optional; } @@ -5375,4 +5343,4 @@ vc_kwds_vectorcall(PyObject *type, PyObject *const *args, return return_value; } -/*[clinic end generated code: output=42857d626df6e2ee input=a9049054013a1b77]*/ +/*[clinic end generated code: output=12fa7bb7ca517b40 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h index 1652e9223e54f94..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_Index() +#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=abe0af8d8c637c36 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 9cf28a550c2ace1..f4b041d4d3bc3ca 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" // _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() @@ -173,4 +173,4 @@ kwds_with_pos_only_and_stararg(PyObject *module, PyObject *args, PyObject *kwarg return return_value; } -/*[clinic end generated code: output=43ce1e8574f2a904 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3796501afb8d2516 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_threadmodule.c.h b/Modules/clinic/_threadmodule.c.h index 090fdee8f6593e3..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() static PyObject * @@ -1066,17 +1065,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_AsSsize_t(args[0], PyExc_OverflowError); + if (new_size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = _thread_stack_size_impl(module, new_size); @@ -1272,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=3bfc76a318c6579d 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 da997377858e8b6..fa4484b284ab463 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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -180,17 +179,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_AsSsize_t(args[0], PyExc_OverflowError); + if (i == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = array_array_pop_impl((arrayobject *)self, i); @@ -252,17 +243,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_AsSsize_t(args[0], PyExc_OverflowError); + if (i == -1 && PyErr_Occurred()) { + goto exit; } v = args[1]; return_value = array_array_insert_impl((arrayobject *)self, i, v); @@ -381,23 +364,15 @@ 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; + 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; } - } return_value = array_array_fromfile_impl((arrayobject *)self, cls, f, n); exit: @@ -858,4 +833,4 @@ array_arrayiterator___setstate__(PyObject *self, PyObject *state) return return_value; } -/*[clinic end generated code: output=9127e1678f4b995b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ce804ee72e207201 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 0c5e35b1516da21..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_Index() #include "pycore_long.h" // _PyLong_Size_t_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -1221,17 +1220,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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +1312,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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +1686,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=9a088b9a940341de input=a9049054013a1b77]*/ diff --git a/Modules/clinic/faulthandler.c.h b/Modules/clinic/faulthandler.c.h index 07a9dd7dc561e12..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_Index() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -91,17 +90,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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +253,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_AsSsize_t(args[3], PyExc_OverflowError); + 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 +406,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_AsSsize_t(args[4], PyExc_OverflowError); + 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 +535,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_AsSsize_t(args[4], PyExc_OverflowError); + 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 +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=14815a5f8afe813f 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 3fd1b7a2fc7b907..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -80,17 +79,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_AsSsize_t(fastargs[1], PyExc_OverflowError); + if (n == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_kwonly; @@ -455,23 +446,15 @@ 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; + 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; } - } skip_optional: return_value = itertools_tee_impl(module, iterable, n); @@ -820,23 +803,15 @@ 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; + 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; } - } return_value = itertools_combinations_impl(type, iterable, r); exit: @@ -871,23 +846,15 @@ 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; + 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; } - } return_value = itertools_combinations_impl(_PyType_CAST(type), iterable, r); exit: @@ -965,23 +932,15 @@ 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; + 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; } - } return_value = itertools_combinations_with_replacement_impl(type, iterable, r); exit: @@ -1016,23 +975,15 @@ 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; + 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; } - } return_value = itertools_combinations_with_replacement_impl(_PyType_CAST(type), iterable, r); exit: @@ -1578,4 +1529,4 @@ zip_longest_next(PyObject *self) return return_value; } -/*[clinic end generated code: output=60939958c9c9348b 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 ece08c0fb6007c0..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -330,17 +329,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_AsSsize_t(arg, PyExc_OverflowError); + 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 +424,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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[1], PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_posonly: if (!noptargs) { @@ -499,17 +474,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_AsSsize_t(args[0], PyExc_OverflowError); + if (dist == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -600,41 +567,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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +727,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + 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 +777,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_AsSsize_t(args[1], PyExc_OverflowError); + if (start == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -967,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=90a906cde591ab92 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 c2f183f70378367..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_Index() #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() @@ -5706,17 +5705,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_AsSsize_t(args[1], PyExc_OverflowError); + if (signal == -1 && PyErr_Occurred()) { + goto exit; } return_value = os_kill_impl(module, pid, signal); @@ -7851,17 +7842,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_AsSsize_t(args[1], PyExc_OverflowError); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = os_read_impl(module, fd, length); @@ -8007,17 +7990,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_AsSsize_t(args[1], PyExc_OverflowError); + if (length == -1 && PyErr_Occurred()) { + goto exit; } if (!_Py_Off_t_Converter(args[2], &offset)) { goto exit; @@ -8326,23 +8301,15 @@ 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; + 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 (!noptargs) { goto skip_optional_pos; } @@ -8437,23 +8404,15 @@ 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; + 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; } - } return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); exit: @@ -8930,23 +8889,15 @@ 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; + 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 (!noptargs) { goto skip_optional_pos; } @@ -9053,23 +9004,15 @@ 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; + 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 (!noptargs) { goto skip_optional_pos; } @@ -11519,23 +11462,15 @@ 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; + 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; } - } return_value = os_urandom_impl(module, size); exit: @@ -12655,17 +12590,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_AsSsize_t(args[0], PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) { + goto exit; } if (!noptargs) { goto skip_optional_pos; @@ -13763,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=077c57e5f93bd790 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 7fdc707626c3243..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(py_sha3_new__doc__, @@ -224,23 +223,15 @@ _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; + 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; } - } return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length); exit: @@ -298,26 +289,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; + 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; } - } 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=4215537b85d00a40 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index 5a1a128b304f028..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_Index() #include "pycore_long.h" // _PyLong_UInt16_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -452,17 +451,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_AsSsize_t(args[0], PyExc_OverflowError); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -547,17 +538,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_AsSsize_t(args[1], PyExc_OverflowError); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -607,17 +590,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_AsSsize_t(args[0], PyExc_OverflowError); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -703,17 +678,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_AsSsize_t(args[1], PyExc_OverflowError); + if (recvlen == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -788,32 +755,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_AsSsize_t(args[0], PyExc_OverflowError); + 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_AsSsize_t(args[1], PyExc_OverflowError); + if (ancbufsize == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -890,17 +841,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_AsSsize_t(args[1], PyExc_OverflowError); + if (ancbufsize == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 3) { goto skip_optional; @@ -2244,17 +2187,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_AsSsize_t(arg, PyExc_OverflowError); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = _socket_CMSG_LEN_impl(module, length); @@ -2290,17 +2225,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_AsSsize_t(arg, PyExc_OverflowError); + if (length == -1 && PyErr_Occurred()) { + goto exit; } return_value = _socket_CMSG_SPACE_impl(module, length); @@ -2449,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=e6e677d3de0c63e4 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 5443893079b1af8..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, @@ -657,32 +656,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_AsSsize_t(args[1], PyExc_OverflowError); + 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_AsSsize_t(args[2], PyExc_OverflowError); + if (end == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = unicodedata_iter_graphemes_impl(module, unistr, start, end); @@ -834,4 +817,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=13549f0196144c13 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 023b178dc58fb5b..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(zlib_compress__doc__, @@ -178,23 +177,15 @@ 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; + 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; } - } skip_optional_pos: return_value = zlib_decompress_impl(module, &data, wbits, bufsize); @@ -548,23 +539,15 @@ 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; + 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; } - } skip_optional_pos: return_value = zlib_Decompress_decompress_impl((compobject *)self, cls, &data, max_length); @@ -824,17 +807,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_AsSsize_t(args[0], PyExc_OverflowError); + if (length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: return_value = zlib_Decompress_flush_impl((compobject *)self, cls, length); @@ -918,17 +893,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_AsSsize_t(args[1], PyExc_OverflowError); + if (max_length == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = zlib__ZlibDecompressor_decompress_impl((ZlibDecompressor *)self, &data, max_length); @@ -1338,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=f4c3b5abac20df9b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e7a387933dc0b242 input=a9049054013a1b77]*/ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 06099a3b8b2e0be..f8de321d58eb7ae 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_AsSsize_t(start_obj, PyExc_OverflowError); if (start == -1 && PyErr_Occurred()) { return NULL; } if (end_obj != Py_None) { - end = _As_Py_ssize_t(end_obj); + end = PyNumber_AsSsize_t(end_obj, PyExc_OverflowError); 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_AsSsize_t(length_obj, PyExc_OverflowError); if (length == -1 && PyErr_Occurred()) { return NULL; } diff --git a/Objects/abstract.c b/Objects/abstract.c index 635e1e927f23370..cce16321c494c18 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1480,6 +1480,12 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) { 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) return -1; diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 5445aa0166967a2..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_runtime.h" // _Py_SINGLETON() @@ -778,17 +777,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_AsSsize_t(arg, PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) { + goto exit; } Py_BEGIN_CRITICAL_SECTION(self); return_value = bytearray_resize_impl((PyByteArrayObject *)self, size); @@ -1029,17 +1020,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_AsSsize_t(args[2], PyExc_OverflowError); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1130,17 +1113,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1290,17 +1265,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -1362,17 +1329,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_AsSsize_t(args[0], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } if (!_getbytevalue(args[1], &item)) { goto exit; @@ -1474,17 +1433,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_AsSsize_t(args[0], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -1938,17 +1889,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_AsSsize_t(args[1], PyExc_OverflowError); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); @@ -2037,4 +1980,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=7661925edf2428d1 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index c96cd94425c1d18..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -98,17 +97,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_split_impl((PyBytesObject *)self, sep, maxsplit); @@ -269,17 +260,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_rsplit_impl((PyBytesObject *)self, sep, maxsplit); @@ -864,17 +847,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_AsSsize_t(args[2], PyExc_OverflowError); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = bytes_replace_impl((PyBytesObject *)self, &old, &new, count); @@ -1333,17 +1308,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_AsSsize_t(args[1], PyExc_OverflowError); + 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 +1464,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=170e9b6af7c1d571 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 359b9c202694472..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_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() @@ -92,17 +91,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_AsSsize_t(args[0], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } object = args[1]; Py_BEGIN_CRITICAL_SECTION(self); @@ -233,17 +224,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_AsSsize_t(args[0], PyExc_OverflowError); + if (index == -1 && PyErr_Occurred()) { + goto exit; } skip_optional: Py_BEGIN_CRITICAL_SECTION(self); @@ -528,4 +511,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=b9a399d4c7d577a4 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index 52ecaffa1f4cf35..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() static PyObject * @@ -330,23 +329,15 @@ 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; + 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 (!--noptargs) { goto skip_optional_pos; } @@ -493,4 +484,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=70dfcada7cc3394e input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index bb81e11e9a0ce20..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -502,17 +501,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_AsSsize_t(args[1], PyExc_OverflowError); + 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 +579,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=8e067b740de80373 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index f214fa42fa1a594..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_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() @@ -113,17 +112,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -757,17 +748,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -977,17 +960,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_AsSsize_t(args[2], PyExc_OverflowError); + if (count == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_replace_impl(self, old, new, count); @@ -1199,17 +1174,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -1302,17 +1269,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_split_impl(self, sep, maxsplit); @@ -1428,17 +1387,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_AsSsize_t(args[1], PyExc_OverflowError); + if (maxsplit == -1 && PyErr_Occurred()) { + goto exit; } skip_optional_pos: return_value = unicode_rsplit_impl(self, sep, maxsplit); @@ -1646,17 +1597,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_AsSsize_t(arg, PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } return_value = unicode_zfill_impl(self, width); @@ -1897,4 +1840,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=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 d695d8cac2fedab..5f3699a4dc9ada9 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_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 588fc101dbb5e3e..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(stringlib_expandtabs__doc__, @@ -101,17 +100,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -171,17 +162,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -241,17 +224,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_AsSsize_t(args[0], PyExc_OverflowError); + if (width == -1 && PyErr_Occurred()) { + goto exit; } if (nargs < 2) { goto skip_optional; @@ -307,21 +282,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_AsSsize_t(arg, PyExc_OverflowError); + 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=73e46317dbfbb715 input=a9049054013a1b77]*/ diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index a64418be0a830ba..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_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(warnings_acquire_lock__doc__, @@ -126,17 +125,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_AsSsize_t(args[2], PyExc_OverflowError); + if (stacklevel == -1 && PyErr_Occurred()) { + goto exit; } if (!--noptargs) { goto skip_optional_pos; @@ -284,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=fc026d6a21e12170 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=739833b3c7c383d7 input=a9049054013a1b77]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 70bd54a23e939ce..4c3d44dc516e809 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_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 10dc0c161665302..3d69f8a9aff9ef8 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -468,27 +468,13 @@ 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()') 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, - PyNumber_Index=PyNumber_Index, non_negative_check=non_negative_check, ) if not limited_capi: