5 # Write a file containing frozen code for the modules in the dictionary.
10 static struct _frozen _PyImport_FrozenModules[] = {
13 {0, 0, 0} /* sentinel */
17 # if __debug__ == 0 (i.e. -O option given), set Py_OptimizeFlag in frozen app.
18 default_entry_point
= """
24 """ + ((not __debug__
and """
27 PyImport_FrozenModules = _PyImport_FrozenModules;
28 return Py_FrozenMain(argc, argv);
33 def makefreeze(outfp
, dict, debug
=0, entry_point
= None):
34 if entry_point
is None: entry_point
= default_entry_point
40 mangled
= string
.join(string
.split(mod
, "."), "__")
43 print "freezing", mod
, "..."
44 str = marshal
.dumps(m
.__code
__)
47 # Indicate package by negative size
49 done
.append((mod
, mangled
, size
))
50 writecode(outfp
, mangled
, str)
52 print "generating table of frozen modules"
54 for mod
, mangled
, size
in done
:
55 outfp
.write('\t{"%s", M_%s, %d},\n' % (mod
, mangled
, size
))
57 outfp
.write(entry_point
)
61 # Write a C initializer for a module containing the frozen python code.
62 # The array is called M_<mod>.
64 def writecode(outfp
, mod
, str):
65 outfp
.write('static unsigned char M_%s[] = {' % mod
)
66 for i
in range(0, len(str), 16):
69 outfp
.write('%d,' % ord(c
))