Mercurial > cpython-lru_cache-weakref
annotate Modules/_testembed.c @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +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 } |
