Issue #12909: Raise TypeError instead of SystemError when PyLong_AsDouble() or PyLong_AsUnsignedLongLong() is passed a non-integer argument (to be consistent with all the other PyLong_AsFoo() functions). diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1193,10 +1193,14 @@ int one = 1; int res; - if (vv == NULL || !PyLong_Check(vv)) { + if (vv == NULL) { PyErr_BadInternalCall(); return (unsigned PY_LONG_LONG)-1; } + if (!PyLong_Check(vv)) { + PyErr_SetString(PyExc_TypeError, "an integer is required"); + return (unsigned PY_LONG_LONG)-1; + } v = (PyLongObject*)vv; switch(Py_SIZE(v)) { @@ -2481,10 +2485,14 @@ Py_ssize_t exponent; double x; - if (v == NULL || !PyLong_Check(v)) { + if (v == NULL) { PyErr_BadInternalCall(); return -1.0; } + if (!PyLong_Check(v)) { + PyErr_SetString(PyExc_TypeError, "an integer is required"); + return -1.0; + } x = _PyLong_Frexp((PyLongObject *)v, &exponent); if ((x == -1.0 && PyErr_Occurred()) || exponent > DBL_MAX_EXP) { PyErr_SetString(PyExc_OverflowError,