summaryrefslogtreecommitdiffstats
path: root/Modules/_testembed.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-04-25 19:21:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-04-25 19:21:07 (GMT)
commit8e6057769373a76fb8cead60f001ced38b635c5c (patch)
treeaa3059350c50f093f0984daad7e9feaddbd2ad15 /Modules/_testembed.c
parentb32321aed94bee8ea68fad79ed710670d0c1941c (diff)
downloadcpython-8e6057769373a76fb8cead60f001ced38b635c5c.zip
cpython-8e6057769373a76fb8cead60f001ced38b635c5c.tar.gz
cpython-8e6057769373a76fb8cead60f001ced38b635c5c.tar.bz2
Issue #10914: Add a minimal embedding test to test_capi.
Diffstat (limited to 'Modules/_testembed.c')
-rw-r--r--Modules/_testembed.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/Modules/_testembed.c b/Modules/_testembed.c
new file mode 100644
index 0000000..0df5ede
--- /dev/null
+++ b/Modules/_testembed.c
@@ -0,0 +1,52 @@
+#include <Python.h>
+#include <stdio.h>
+
+void print_subinterp(void)
+{
+ /* Just output some debug stuff */
+ PyThreadState *ts = PyThreadState_Get();
+ printf("interp %p, thread state %p: ", ts->interp, ts);
+ fflush(stdout);
+ PyRun_SimpleString(
+ "import sys;"
+ "print('id(modules) =', id(sys.modules));"
+ "sys.stdout.flush()"
+ );
+}
+
+int main(int argc, char *argv[])
+{
+ PyThreadState *mainstate, *substate;
+ PyGILState_STATE gilstate;
+ int i, j;
+
+ for (i=0; i<3; i++) {
+ printf("--- Pass %d ---\n", i);
+ /* HACK: the "./" at front avoids a search along the PATH in
+ Modules/getpath.c */
+ Py_SetProgramName(L"./_testembed");
+ Py_Initialize();
+ mainstate = PyThreadState_Get();
+
+ PyEval_InitThreads();
+ PyEval_ReleaseThread(mainstate);
+
+ gilstate = PyGILState_Ensure();
+ print_subinterp();
+ PyThreadState_Swap(NULL);
+
+ for (j=0; j<3; j++) {
+ substate = Py_NewInterpreter();
+ print_subinterp();
+ Py_EndInterpreter(substate);
+ }
+
+ PyThreadState_Swap(mainstate);
+ print_subinterp();
+ PyGILState_Release(gilstate);
+
+ PyEval_RestoreThread(mainstate);
+ Py_Finalize();
+ }
+ return 0;
+}