Author: Matti Picus <[email protected]>
Branch: cpyext-pickle
Changeset: r84847:9d276f2f9df4
Date: 2016-05-31 23:29 +0300
http://bitbucket.org/pypy/pypy/changeset/9d276f2f9df4/

Log:    add cpyext class to pickler dispatch more cleanly

diff --git a/lib-python/2.7/pickle.py b/lib-python/2.7/pickle.py
--- a/lib-python/2.7/pickle.py
+++ b/lib-python/2.7/pickle.py
@@ -285,10 +285,6 @@
         if f:
             f(self, obj) # Call unbound method with explicit self
             return
-        elif 'builtin' in str(t):
-            # specifically cpyext builtin types
-            self.save_global(obj)
-            return
         # Check copy_reg.dispatch_table
         reduce = dispatch_table.get(t)
         if reduce:
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -1,7 +1,14 @@
 from pypy.interpreter.mixedmodule import MixedModule
+from pypy.interpreter import gateway
 from pypy.module.cpyext.state import State
 from pypy.module.cpyext import api
 
+add_pickle_key = gateway.applevel('''
+    def add_pickle_key(methodtype):
+        from pickle import Pickler 
+        Pickler.dispatch[methodtype] = Pickler.save_global
+''', filename=__file__).interphook('add_pickle_key')
+
 class Module(MixedModule):
     interpleveldefs = {
         'load_module': 'api.load_extension_module',
@@ -14,6 +21,9 @@
 
     def startup(self, space):
         space.fromcache(State).startup(space)
+        method = pypy.module.cpyext.typeobject.get_new_method_def(space)
+        w_obj = pypy.module.cpyext.methodobject.W_PyCFunctionObject(space, 
method, '')
+        add_pickle_key(space, space.type(w_obj))
 
     def register_atexit(self, function):
         if len(self.atexit_funcs) >= 32:
@@ -65,6 +75,7 @@
 import pypy.module.cpyext.pyfile
 import pypy.module.cpyext.pystrtod
 import pypy.module.cpyext.pytraceback
+import pypy.module.cpyext.methodobject
 
 # now that all rffi_platform.Struct types are registered, configure them
 api.configure_types()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to