Mercurial > cpython-lru_cache-weakref
annotate Modules/_testembed.c @ 74006:88198b93ff2f
Issue #13560: Add PyUnicode_EncodeLocale()
* Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not
available
* Document my last changes in Misc/NEWS
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 17 Dec 2011 04:13:41 +0100 |
| parents | 79fcd71d0356 |
| children | 9cd88b39ef62 |
| rev | line source |
|---|---|
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1 #include <Python.h> |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
2 #include <stdio.h> |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
3 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
4 void print_subinterp(void) |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
5 { |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
6 /* Just output some debug stuff */ |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
7 PyThreadState *ts = PyThreadState_Get(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
8 printf("interp %p, thread state %p: ", ts->interp, ts); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
9 fflush(stdout); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
10 PyRun_SimpleString( |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
11 "import sys;" |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
12 "print('id(modules) =', id(sys.modules));" |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
13 "sys.stdout.flush()" |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
14 ); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
15 } |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
16 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
17 int main(int argc, char *argv[]) |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
18 { |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
19 PyThreadState *mainstate, *substate; |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
20 #ifdef WITH_THREAD |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 PyGILState_STATE gilstate; |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
22 #endif |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
23 int i, j; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
24 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 for (i=0; i<3; i++) { |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
26 printf("--- Pass %d ---\n", i); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
27 /* HACK: the "./" at front avoids a search along the PATH in |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
28 Modules/getpath.c */ |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 Py_SetProgramName(L"./_testembed"); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 Py_Initialize(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 mainstate = PyThreadState_Get(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
33 #ifdef WITH_THREAD |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 PyEval_InitThreads(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
35 PyEval_ReleaseThread(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
36 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 gilstate = PyGILState_Ensure(); |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
38 #endif |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
39 print_subinterp(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 PyThreadState_Swap(NULL); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 for (j=0; j<3; j++) { |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 substate = Py_NewInterpreter(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
44 print_subinterp(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
45 Py_EndInterpreter(substate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
46 } |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
47 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
48 PyThreadState_Swap(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
49 print_subinterp(); |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
50 #ifdef WITH_THREAD |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
51 PyGILState_Release(gilstate); |
|
69585
79fcd71d0356
Fix compilation of _testembed.c without threads
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69553
diff
changeset
|
52 #endif |
|
69553
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
53 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
54 PyEval_RestoreThread(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
55 Py_Finalize(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
56 } |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
57 return 0; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
58 } |
