Back to index

python3.2  3.2.2
Functions | Variables
makefreeze Namespace Reference

Functions

def makefreeze
def writecode

Variables

string header
string trailer
string default_entry_point

Function Documentation

def makefreeze.makefreeze (   base,
  dict,
  debug = 0,
  entry_point = None,
  fail_import = () 
)

Definition at line 32 of file makefreeze.py.

00032 
00033 def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
00034     if entry_point is None: entry_point = default_entry_point
00035     done = []
00036     files = []
00037     mods = sorted(dict.keys())
00038     for mod in mods:
00039         m = dict[mod]
00040         mangled = "__".join(mod.split("."))
00041         if m.__code__:
00042             file = 'M_' + mangled + '.c'
00043             outfp = bkfile.open(base + file, 'w')
00044             files.append(file)
00045             if debug:
00046                 print("freezing", mod, "...")
00047             str = marshal.dumps(m.__code__)
00048             size = len(str)
00049             if m.__path__:
00050                 # Indicate package by negative size
00051                 size = -size
00052             done.append((mod, mangled, size))
00053             writecode(outfp, mangled, str)
00054             outfp.close()
00055     if debug:
00056         print("generating table of frozen modules")
00057     outfp = bkfile.open(base + 'frozen.c', 'w')
00058     for mod, mangled, size in done:
00059         outfp.write('extern unsigned char M_%s[];\n' % mangled)
00060     outfp.write(header)
00061     for mod, mangled, size in done:
00062         outfp.write('\t{"%s", M_%s, %d},\n' % (mod, mangled, size))
00063     outfp.write('\n')
00064     # The following modules have a NULL code pointer, indicating
00065     # that the prozen program should not search for them on the host
00066     # system. Importing them will *always* raise an ImportError.
00067     # The zero value size is never used.
00068     for mod in fail_import:
00069         outfp.write('\t{"%s", NULL, 0},\n' % (mod,))
00070     outfp.write(trailer)
00071     outfp.write(entry_point)
00072     outfp.close()
00073     return files
00074 
00075 
00076 
00077 # Write a C initializer for a module containing the frozen python code.
00078 # The array is called M_<mod>.

Here is the call graph for this function:

Here is the caller graph for this function:

def makefreeze.writecode (   outfp,
  mod,
  str 
)

Definition at line 79 of file makefreeze.py.

00079 
00080 def writecode(outfp, mod, str):
00081     outfp.write('unsigned char M_%s[] = {' % mod)
00082     for i in range(0, len(str), 16):
00083         outfp.write('\n\t')
00084         for c in bytes(str[i:i+16]):
00085             outfp.write('%d,' % c)
00086     outfp.write('\n};\n')

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 """
00002 int
00003 main(int argc, char **argv)
00004 {
00005         extern int Py_FrozenMain(int, char **);
00006 """

Definition at line 18 of file makefreeze.py.

Initial value:
00001 """
00002 #include "Python.h"
00003 
00004 static struct _frozen _PyImport_FrozenModules[] = {
00005 """

Definition at line 7 of file makefreeze.py.

Initial value:
00001 """\
00002     {0, 0, 0} /* sentinel */
00003 };
00004 """

Definition at line 12 of file makefreeze.py.