summaryrefslogtreecommitdiff
path: root/Modules/testcapi_long.h
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-09-07 21:40:26 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-09-07 21:40:26 +0200
commit3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf (patch)
tree56fe5975d6856ad3f89daa74988a5f66221eda4a /Modules/testcapi_long.h
parent425fcd3045708a6e8ce1c15c6950101d2523dd59 (diff)
downloadcpython-git-3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf.tar.gz
Issue #12909: Make PyLong_As* functions consistent in their use of exceptions.
PyLong_AsDouble() and PyLong_AsUnsignedLongLong() now raise TypeError (rather than SystemError) when passed a non-integer argument, matching the behavior of all the other PyLong_As*() functions.
Diffstat (limited to 'Modules/testcapi_long.h')
-rw-r--r--Modules/testcapi_long.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/Modules/testcapi_long.h b/Modules/testcapi_long.h
index fa94fd6bea..5784452edf 100644
--- a/Modules/testcapi_long.h
+++ b/Modules/testcapi_long.h
@@ -177,6 +177,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;
}