diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-10-28 20:41:24 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-10-28 20:41:24 (GMT) |
commit | e6514f533efba25e5aeba50208515d02d528995a (patch) | |
tree | 9895781bdec365d927ee7669366773119c5164ad /Modules/_lzmamodule.c | |
parent | d1b48998e5b404387c8f0942197189ba3207c15e (diff) | |
parent | 3797065ac55997741fd625a30a8308c04ee5c9b9 (diff) | |
download | cpython-e6514f533efba25e5aeba50208515d02d528995a.zip cpython-e6514f533efba25e5aeba50208515d02d528995a.tar.gz cpython-e6514f533efba25e5aeba50208515d02d528995a.tar.bz2 |
#19395: Raise exception when pickling a (BZ2|LZMA)(Compressor|Decompressor).
The underlying C libraries provide no mechanism for serializing compressor and
decompressor objects, so actually pickling these classes is impractical.
Previously, these objects would be pickled without error, but attempting to use
a deserialized instance would segfault the interpreter.
Diffstat (limited to 'Modules/_lzmamodule.c')
-rw-r--r-- | Modules/_lzmamodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 5d610bf..1217ed4 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -564,6 +564,14 @@ Compressor_flush(Compressor *self, PyObject *noargs) return result; } +static PyObject * +Compressor_getstate(Compressor *self, PyObject *noargs) +{ + PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", + Py_TYPE(self)->tp_name); + return NULL; +} + static int Compressor_init_xz(lzma_stream *lzs, int check, uint32_t preset, PyObject *filterspecs) @@ -735,6 +743,7 @@ static PyMethodDef Compressor_methods[] = { Compressor_compress_doc}, {"flush", (PyCFunction)Compressor_flush, METH_NOARGS, Compressor_flush_doc}, + {"__getstate__", (PyCFunction)Compressor_getstate, METH_NOARGS}, {NULL} }; @@ -892,6 +901,14 @@ Decompressor_decompress(Decompressor *self, PyObject *args) return result; } +static PyObject * +Decompressor_getstate(Decompressor *self, PyObject *noargs) +{ + PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", + Py_TYPE(self)->tp_name); + return NULL; +} + static int Decompressor_init_raw(lzma_stream *lzs, PyObject *filterspecs) { @@ -1019,6 +1036,7 @@ Decompressor_dealloc(Decompressor *self) static PyMethodDef Decompressor_methods[] = { {"decompress", (PyCFunction)Decompressor_decompress, METH_VARARGS, Decompressor_decompress_doc}, + {"__getstate__", (PyCFunction)Decompressor_getstate, METH_NOARGS}, {NULL} }; |