]> granicus.if.org Git - python/commitdiff
Check for errors in creating sub-interpreters when testing the C API.
authorBrett Cannon <brett@python.org>
Fri, 3 Feb 2012 17:08:03 +0000 (12:08 -0500)
committerBrett Cannon <brett@python.org>
Fri, 3 Feb 2012 17:08:03 +0000 (12:08 -0500)
Modules/_testcapimodule.c

index b00ac20b8e15bc49b71f25158a2965eae21535bc..bcb3a0fcbf2f8a28717659f4f23744ebfa0f5371 100644 (file)
@@ -2396,6 +2396,14 @@ run_in_subinterp(PyObject *self, PyObject *args)
     PyThreadState_Swap(NULL);
 
     substate = Py_NewInterpreter();
+    if (substate == NULL) {
+        /* Since no new thread state was created, there is no exception to
+           propagate; raise a fresh one after swapping in the old thread
+           state. */
+        PyThreadState_Swap(mainstate);
+        PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed");
+        return NULL;
+    }
     r = PyRun_SimpleString(code);
     Py_EndInterpreter(substate);