annotate Python/frozen.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 44fd95cead7b
children 2dd046be2c88
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 2896
diff changeset
1
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 2896
diff changeset
2 /* Dummy frozen modules initializer */
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 2896
diff changeset
3
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 2896
diff changeset
4 #include "Python.h"
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 2896
diff changeset
5
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 /* In order to test the support for frozen modules, by default we
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 define a single frozen module, __hello__. Loading it will print
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 some famous words... */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
20526
1f3c1e831f21 Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
10 /* To regenerate this data after the bytecode or marshal format has changed,
43835
a2213060d9dd Fix for refleak tests through regrtest.py -R:: bug #1414
Christian Heimes <christian@cheimes.de>
parents: 43569
diff changeset
11 go to ../Tools/freeze/ and freeze the flag.py file; then copy and paste
20526
1f3c1e831f21 Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
12 the appropriate bytes from M___main__.c. */
1f3c1e831f21 Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
13
40452
50ce56b24cbe Oops, re-add 'static' qualifier.
Thomas Wouters <thomas@python.org>
parents: 40451
diff changeset
14 static unsigned char M___hello__[] = {
70152
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
15 99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
16 0,64,0,0,0,115,20,0,0,0,100,2,0,90,1,0,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
17 101,2,0,100,0,0,131,1,0,1,100,1,0,83,40,3,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
18 0,0,0,117,12,0,0,0,72,101,108,108,111,32,119,111,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
19 114,108,100,33,78,84,40,3,0,0,0,117,4,0,0,0,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
20 84,114,117,101,117,11,0,0,0,105,110,105,116,105,97,108,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
21 105,122,101,100,117,5,0,0,0,112,114,105,110,116,40,0,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
22 0,0,0,40,0,0,0,0,40,0,0,0,0,117,7,0,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
23 0,0,102,108,97,103,46,112,121,117,8,0,0,0,60,109,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
24 111,100,117,108,101,62,1,0,0,0,115,2,0,0,0,6,
44fd95cead7b Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61467
diff changeset
25 1,
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 };
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
20528
cb334a8c8dd2 Squash compiler wng about signed/unsigned mismatch.
Tim Peters <tim.peters@gmail.com>
parents: 20526
diff changeset
28 #define SIZE (int)sizeof(M___hello__)
20526
1f3c1e831f21 Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
29
3684
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
30 static struct _frozen _PyImport_FrozenModules[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
31 /* Test module */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
32 {"__hello__", M___hello__, SIZE},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
33 /* Test package (negative size indicates package-ness) */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
34 {"__phello__", M___hello__, -SIZE},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
35 {"__phello__.spam", M___hello__, SIZE},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 43835
diff changeset
36 {0, 0, 0} /* sentinel */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 };
3684
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
38
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
39 /* Embedding apps may change this pointer to point to their favorite
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
40 collection of frozen modules: */
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
41
606c38535f30 New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
42 struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;