summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:21:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:21:23 (GMT)
commit9aa16d93c9570771bdb8f0819e4b17f4284c952e (patch)
treed99399279e4224251f689f1a2b80b764ce6835e8 /Modules
parent3ce7873fddef05ecd6c5da2d5bd40206fee3805c (diff)
downloadcpython-9aa16d93c9570771bdb8f0819e4b17f4284c952e.zip
cpython-9aa16d93c9570771bdb8f0819e4b17f4284c952e.tar.gz
cpython-9aa16d93c9570771bdb8f0819e4b17f4284c952e.tar.bz2
Issue #23842: os.major(), os.minor() and os.makedev() now support ints again.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c4c767e..4e86d32 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -478,13 +478,38 @@ OverflowUp:
static int
_Py_Dev_Converter(PyObject *obj, void *p)
{
+ PyObject *index = PyNumber_Index(obj);
+ if (index == NULL)
+ return 0;
+ if (PyInt_Check(index)) {
+ long x = PyInt_AS_LONG(index);
+ Py_DECREF(index);
+ if (x == -1 && PyErr_Occurred())
+ return 0;
+ if (x < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative number to unsigned long");
+ return 0;
+ }
+ *((dev_t *)p) = (unsigned long)x;
+ }
+ else if (PyLong_Check(index)) {
#ifdef HAVE_LONG_LONG
- *((dev_t *)p) = PyLong_AsUnsignedLongLong(obj);
+ *((dev_t *)p) = PyLong_AsUnsignedLongLong(index);
#else
- *((dev_t *)p) = PyLong_AsUnsignedLong(obj);
+ *((dev_t *)p) = PyLong_AsUnsignedLong(index);
#endif
- if (PyErr_Occurred())
+ Py_DECREF(index);
+ if (PyErr_Occurred())
+ return 0;
+ }
+ else {
+ Py_DECREF(index);
+ PyErr_Format(PyExc_TypeError,
+ "expected int/long, %s found",
+ Py_TYPE(obj)->tp_name);
return 0;
+ }
return 1;
}