bpo-40792: Make the result of PyNumber_Index() always having exact type int. (GH-20443)
Previously, the result could have been an instance of a subclass of int.
Also revert bpo-26202 and make attributes start, stop and step of the range
object having exact type int.
Add private function _PyNumber_Index() which preserves the old behavior
of PyNumber_Index() for performance to use it in the conversion functions
like PyLong_AsLong().
diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h
index 8a0170a..07fc906 100644
--- a/Modules/clinic/_bisectmodule.c.h
+++ b/Modules/clinic/_bisectmodule.c.h
@@ -48,7 +48,7 @@
if (args[2]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -119,7 +119,7 @@
if (args[2]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -189,7 +189,7 @@
if (args[2]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -260,7 +260,7 @@
if (args[2]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -283,4 +283,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=e9097a9acd10b13f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6cf46f205659f01a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h
index ab610a1..4660207 100644
--- a/Modules/clinic/_bz2module.c.h
+++ b/Modules/clinic/_bz2module.c.h
@@ -159,7 +159,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -210,4 +210,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=c69a7de8e26c2ad1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b49102ee26928a28 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h
index 0cc1466..7e18aeb 100644
--- a/Modules/clinic/_collectionsmodule.c.h
+++ b/Modules/clinic/_collectionsmodule.c.h
@@ -52,7 +52,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 0));
+ PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 0));
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -68,4 +68,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=439d77631a056b4d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=947186d369f50f1e input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h
index 5934218..2c9ba47 100644
--- a/Modules/clinic/_elementtree.c.h
+++ b/Modules/clinic/_elementtree.c.h
@@ -432,7 +432,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -915,4 +915,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=c98b210c525a9338 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1385b5e5688f3614 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index 51ae240..e72b558 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -94,7 +94,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -141,7 +141,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -1417,4 +1417,4 @@
#ifndef _HASHLIB_GET_FIPS_MODE_METHODDEF
#define _HASHLIB_GET_FIPS_MODE_METHODDEF
#endif /* !defined(_HASHLIB_GET_FIPS_MODE_METHODDEF) */
-/*[clinic end generated code: output=95447a60132f039e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2bbd6159493f44ea input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h
index 40913ef..e4e0a79 100644
--- a/Modules/clinic/_lzmamodule.c.h
+++ b/Modules/clinic/_lzmamodule.c.h
@@ -118,7 +118,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -319,4 +319,4 @@
return return_value;
}
-/*[clinic end generated code: output=a87074ca902bd432 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d6e997ebc269f78f input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h
index 2a66f8f..34b6fda 100644
--- a/Modules/clinic/_operator.c.h
+++ b/Modules/clinic/_operator.c.h
@@ -1426,7 +1426,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -1486,4 +1486,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=1fe4adf4f5761420 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=eae5d08f971a65fd input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_sre.c.h b/Modules/clinic/_sre.c.h
index fc3ae04..2314114 100644
--- a/Modules/clinic/_sre.c.h
+++ b/Modules/clinic/_sre.c.h
@@ -193,7 +193,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -209,7 +209,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -262,7 +262,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -278,7 +278,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -333,7 +333,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -349,7 +349,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -402,7 +402,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -418,7 +418,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -473,7 +473,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -489,7 +489,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -541,7 +541,7 @@
if (args[1]) {
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -557,7 +557,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -608,7 +608,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -661,7 +661,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -714,7 +714,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -800,7 +800,7 @@
code = args[2];
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[3]);
+ PyObject *iobj = _PyNumber_Index(args[3]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -1102,4 +1102,4 @@
{
return _sre_SRE_Scanner_search_impl(self);
}
-/*[clinic end generated code: output=7a3360917b40a808 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0e27915b1eb7c0e4 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h
index 874f30a..1cfaef3 100644
--- a/Modules/clinic/_struct.c.h
+++ b/Modules/clinic/_struct.c.h
@@ -126,7 +126,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -312,7 +312,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -376,4 +376,4 @@
return return_value;
}
-/*[clinic end generated code: output=1205daf7f616f0cf input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8089792d8ed0c1be input=a9049054013a1b77]*/
diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h
index 334db39..300cd13 100644
--- a/Modules/clinic/arraymodule.c.h
+++ b/Modules/clinic/arraymodule.c.h
@@ -84,7 +84,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -134,7 +134,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -245,7 +245,7 @@
f = args[0];
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -514,4 +514,4 @@
#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
{"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
-/*[clinic end generated code: output=c953eb8486c7c8da input=a9049054013a1b77]*/
+/*[clinic end generated code: output=91c1cded65a1285f input=a9049054013a1b77]*/
diff --git a/Modules/clinic/audioop.c.h b/Modules/clinic/audioop.c.h
index 56d31d3..da12bd1 100644
--- a/Modules/clinic/audioop.c.h
+++ b/Modules/clinic/audioop.c.h
@@ -39,7 +39,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -372,7 +372,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -1309,4 +1309,4 @@
return return_value;
}
-/*[clinic end generated code: output=343e5ae478fc0359 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=840f8c315ebd4946 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h
index c6d6717..c1192bb 100644
--- a/Modules/clinic/itertoolsmodule.c.h
+++ b/Modules/clinic/itertoolsmodule.c.h
@@ -172,7 +172,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -353,7 +353,7 @@
iterable = fastargs[0];
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(fastargs[1]);
+ PyObject *iobj = _PyNumber_Index(fastargs[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -401,7 +401,7 @@
iterable = fastargs[0];
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(fastargs[1]);
+ PyObject *iobj = _PyNumber_Index(fastargs[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -627,4 +627,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=07211f86c4153050 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d7f58dc477814b45 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index 96ea020..ff439ee 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -4743,7 +4743,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -4843,7 +4843,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -5112,7 +5112,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[3]);
+ PyObject *iobj = _PyNumber_Index(args[3]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -5192,7 +5192,7 @@
offobj = args[2];
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[3]);
+ PyObject *iobj = _PyNumber_Index(args[3]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -5627,7 +5627,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -7512,7 +7512,7 @@
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(arg);
+ PyObject *iobj = _PyNumber_Index(arg);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -8160,7 +8160,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -8877,4 +8877,4 @@
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=9623b9e6f3809842 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=767780ea3beacf34 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index 2b72aeb..61dfa9a 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -117,7 +117,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[2]);
+ PyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -409,7 +409,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[1]);
+ PyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -611,7 +611,7 @@
}
{
Py_ssize_t ival = -1;
- PyObject *iobj = PyNumber_Index(args[0]);
+ PyObject *iobj = _PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
@@ -757,4 +757,4 @@
#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
-/*[clinic end generated code: output=06b6438506aab0cb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=be34f273564e39a8 input=a9049054013a1b77]*/