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/_bz2module.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/_bz2module.c')
-rw-r--r-- | Modules/_bz2module.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index abc4d5d..fd05de0 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -248,6 +248,14 @@ BZ2Compressor_flush(BZ2Compressor *self, PyObject *noargs) return result; } +static PyObject * +BZ2Compressor_getstate(BZ2Compressor *self, PyObject *noargs) +{ + PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", + Py_TYPE(self)->tp_name); + return NULL; +} + static void* BZ2_Malloc(void* ctx, int items, int size) { @@ -317,10 +325,11 @@ BZ2Compressor_dealloc(BZ2Compressor *self) } static PyMethodDef BZ2Compressor_methods[] = { - {"compress", (PyCFunction)BZ2Compressor_compress, METH_VARARGS, + {"compress", (PyCFunction)BZ2Compressor_compress, METH_VARARGS, BZ2Compressor_compress__doc__}, - {"flush", (PyCFunction)BZ2Compressor_flush, METH_NOARGS, + {"flush", (PyCFunction)BZ2Compressor_flush, METH_NOARGS, BZ2Compressor_flush__doc__}, + {"__getstate__", (PyCFunction)BZ2Compressor_getstate, METH_NOARGS}, {NULL} }; @@ -471,6 +480,14 @@ BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args) return result; } +static PyObject * +BZ2Decompressor_getstate(BZ2Decompressor *self, PyObject *noargs) +{ + PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", + Py_TYPE(self)->tp_name); + return NULL; +} + static int BZ2Decompressor_init(BZ2Decompressor *self, PyObject *args, PyObject *kwargs) { @@ -521,6 +538,7 @@ BZ2Decompressor_dealloc(BZ2Decompressor *self) static PyMethodDef BZ2Decompressor_methods[] = { {"decompress", (PyCFunction)BZ2Decompressor_decompress, METH_VARARGS, BZ2Decompressor_decompress__doc__}, + {"__getstate__", (PyCFunction)BZ2Decompressor_getstate, METH_NOARGS}, {NULL} }; |