diff options
Diffstat (limited to 'Modules/testcapi_long.h')
-rw-r--r-- | Modules/testcapi_long.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/Modules/testcapi_long.h b/Modules/testcapi_long.h index fa94fd6..6bddad7 100644 --- a/Modules/testcapi_long.h +++ b/Modules/testcapi_long.h @@ -33,8 +33,7 @@ TESTNAME(PyObject *error(const char*)) unsigned TYPENAME uin, uout; /* For 0, 1, 2 use base; for 3, 4, 5 use -base */ - uin = j < 3 ? base - : (unsigned TYPENAME)(-(TYPENAME)base); + uin = j < 3 ? base : 0U - base; /* For 0 & 3, subtract 1. * For 1 & 4, leave alone. @@ -177,6 +176,32 @@ TESTNAME(PyObject *error(const char*)) Py_DECREF(one); } + /* Test F_PY_TO_{S,U} on non-pylong input. This should raise a TypeError. */ + { + TYPENAME out; + unsigned TYPENAME uout; + + Py_INCREF(Py_None); + + out = F_PY_TO_S(Py_None); + if (out != (TYPENAME)-1 || !PyErr_Occurred()) + return error("PyLong_AsXXX(None) didn't complain"); + if (!PyErr_ExceptionMatches(PyExc_TypeError)) + return error("PyLong_AsXXX(None) raised " + "something other than TypeError"); + PyErr_Clear(); + + uout = F_PY_TO_U(Py_None); + if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred()) + return error("PyLong_AsXXX(None) didn't complain"); + if (!PyErr_ExceptionMatches(PyExc_TypeError)) + return error("PyLong_AsXXX(None) raised " + "something other than TypeError"); + PyErr_Clear(); + + Py_DECREF(Py_None); + } + Py_INCREF(Py_None); return Py_None; } |