[pypy-svn] r9523 - pypy/dist/pypy/translator

arigo at codespeak.net arigo at codespeak.net
Mon Feb 28 16:21:47 CET 2005


Author: arigo
Date: Mon Feb 28 16:21:47 2005
New Revision: 9523

Modified:
   pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc.py
Log:
genc now generates the frozen initialization bytecode as a big string 
literal instead of a { } array literal.  This helps keep gcc memory 
consumption lower.



Modified: pypy/dist/pypy/translator/genc.h
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc.h	Mon Feb 28 16:21:47 2005
@@ -342,12 +342,12 @@
 	return 0;
 }
 
-static int setup_initcode(unsigned char* frozendata, int len)
+static int setup_initcode(char* frozendata, int len)
 {
 	PyObject* co;
 	PyObject* globals;
 	PyObject* res;
-	co = PyMarshal_ReadObjectFromString((char*) frozendata, len);
+	co = PyMarshal_ReadObjectFromString(frozendata, len);
 	if (co == NULL)
 		return -1;
 	if (!PyCode_Check(co)) {

Modified: pypy/dist/pypy/translator/genc.py
==============================================================================
--- pypy/dist/pypy/translator/genc.py	(original)
+++ pypy/dist/pypy/translator/genc.py	Mon Feb 28 16:21:47 2005
@@ -490,8 +490,12 @@
         # frozen init bytecode
         print >> f, self.C_FROZEN_BEGIN
         bytecode = self.getfrozenbytecode()
+        def char_repr(c):
+            if c in '\\"': return '\\' + c
+            if ' ' <= c < '\x7F': return c
+            return '\\%03o' % ord(c)
         for i in range(0, len(bytecode), 20):
-            print >> f, ''.join(['%d,' % ord(c) for c in bytecode[i:i+20]])
+            print >> f, ''.join([char_repr(c) for c in bytecode[i:i+20]])+'\\'
         print >> f, self.C_FROZEN_END
 
         # the footer proper: the module init function */
@@ -826,9 +830,9 @@
 
     C_FROZEN_BEGIN = '''
 /* Frozen Python bytecode: the initialization code */
-static unsigned char frozen_initcode[] = {'''
+static char frozen_initcode[] = "\\'''
 
-    C_FROZEN_END = '''};\n'''
+    C_FROZEN_END = '''";\n'''
 
     C_FOOTER = C_SEP + '''
 



More information about the Pypy-commit mailing list