From af91642cd177ba4f59fb3d0020b2cc0164bbd5ff Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 13 Mar 2016 14:44:27 -0700 Subject: [PATCH] lept: fix __getstate/__setstate --- ocrmypdf/leptonica.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ocrmypdf/leptonica.py b/ocrmypdf/leptonica.py index 5d86fadd..2f81dc4a 100644 --- a/ocrmypdf/leptonica.py +++ b/ocrmypdf/leptonica.py @@ -126,7 +126,11 @@ class Pix: raise LeptonicaIOError("pixSerializeToMemory") char_data = ffi.cast('char *', data[0]) + + # Copy from C bytes to python bytes() data_bytes = ffi.buffer(char_data, size[0])[:] + + # Can now free C bytes lept.lept_free(char_data) return dict(data=data_bytes) @@ -134,8 +138,9 @@ class Pix: cdata_bytes = ffi.new('char[]', state['data']) cdata_uint32 = ffi.cast('l_uint32 *', cdata_bytes) - self._pix = lept.pixDeserializeFromMemory( + pix = lept.pixDeserializeFromMemory( cdata_uint32, len(state['data'])) + Pix.__init__(self, pix) @property def width(self):