Skip to content

Commit ca4cba0

Browse files
eendebakptclaude
andcommitted
Use PyNumber_AsSsize_t() with an int fast path instead of a new helper
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent aeba29e commit ca4cba0

57 files changed

Lines changed: 394 additions & 457 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Include/internal/pycore_abstract.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ PyAPI_FUNC(int) _Py_convert_optional_to_non_negative_ssize_t(PyObject *, void *)
6060
// Export for 'math' shared extension.
6161
PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject *o);
6262

63-
PyAPI_FUNC(Py_ssize_t) _PyNumber_IndexAsSsize_t(PyObject *o);
64-
6563
typedef struct {
6664
PyObject *object;
6765
PySendResult kind;

‎Lib/test/clinic.test.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,14 +1652,14 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na
16521652
if (nargs < 1) {
16531653
goto skip_optional;
16541654
}
1655-
a = _PyNumber_IndexAsSsize_t(args[0]);
1655+
a = PyNumber_AsSsize_t(args[0], PyExc_OverflowError);
16561656
if (a == -1 && PyErr_Occurred()) {
16571657
goto exit;
16581658
}
16591659
if (nargs < 2) {
16601660
goto skip_optional;
16611661
}
1662-
b = _PyNumber_IndexAsSsize_t(args[1]);
1662+
b = PyNumber_AsSsize_t(args[1], PyExc_OverflowError);
16631663
if (b == -1 && PyErr_Occurred()) {
16641664
goto exit;
16651665
}
@@ -1672,15 +1672,15 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na
16721672
if (nargs < 4) {
16731673
goto skip_optional;
16741674
}
1675-
d = _PyNumber_IndexAsSsize_t(args[3]);
1675+
d = PyNumber_AsSsize_t(args[3], PyExc_OverflowError);
16761676
if (d == -1 && PyErr_Occurred()) {
16771677
goto exit;
16781678
}
1679-
if (d < 0) {
1680-
PyErr_SetString(PyExc_ValueError,
1681-
"d cannot be negative");
1682-
goto exit;
1683-
}
1679+
if (d < 0) {
1680+
PyErr_SetString(PyExc_ValueError,
1681+
"d cannot be negative");
1682+
goto exit;
1683+
}
16841684
if (nargs < 5) {
16851685
goto skip_optional;
16861686
}
@@ -1690,7 +1690,7 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na
16901690
if (nargs < 6) {
16911691
goto skip_optional;
16921692
}
1693-
f = _PyNumber_IndexAsSsize_t(args[5]);
1693+
f = PyNumber_AsSsize_t(args[5], PyExc_OverflowError);
16941694
if (f == -1 && PyErr_Occurred()) {
16951695
goto exit;
16961696
}
@@ -1711,7 +1711,7 @@ static PyObject *
17111711
test_Py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b,
17121712
Py_ssize_t c, Py_ssize_t d, Py_ssize_t e,
17131713
Py_ssize_t f, Py_ssize_t g)
1714-
/*[clinic end generated code: output=e4286b4ef87a92ab input=a25bac8ecf2890aa]*/
1714+
/*[clinic end generated code: output=4f744bf0d897e01c input=a25bac8ecf2890aa]*/
17151715

17161716

17171717
/*[clinic input]

‎Lib/test/test_zlib.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@ def test_decompressobj_badflush(self):
337337

338338
@support.cpython_only
339339
def test_overflow(self):
340-
with self.assertRaisesRegex(OverflowError, 'int too large'):
340+
with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"):
341341
zlib.decompress(b'', 15, sys.maxsize + 1)
342-
with self.assertRaisesRegex(OverflowError, 'int too large'):
342+
with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"):
343343
zlib.decompressobj().decompress(b'', sys.maxsize + 1)
344-
with self.assertRaisesRegex(OverflowError, 'int too large'):
344+
with self.assertRaisesRegex(OverflowError, "cannot fit 'int'"):
345345
zlib.decompressobj().flush(sys.maxsize + 1)
346346

347347
@support.cpython_only

‎Modules/_ctypes/clinic/_ctypes.c.h‎

Lines changed: 13 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_ctypes/clinic/callproc.c.h‎

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_ctypes/clinic/cfield.c.h‎

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_decimal/clinic/_decimal.c.h‎

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/bufferedio.c.h‎

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/bytesio.c.h‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/iobase.c.h‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)