Fix pickling for pypy
This commit is contained in:
@@ -845,7 +845,10 @@ cdef class _MessageSize:
|
|||||||
self.word_count = word_count
|
self.word_count = word_count
|
||||||
self.cap_count = cap_count
|
self.cap_count = cap_count
|
||||||
|
|
||||||
def _struct_reducer(schema_id, data):
|
if getattr(_sys, 'subversion', [''])[0] == 'PyPy':
|
||||||
|
from pickle_helper import _struct_reducer
|
||||||
|
else:
|
||||||
|
def _struct_reducer(schema_id, data):
|
||||||
return _global_schema_parser.modules_by_id[schema_id].from_bytes(data)
|
return _global_schema_parser.modules_by_id[schema_id].from_bytes(data)
|
||||||
|
|
||||||
cdef class _DynamicStructReader:
|
cdef class _DynamicStructReader:
|
||||||
@@ -930,7 +933,7 @@ cdef class _DynamicStructReader:
|
|||||||
size = self.thisptr.totalSize()
|
size = self.thisptr.totalSize()
|
||||||
return _MessageSize(size.wordCount, size.capCount)
|
return _MessageSize(size.wordCount, size.capCount)
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce_ex__(self, proto):
|
||||||
return _struct_reducer, (self.schema.node.id, self.as_builder().to_bytes())
|
return _struct_reducer, (self.schema.node.id, self.as_builder().to_bytes())
|
||||||
|
|
||||||
cdef class _DynamicStructBuilder:
|
cdef class _DynamicStructBuilder:
|
||||||
@@ -1191,7 +1194,7 @@ cdef class _DynamicStructBuilder:
|
|||||||
size = self.thisptr.totalSize()
|
size = self.thisptr.totalSize()
|
||||||
return _MessageSize(size.wordCount, size.capCount)
|
return _MessageSize(size.wordCount, size.capCount)
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce_ex__(self, proto):
|
||||||
return _struct_reducer, (self.schema.node.id, self.to_bytes())
|
return _struct_reducer, (self.schema.node.id, self.to_bytes())
|
||||||
|
|
||||||
cdef class _DynamicStructPipeline:
|
cdef class _DynamicStructPipeline:
|
||||||
|
|||||||
6
capnp/lib/pickle_helper.py
Normal file
6
capnp/lib/pickle_helper.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import capnp
|
||||||
|
|
||||||
|
|
||||||
|
def _struct_reducer(schema_id, data):
|
||||||
|
'Hack to deal with pypy not allowing reduce functions to be "built-in" methods (ie. compiled from a .pyx)'
|
||||||
|
return capnp._global_schema_parser.modules_by_id[schema_id].from_bytes(data)
|
||||||
Reference in New Issue
Block a user