#3643 add more checks to _testcapi to prevent segfaults

Author: Victor Stinner
Reviewer: Benjamin Peterson
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 494937a..995d789 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -961,6 +961,10 @@
 	if (!PyArg_ParseTuple(args, "O:exception_print",
 				&value))
 		return NULL;
+	if (!PyExceptionInstance_Check(value)) {
+		PyErr_Format(PyExc_TypeError, "an exception instance is required");
+		return NULL;
+	}
 
 	tb = PyException_GetTraceback(value);
 	PyErr_Display((PyObject *) Py_TYPE(value), value, tb);