@@ -1035,21 +1035,34 @@ _PyLong_FromDev(dev_t dev)
1035
1035
static int
1036
1036
_Py_Dev_Converter (PyObject * obj , void * p )
1037
1037
{
1038
+ if (!PyLong_Check (obj )) {
1039
+ obj = _PyNumber_Index (obj );
1040
+ if (obj == NULL ) {
1041
+ return 0 ;
1042
+ }
1043
+ }
1044
+ else {
1045
+ Py_INCREF (obj );
1046
+ }
1047
+ assert (PyLong_Check (obj ));
1038
1048
#ifdef NODEV
1039
- if (PyLong_Check ( obj ) && _PyLong_IsNegative ((PyLongObject * )obj )) {
1049
+ if (_PyLong_IsNegative ((PyLongObject * )obj )) {
1040
1050
int overflow ;
1041
1051
long long result = PyLong_AsLongLongAndOverflow (obj , & overflow );
1042
1052
if (result == -1 && PyErr_Occurred ()) {
1053
+ Py_DECREF (obj );
1043
1054
return 0 ;
1044
1055
}
1045
1056
if (!overflow && result == (long long )NODEV ) {
1046
1057
* ((dev_t * )p ) = NODEV ;
1058
+ Py_DECREF (obj );
1047
1059
return 1 ;
1048
1060
}
1049
1061
}
1050
1062
#endif
1051
1063
1052
1064
unsigned long long result = PyLong_AsUnsignedLongLong (obj );
1065
+ Py_DECREF (obj );
1053
1066
if (result == (unsigned long long )-1 && PyErr_Occurred ()) {
1054
1067
return 0 ;
1055
1068
}
@@ -8499,7 +8512,7 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)
8499
8512
8500
8513
while ((item = PyIter_Next (iterator ))) {
8501
8514
long cpu ;
8502
- if (!PyLong_Check (item )) {
8515
+ if (!PyIndex_Check (item )) {
8503
8516
PyErr_Format (PyExc_TypeError ,
8504
8517
"expected an iterator of ints, "
8505
8518
"but iterator yielded %R" ,
@@ -9874,7 +9887,7 @@ os_setgroups(PyObject *module, PyObject *groups)
9874
9887
PyMem_Free (grouplist );
9875
9888
return NULL ;
9876
9889
}
9877
- if (!PyLong_Check (elem )) {
9890
+ if (!PyIndex_Check (elem )) {
9878
9891
PyErr_SetString (PyExc_TypeError ,
9879
9892
"groups must be integers" );
9880
9893
Py_DECREF (elem );
@@ -13643,7 +13656,7 @@ conv_confname(PyObject *module, PyObject *arg, int *valuep, const char *tablenam
13643
13656
}
13644
13657
13645
13658
int success = 0 ;
13646
- if (!PyLong_Check (arg )) {
13659
+ if (!PyIndex_Check (arg )) {
13647
13660
PyErr_SetString (PyExc_TypeError ,
13648
13661
"configuration names must be strings or integers" );
13649
13662
} else {
0 commit comments