Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 61050) +++ Python/bltinmodule.c (working copy) @@ -1576,38 +1576,39 @@ ilow = NULL; } assert(ihigh != NULL); - Py_INCREF(ihigh); /* ihigh correct now; do ilow */ - if (ilow == NULL) - ilow = zero; - Py_INCREF(ilow); - - /* ilow and ihigh correct now; do istep */ - if (istep == NULL) { - istep = PyLong_FromLong(1L); - if (istep == NULL) - goto Fail; + if (ilow == NULL) { + ilow = zero; + Py_INCREF(ilow); } - else { - Py_INCREF(istep); - } - - if (!PyInt_Check(ilow) && !PyLong_Check(ilow)) { + else if (PyInt_Check(ilow)) + Py_INCREF(ilow); + else if (!(ilow = PyNumber_Long(ilow))) { PyErr_Format(PyExc_TypeError, "range() integer start argument expected, got %s.", ilow->ob_type->tp_name); goto Fail; } - if (!PyInt_Check(ihigh) && !PyLong_Check(ihigh)) { + if (PyInt_Check(ihigh)) + Py_INCREF(ihigh); + else if (!(ihigh = PyNumber_Long(ihigh))) { PyErr_Format(PyExc_TypeError, "range() integer end argument expected, got %s.", ihigh->ob_type->tp_name); goto Fail; } - if (!PyInt_Check(istep) && !PyLong_Check(istep)) { + /* ilow and ihigh correct now; do istep */ + if (istep == NULL) { + istep = PyLong_FromLong(1L); + if (istep == NULL) + goto Fail; + } + else if (PyInt_Check(istep)) + Py_INCREF(istep); + else if (!(istep = PyNumber_Long(istep))) { PyErr_Format(PyExc_TypeError, "range() integer step argument expected, got %s.", istep->ob_type->tp_name); @@ -1669,8 +1670,8 @@ return v; Fail: - Py_DECREF(ilow); - Py_DECREF(ihigh); + Py_XDECREF(ilow); + Py_XDECREF(ihigh); Py_XDECREF(istep); Py_DECREF(zero); Py_XDECREF(curnum);