Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4114a4a

Browse files
committed
Fix the frozen bytecode for __hello__ (betcha didn't know that existed
:-). Add a test that prevents the __hello__ bytecode from going stale unnoticed again. The test also tests the loophole noted in SF bug #404545. This test will fail right now; I'll check in the fix in a minute.
1 parent 9ae0994 commit 4114a4a

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

Lib/__phello__.foo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file exists as a helper for the test.test_frozen module.

Lib/test/output/test_frozen

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_frozen
2+
Hello world...
3+
Hello world...
4+
Hello world...

Lib/test/test_frozen.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test the frozen module defined in frozen.c.
2+
3+
from test_support import TestFailed
4+
import sys, os
5+
6+
try:
7+
import __hello__
8+
except ImportError, x:
9+
raise TestFailed, "import __hello__ failed:", x
10+
11+
try:
12+
import __phello__
13+
except ImportError, x:
14+
raise TestFailed, "import __phello__ failed:", x
15+
16+
try:
17+
import __phello__.spam
18+
except ImportError, x:
19+
raise TestFailed, "import __phello__.spam failed:", x
20+
21+
try:
22+
import __phello__.foo
23+
except ImportError:
24+
pass
25+
else:
26+
raise TestFailed, "import __phello__.foo should have failed"

Python/frozen.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@
77
define a single frozen module, __hello__. Loading it will print
88
some famous words... */
99

10+
/* To regenerate this data after the bytecode or marshal format has changed,
11+
go to ../Tools/freeze/ and freeze the hello.py file; then copy and paste
12+
the appropriate bytes from M___main__.c. */
13+
1014
static unsigned char M___hello__[] = {
1115
99,0,0,0,0,1,0,0,0,115,15,0,0,0,127,0,
1216
0,127,1,0,100,0,0,71,72,100,1,0,83,40,2,0,
1317
0,0,115,14,0,0,0,72,101,108,108,111,32,119,111,114,
1418
108,100,46,46,46,78,40,0,0,0,0,40,0,0,0,0,
15-
115,8,0,0,0,104,101,108,108,111,46,112,121,115,1,0,
16-
0,0,63,1,0,115,0,0,0,0,
19+
40,0,0,0,0,40,0,0,0,0,115,8,0,0,0,104,
20+
101,108,108,111,46,112,121,115,1,0,0,0,63,1,0,115,
21+
0,0,0,0,
1722
};
1823

24+
#define SIZE sizeof(M___hello__)
25+
1926
static struct _frozen _PyImport_FrozenModules[] = {
2027
/* Test module */
21-
{"__hello__", M___hello__, 90},
28+
{"__hello__", M___hello__, SIZE},
2229
/* Test package (negative size indicates package-ness) */
23-
{"__phello__", M___hello__, -90},
24-
{"__phello__.spam", M___hello__, 90},
30+
{"__phello__", M___hello__, -SIZE},
31+
{"__phello__.spam", M___hello__, SIZE},
2532
{0, 0, 0} /* sentinel */
2633
};
2734

0 commit comments

Comments
 (0)