[pypy-svn] r64164 - pypy/trunk/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Thu Apr 16 15:25:11 CEST 2009


Author: arigo
Date: Thu Apr 16 15:25:11 2009
New Revision: 64164

Added:
   pypy/trunk/pypy/interpreter/gateway.py.merge.tmp
      - copied, changed from r64160, pypy/trunk/pypy/interpreter/gateway.py
Log:
merging of svn+ssh://codespeak.net/svn/pypy/branch/wip-fix-stackless-O2-pickling/pypy/interpreter/gateway.py
revisions 63853 to 64160:

    ------------------------------------------------------------------------
    r64149 | cfbolz | 2009-04-16 12:49:52 +0200 (Thu, 16 Apr 2009) | 3 lines
    
    (cfbolz, pedronis, arigo around): the self_type needs to be part of the key that
    is used to cache interp2app objects.
    
    ------------------------------------------------------------------------
    r64146 | cfbolz | 2009-04-16 12:11:43 +0200 (Thu, 16 Apr 2009) | 3 lines
    
    (pedronis, cfbolz): fix pickling of functions that have builtin code objects
    attached to them.
    
    ------------------------------------------------------------------------
    r64107 | cfbolz | 2009-04-15 18:12:38 +0200 (Wed, 15 Apr 2009) | 2 lines
    
    (cfbolz, pedronis): This xxx is fixed, and there is an assert to check it.
    
    ------------------------------------------------------------------------
    r64100 | cfbolz | 2009-04-15 16:43:11 +0200 (Wed, 15 Apr 2009) | 2 lines
    
    (pedronis, cfbolz): try to make more builtin function names unique. 
    
    ------------------------------------------------------------------------
    r63866 | pedronis | 2009-04-08 18:43:53 +0200 (Wed, 08 Apr 2009) | 3 lines
    
    my current bunch of changes, mostly started supporting pickling of builtin code objects
    
    
    ------------------------------------------------------------------------
    r63865 | pedronis | 2009-04-08 18:42:06 +0200 (Wed, 08 Apr 2009) | 3 lines
    
    making a branch to check-in my WIP work, it is at least not broken with -O0 so something stranger is going on
    
    
    ------------------------------------------------------------------------


Copied: pypy/trunk/pypy/interpreter/gateway.py.merge.tmp (from r64160, pypy/trunk/pypy/interpreter/gateway.py)
==============================================================================
--- pypy/trunk/pypy/interpreter/gateway.py	(original)
+++ pypy/trunk/pypy/interpreter/gateway.py.merge.tmp	Thu Apr 16 15:25:11 2009
@@ -405,6 +405,9 @@
         eval.Code.__init__(self, func.__name__)
         self.docstring = func.__doc__
 
+        self.identifier = "%s-%s-%s" % (func.__module__, func.__name__,
+                                        getattr(self_type, '__name__', '*'))
+
         # unwrap_spec can be passed to interp2app or
         # attached as an attribute to the function.
         # It is a list of types or singleton objects:
@@ -479,6 +482,19 @@
                 self.__class__ = globals()['BuiltinCode%d' % arity]
                 setattr(self, 'fastfunc_%d' % arity, fastfunc)
 
+    def descr__reduce__(self, space):
+        from pypy.interpreter.mixedmodule import MixedModule
+        w_mod    = space.getbuiltinmodule('_pickle_support')
+        mod      = space.interp_w(MixedModule, w_mod)
+        builtin_code = mod.get('builtin_code')
+        return space.newtuple([builtin_code,
+                               space.newtuple([space.wrap(self.identifier)])])
+
+    def find(indentifier):
+        from pypy.interpreter.function import Function
+        return Function._all[indentifier].code
+    find = staticmethod(find)
+
     def signature(self):
         return self.sig
 
@@ -702,11 +718,13 @@
     # Takes optionally an unwrap_spec, see BuiltinCode
 
     NOT_RPYTHON_ATTRIBUTES = ['_staticdefs']
+
+    instancecache = {}
     
-    def __init__(self, f, app_name=None, unwrap_spec = None,
-                 descrmismatch=None, as_classmethod=False):
+    def __new__(cls, f, app_name=None, unwrap_spec = None,
+                descrmismatch=None, as_classmethod=False):
+
         "NOT_RPYTHON"
-        Wrappable.__init__(self)
         # f must be a function whose name does NOT start with 'app_'
         self_type = None
         if hasattr(f, 'im_func'):
@@ -719,6 +737,18 @@
                 raise ValueError, ("function name %r suspiciously starts "
                                    "with 'app_'" % f.func_name)
             app_name = f.func_name
+
+        if unwrap_spec is not None:
+            unwrap_spec_key = tuple(unwrap_spec)
+        else:
+            unwrap_spec_key = None
+        key = (f, self_type, unwrap_spec_key, descrmismatch, as_classmethod)
+        if key in cls.instancecache:
+            result = cls.instancecache[key]
+            assert result.__class__ is cls
+            return result
+        self = Wrappable.__new__(cls)
+        cls.instancecache[key] = self
         self._code = BuiltinCode(f, unwrap_spec=unwrap_spec,
                                  self_type = self_type,
                                  descrmismatch=descrmismatch)
@@ -726,6 +756,7 @@
         self.name = app_name
         self.as_classmethod = as_classmethod
         self._staticdefs = list(f.func_defaults or ())
+        return self
 
     def _getdefaults(self, space):
         "NOT_RPYTHON"
@@ -758,6 +789,8 @@
         defs = gateway._getdefaults(space) # needs to be implemented by subclass
         code = gateway._code
         fn = Function(space, code, None, defs, forcename = gateway.name)
+        if not space.config.translating: # for tests and py.py
+            fn._freeze_()
         if gateway.as_classmethod:
             fn = ClassMethod(space.wrap(fn))
         return fn



More information about the Pypy-commit mailing list