summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-01-17 23:21:11 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-01-17 23:21:11 (GMT)
commit2f828f2c8859b331bf9519bdc660eb8a2288779a (patch)
treed137b7be2783abe51bd5f15913ef73283b25b962 /Modules/_testcapimodule.c
parent03757ec4a571df0e871bd9136cae9d08841f8a6a (diff)
downloadcpython-2f828f2c8859b331bf9519bdc660eb8a2288779a.zip
cpython-2f828f2c8859b331bf9519bdc660eb8a2288779a.tar.gz
cpython-2f828f2c8859b331bf9519bdc660eb8a2288779a.tar.bz2
Test running of code in a sub-interpreter
(prelude to issue #6531).
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 6c61f7d..94b6e67 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2300,6 +2300,32 @@ crash_no_current_thread(PyObject *self)
return NULL;
}
+/* To run some code in a sub-interpreter. */
+static PyObject *
+run_in_subinterp(PyObject *self, PyObject *args)
+{
+ const char *code;
+ int r;
+ PyThreadState *substate, *mainstate;
+
+ if (!PyArg_ParseTuple(args, "s:run_in_subinterp",
+ &code))
+ return NULL;
+
+ mainstate = PyThreadState_Get();
+
+ PyThreadState_Swap(NULL);
+
+ substate = Py_NewInterpreter();
+ r = PyRun_SimpleString(code);
+ Py_EndInterpreter(substate);
+
+ PyThreadState_Swap(mainstate);
+
+ return PyLong_FromLong(r);
+}
+
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
@@ -2385,6 +2411,7 @@ static PyMethodDef TestMethods[] = {
{"make_memoryview_from_NULL_pointer", (PyCFunction)make_memoryview_from_NULL_pointer,
METH_NOARGS},
{"crash_no_current_thread", (PyCFunction)crash_no_current_thread, METH_NOARGS},
+ {"run_in_subinterp", run_in_subinterp, METH_VARARGS},
{NULL, NULL} /* sentinel */
};