Commits

Ronny Pfannschmidt committed 2ee2929

getstate/setstate

Comments (0)

Files changed (1)

         'typecode',
     ]
 
+    def __getnewargs(self):
+        return self.typecode
+
+    def __getstate__(self):
+        return self.typecode, self.tostring(), getattr(self, '__dict__', None)
+
+    def __setstate__(self, state):
+        typecode, data , vars = state
+        self._data = ffi.NULL
+        self._len = 0
+        self._capacity = 0
+        self.typecode = typecode
+        self.ctype = typecode2ctype(self.typecode)
+        self.arraytype = ffi.getctype(self.ctype, '[]')
+        if vars is not None:
+            self.__dict__.update(vars)
+        self.fromstring(data)
+
     def __new__(cls, typecode, initializer=missing, **kw):
         ctype = typecode2ctype(typecode)
         self = cffi_array.__new__(cls, ctype)
         self._len +=count
 
     def _assign_buffer(self, start, data):
+        if not data and self._data is ffi.NULL:
+            return
         start = start*self.itemsize
         assign = ffi.buffer(self._data)
         assign[start:start+len(data)] = data