diff -r da8e8e28a616 Modules/_bz2module.c --- a/Modules/_bz2module.c Sat Jan 18 00:49:30 2014 -0500 +++ b/Modules/_bz2module.c Sat Jan 18 13:29:28 2014 +0200 @@ -196,44 +196,59 @@ return NULL; } -PyDoc_STRVAR(BZ2Compressor_compress__doc__, -"compress(data) -> bytes\n" -"\n" -"Provide data to the compressor object. Returns a chunk of\n" -"compressed data if possible, or b'' otherwise.\n" -"\n" -"When you have finished providing data to the compressor, call the\n" -"flush() method to finish the compression process.\n"); +/*[clinic input] +output preset file +module bz2 +class bz2.BZ2Compressor +class bz2.BZ2Decompressor +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + +/*[clinic input] +bz2.BZ2Compressor.compress + + self: self(type="BZ2Compressor *") + data: Py_buffer + / + +Provide data to the compressor object. + +Returns a chunk of compressed data if possible, or b'' otherwise. + +When you have finished providing data to the compressor, call the +flush() method to finish the compression process. +[clinic start generated code]*/ static PyObject * -BZ2Compressor_compress(BZ2Compressor *self, PyObject *args) +bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data) +/*[clinic end generated code: checksum=ee7e32540a3194b61bf10a81e214057760f366e2]*/ { - Py_buffer buffer; PyObject *result = NULL; - if (!PyArg_ParseTuple(args, "y*:compress", &buffer)) - return NULL; - ACQUIRE_LOCK(self); if (self->flushed) PyErr_SetString(PyExc_ValueError, "Compressor has been flushed"); else - result = compress(self, buffer.buf, buffer.len, BZ_RUN); + result = compress(self, data->buf, data->len, BZ_RUN); RELEASE_LOCK(self); - PyBuffer_Release(&buffer); return result; } -PyDoc_STRVAR(BZ2Compressor_flush__doc__, -"flush() -> bytes\n" -"\n" -"Finish the compression process. Returns the compressed data left\n" -"in internal buffers.\n" -"\n" -"The compressor object may not be used after this method is called.\n"); +/*[clinic input] +bz2.BZ2Compressor.flush + + self: self(type="BZ2Compressor *") + +Finish the compression process. + +Returns the compressed data left in internal buffers. + +The compressor object may not be used after this method is called. +[clinic start generated code]*/ static PyObject * -BZ2Compressor_flush(BZ2Compressor *self, PyObject *noargs) +bz2_BZ2Compressor_flush_impl(BZ2Compressor *self) +/*[clinic end generated code: checksum=174aede133d77dccb63a6a15d5ecdc5de77a03e9]*/ { PyObject *result = NULL; @@ -324,14 +339,7 @@ Py_TYPE(self)->tp_free((PyObject *)self); } -static PyMethodDef BZ2Compressor_methods[] = { - {"compress", (PyCFunction)BZ2Compressor_compress, METH_VARARGS, - BZ2Compressor_compress__doc__}, - {"flush", (PyCFunction)BZ2Compressor_flush, METH_NOARGS, - BZ2Compressor_flush__doc__}, - {"__getstate__", (PyCFunction)BZ2Compressor_getstate, METH_NOARGS}, - {NULL} -}; +static PyMethodDef BZ2Compressor_methods[]; PyDoc_STRVAR(BZ2Compressor__doc__, "BZ2Compressor(compresslevel=9)\n" @@ -451,32 +459,34 @@ return NULL; } -PyDoc_STRVAR(BZ2Decompressor_decompress__doc__, -"decompress(data) -> bytes\n" -"\n" -"Provide data to the decompressor object. Returns a chunk of\n" -"decompressed data if possible, or b'' otherwise.\n" -"\n" -"Attempting to decompress data after the end of stream is reached\n" -"raises an EOFError. Any data found after the end of the stream\n" -"is ignored and saved in the unused_data attribute.\n"); +/*[clinic input] +bz2.BZ2Decompressor.decompress + + self: self(type="BZ2Decompressor *") + data: Py_buffer + / + +Provide data to the decompressor object. + +Returns a chunk of decompressed data if possible, or b'' otherwise. + +Attempting to decompress data after the end of stream is reached +raises an EOFError. Any data found after the end of the stream +is ignored and saved in the unused_data attribute. +[clinic start generated code]*/ static PyObject * -BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args) +bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data) +/*[clinic end generated code: checksum=39f4c8064d9219f2bfd709fd9004487617588b32]*/ { - Py_buffer buffer; PyObject *result = NULL; - if (!PyArg_ParseTuple(args, "y*:decompress", &buffer)) - return NULL; - ACQUIRE_LOCK(self); if (self->eof) PyErr_SetString(PyExc_EOFError, "End of stream already reached"); else - result = decompress(self, buffer.buf, buffer.len); + result = decompress(self, data->buf, data->len); RELEASE_LOCK(self); - PyBuffer_Release(&buffer); return result; } @@ -535,9 +545,17 @@ Py_TYPE(self)->tp_free((PyObject *)self); } +#include "_bz2module.clinic.c" + +static PyMethodDef BZ2Compressor_methods[] = { + BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF + BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF + {"__getstate__", (PyCFunction)BZ2Compressor_getstate, METH_NOARGS}, + {NULL} +}; + static PyMethodDef BZ2Decompressor_methods[] = { - {"decompress", (PyCFunction)BZ2Decompressor_decompress, METH_VARARGS, - BZ2Decompressor_decompress__doc__}, + BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF {"__getstate__", (PyCFunction)BZ2Decompressor_getstate, METH_NOARGS}, {NULL} }; diff -r da8e8e28a616 Modules/_bz2module.clinic.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/_bz2module.clinic.c Sat Jan 18 13:29:28 2014 +0200 @@ -0,0 +1,95 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(bz2_BZ2Compressor_compress__doc__, +"compress(data)\n" +"Provide data to the compressor object.\n" +"\n" +"Returns a chunk of compressed data if possible, or b\'\' otherwise.\n" +"\n" +"When you have finished providing data to the compressor, call the\n" +"flush() method to finish the compression process."); + +#define BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF \ + {"compress", (PyCFunction)bz2_BZ2Compressor_compress, METH_VARARGS, bz2_BZ2Compressor_compress__doc__}, + +static PyObject * +bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data); + +static PyObject * +bz2_BZ2Compressor_compress(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + + if (!PyArg_ParseTuple(args, + "y*:compress", + &data)) + goto exit; + return_value = bz2_BZ2Compressor_compress_impl((BZ2Compressor *)self, &data); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(bz2_BZ2Compressor_flush__doc__, +"flush()\n" +"Finish the compression process.\n" +"\n" +"Returns the compressed data left in internal buffers.\n" +"\n" +"The compressor object may not be used after this method is called."); + +#define BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \ + {"flush", (PyCFunction)bz2_BZ2Compressor_flush, METH_NOARGS, bz2_BZ2Compressor_flush__doc__}, + +static PyObject * +bz2_BZ2Compressor_flush_impl(BZ2Compressor *self); + +static PyObject * +bz2_BZ2Compressor_flush(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return bz2_BZ2Compressor_flush_impl((BZ2Compressor *)self); +} + +PyDoc_STRVAR(bz2_BZ2Decompressor_decompress__doc__, +"decompress(data)\n" +"Provide data to the decompressor object.\n" +"\n" +"Returns a chunk of decompressed data if possible, or b\'\' otherwise.\n" +"\n" +"Attempting to decompress data after the end of stream is reached\n" +"raises an EOFError. Any data found after the end of the stream\n" +"is ignored and saved in the unused_data attribute."); + +#define BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \ + {"decompress", (PyCFunction)bz2_BZ2Decompressor_decompress, METH_VARARGS, bz2_BZ2Decompressor_decompress__doc__}, + +static PyObject * +bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data); + +static PyObject * +bz2_BZ2Decompressor_decompress(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + + if (!PyArg_ParseTuple(args, + "y*:decompress", + &data)) + goto exit; + return_value = bz2_BZ2Decompressor_decompress_impl((BZ2Decompressor *)self, &data); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} +/*[clinic end generated code: checksum=6a5a32ee8b92560800074ba0e1b40954494d3a60]*/