summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 20:35:23 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 20:35:23 (GMT)
commit3797065ac55997741fd625a30a8308c04ee5c9b9 (patch)
treecf67e5dabe3bfcab16f64afa5118fd8b207c6da6 /Modules
parentba4e58a02172df294f16c68f0b0c4ac80184e4b0 (diff)
downloadcpython-3797065ac55997741fd625a30a8308c04ee5c9b9.zip
cpython-3797065ac55997741fd625a30a8308c04ee5c9b9.tar.gz
cpython-3797065ac55997741fd625a30a8308c04ee5c9b9.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')
-rw-r--r--Modules/_bz2module.c22
-rw-r--r--Modules/_lzmamodule.c18
2 files changed, 38 insertions, 2 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
index 4eee5a2..3f7a6cf 100644
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -250,6 +250,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 int
BZ2Compressor_init(BZ2Compressor *self, PyObject *args, PyObject *kwargs)
{
@@ -298,10 +306,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}
};
@@ -452,6 +461,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)
{
@@ -502,6 +519,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}
};
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index b482a77..6436160 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -546,6 +546,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)
@@ -712,6 +720,7 @@ static PyMethodDef Compressor_methods[] = {
Compressor_compress_doc},
{"flush", (PyCFunction)Compressor_flush, METH_NOARGS,
Compressor_flush_doc},
+ {"__getstate__", (PyCFunction)Compressor_getstate, METH_NOARGS},
{NULL}
};
@@ -869,6 +878,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)
{
@@ -991,6 +1008,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}
};