Skip to content

gh-132987: Support __index__() in the posix module #133096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,21 +1035,34 @@ _PyLong_FromDev(dev_t dev)
static int
_Py_Dev_Converter(PyObject *obj, void *p)
{
if (!PyLong_Check(obj)) {
obj = _PyNumber_Index(obj);
if (obj == NULL) {
return 0;
}
}
else {
Py_INCREF(obj);
}
assert(PyLong_Check(obj));
#ifdef NODEV
if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
if (_PyLong_IsNegative((PyLongObject *)obj)) {
int overflow;
long long result = PyLong_AsLongLongAndOverflow(obj, &overflow);
if (result == -1 && PyErr_Occurred()) {
Py_DECREF(obj);
return 0;
}
if (!overflow && result == (long long)NODEV) {
*((dev_t *)p) = NODEV;
Py_DECREF(obj);
return 1;
}
}
#endif

unsigned long long result = PyLong_AsUnsignedLongLong(obj);
Py_DECREF(obj);
if (result == (unsigned long long)-1 && PyErr_Occurred()) {
return 0;
}
Expand Down Expand Up @@ -8499,7 +8512,7 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)

while ((item = PyIter_Next(iterator))) {
long cpu;
if (!PyLong_Check(item)) {
if (!PyIndex_Check(item)) {
PyErr_Format(PyExc_TypeError,
"expected an iterator of ints, "
"but iterator yielded %R",
Expand Down Expand Up @@ -9874,7 +9887,7 @@ os_setgroups(PyObject *module, PyObject *groups)
PyMem_Free(grouplist);
return NULL;
}
if (!PyLong_Check(elem)) {
if (!PyIndex_Check(elem)) {
PyErr_SetString(PyExc_TypeError,
"groups must be integers");
Py_DECREF(elem);
Expand Down Expand Up @@ -13643,7 +13656,7 @@ conv_confname(PyObject *module, PyObject *arg, int *valuep, const char *tablenam
}

int success = 0;
if (!PyLong_Check(arg)) {
if (!PyIndex_Check(arg)) {
PyErr_SetString(PyExc_TypeError,
"configuration names must be strings or integers");
} else {
Expand Down
Loading