Mercurial > cpython-lru_cache-weakref
annotate Modules/_testembed.c @ 69676:89ebde7cd8ea 3.2
Add WSANO_DATA to possible errors triggered by getaddrinfo (Windows)
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Fri, 29 Apr 2011 00:44:33 +0200 |
| parents | d195ff5c44f4 |
| children | 79fcd71d0356 |
| 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; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
20 PyGILState_STATE gilstate; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 int i, j; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
22 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
23 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
|
24 printf("--- Pass %d ---\n", i); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 /* 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
|
26 Modules/getpath.c */ |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
27 Py_SetProgramName(L"./_testembed"); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
28 Py_Initialize(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 mainstate = PyThreadState_Get(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 PyEval_InitThreads(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 PyEval_ReleaseThread(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
33 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 gilstate = PyGILState_Ensure(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
35 print_subinterp(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
36 PyThreadState_Swap(NULL); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
38 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
|
39 substate = Py_NewInterpreter(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 print_subinterp(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 Py_EndInterpreter(substate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 } |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
44 PyThreadState_Swap(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
45 print_subinterp(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
46 PyGILState_Release(gilstate); |
|
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 PyEval_RestoreThread(mainstate); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
49 Py_Finalize(); |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
50 } |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
51 return 0; |
|
d195ff5c44f4
Issue #10914: Add a minimal embedding test to test_capi.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
52 } |
