[pypy-svn] r14796 - in pypy/dist/pypy: rpython translator/goal translator/pickle

tismer at codespeak.net tismer at codespeak.net
Wed Jul 20 02:54:39 CEST 2005


Author: tismer
Date: Wed Jul 20 02:54:37 2005
New Revision: 14796

Modified:
   pypy/dist/pypy/rpython/lltype.py
   pypy/dist/pypy/translator/goal/translate_pypy.py
   pypy/dist/pypy/translator/pickle/genpickle.py
Log:
tried to build pickling support for debugging.

translate_pypy now tries to save a file if the
option was given, after a TyperError has happened.

Unfortunately, the involved structures seem to be
too deeply nested. We crash with stack overflow.

Further exploration is necessry to find out what to cut.


Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Wed Jul 20 02:54:37 2005
@@ -59,13 +59,10 @@
         finally:
             TLS.nested_hash_level -= 1
 
-    # due to this dynamic hash value, we must forbid
-    # pickling, until we have an algorithm for that
-    def __reduce_ex__(self, *args):
-        raise Exception('%s insts cannot be pickled, yet. __hash__ is not'
-                        ' constant during reconstruction.' %
-                        self.__class__.__name__)
-    __reduce__ = __reduce_ex__
+    # due to this dynamic hash value, we should forbid
+    # pickling, until we have an algorithm for that.
+    # but we just provide a tag for external help.
+    __hash_is_not_constant__ = True
 
     def __repr__(self):
         return '<%s>' % (self,)
@@ -746,6 +743,8 @@
 
 
 class _pyobject(Hashable):
+    __slots__ = []   # or we get in trouble with pickling
+
     _TYPE = PyObject
 
     def _parentstructure(self):

Modified: pypy/dist/pypy/translator/goal/translate_pypy.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate_pypy.py	(original)
+++ pypy/dist/pypy/translator/goal/translate_pypy.py	Wed Jul 20 02:54:37 2005
@@ -75,6 +75,8 @@
 from pypy.tool.udir import udir 
 from pypy.tool.ansi_print import ansi_print
 from pypy.translator.pickle.main import load, save
+# catch TyperError to allow for post-mortem dump
+from pypy.rpython.rmodel import TyperError
 
 # XXX this tries to make compiling faster
 from pypy.translator.tool import buildpyxmodule
@@ -492,6 +494,7 @@
             cleanup()
 
     try:
+        err = None
         if load_file:
             t = loaded_dic['trans']
             entry_point = t.entrypoint
@@ -509,17 +512,25 @@
             print "continuing Analysis as defined by %s, loaded from %s" %(
                 targetspec, load_file)
             print 'options in effect:', options
-            analyse(None)
+            try:
+                analyse(None)
+            except TyperError:
+                err = sys.exc_info()
         else:
             targetspec_dic = {}
             sys.path.insert(0, os.path.dirname(targetspec))
             execfile(targetspec+'.py', targetspec_dic)
             print "Analysing target as defined by %s" % targetspec
             print 'options in effect:', options
-            analyse(targetspec_dic['target'])
+            try:
+                analyse(targetspec_dic['target'])
+            except TyperError:
+                err = sys.exc_info()
         print '-'*60
         if save_file:
             print 'saving state to %s' % save_file
+            if err:
+                print '*** this save is done after errors occured ***'
             save(t, save_file,
                  trans=t,
                  inputtypes=inputtypes,
@@ -527,6 +538,8 @@
                  targetspec_dic=targetspec_dic,
                  options=options,
                  )
+        if err:
+            raise err[0], err[1], err[2]
         if options['-no-c']:
             print 'Not generating C code.'
         elif options['-c']:

Modified: pypy/dist/pypy/translator/pickle/genpickle.py
==============================================================================
--- pypy/dist/pypy/translator/pickle/genpickle.py	(original)
+++ pypy/dist/pypy/translator/pickle/genpickle.py	Wed Jul 20 02:54:37 2005
@@ -31,7 +31,7 @@
 import pickle
 
 from types import *
-import types
+import types, weakref
 
 class AlreadyCreated(Exception): pass
 
@@ -191,6 +191,9 @@
             except AlreadyCreated:
                 name = self.picklenames[id(obj)]
             return name
+        except Exception, e:
+            self.problem = e, obj
+            raise
 
     def nameofargs(self, tup, plain_tuple = False):
         """ a string with the nameofs, concatenated """
@@ -443,6 +446,13 @@
             self.produce('from types import %s as %s' % (
                 key, name))
             return name
+        elif cls in weakref.__dict__.values():
+            for key, value in weakref.__dict__.items():
+                if value is cls:
+                    break
+            self.produce('from weakref import %s as %s' % (
+                key, name))
+            return name
         else:
             expr = self.typename_mapping[cls]
         self.produce('%s = %s' % (name, expr))
@@ -600,7 +610,7 @@
                     raise
                 assert not hasattr(instance, '__dict__'), ('wrong assumptions'
                     ' about __slots__ in %s instance without __setstate__,'
-                    ' please update %s' % (cls.__name__, __name__) )
+                    ' please update %s' % (klass.__name__, __name__) )
                 restorestate = _get(instance)
                 restorer = _rec
                 restoreargs = klass,
@@ -746,6 +756,12 @@
             wp, wp.__name__)
         return self.skipped_function(wp, msg)
 
+    def nameof_weakref(self, value):
+        # no need to name weakrefs. Their contents is what is weakref'ed.
+        # obtain the ref'ed object by calling
+        obj = value()
+        return '%s(%s)' % (self.nameof(type(value)), self.nameof(obj))
+
 
 def make_cell(obj):
     def func():



More information about the Pypy-commit mailing list