--- a/contrib/python-zstandard/c-ext/compressionreader.c Tue Sep 25 20:55:03 2018 +0900
+++ b/contrib/python-zstandard/c-ext/compressionreader.c Mon Oct 08 16:27:40 2018 -0700
@@ -43,20 +43,11 @@
}
static ZstdCompressionReader* reader_enter(ZstdCompressionReader* self) {
- size_t zresult;
-
if (self->entered) {
PyErr_SetString(PyExc_ValueError, "cannot __enter__ multiple times");
return NULL;
}
- zresult = ZSTD_CCtx_setPledgedSrcSize(self->compressor->cctx, self->sourceSize);
- if (ZSTD_isError(zresult)) {
- PyErr_Format(ZstdError, "error setting source size: %s",
- ZSTD_getErrorName(zresult));
- return NULL;
- }
-
self->entered = 1;
Py_INCREF(self);
@@ -132,15 +123,6 @@
Py_RETURN_NONE;
}
-static PyObject* reader_closed(ZstdCompressionReader* self) {
- if (self->closed) {
- Py_RETURN_TRUE;
- }
- else {
- Py_RETURN_FALSE;
- }
-}
-
static PyObject* reader_tell(ZstdCompressionReader* self) {
/* TODO should this raise OSError since stream isn't seekable? */
return PyLong_FromUnsignedLongLong(self->bytesCompressed);
@@ -159,11 +141,6 @@
size_t zresult;
size_t oldPos;
- if (!self->entered) {
- PyErr_SetString(ZstdError, "read() must be called from an active context manager");
- return NULL;
- }
-
if (self->closed) {
PyErr_SetString(PyExc_ValueError, "stream is closed");
return NULL;
@@ -333,8 +310,6 @@
PyDoc_STR("Exit a compression context") },
{ "close", (PyCFunction)reader_close, METH_NOARGS,
PyDoc_STR("Close the stream so it cannot perform any more operations") },
- { "closed", (PyCFunction)reader_closed, METH_NOARGS,
- PyDoc_STR("Whether stream is closed") },
{ "flush", (PyCFunction)reader_flush, METH_NOARGS, PyDoc_STR("no-ops") },
{ "isatty", (PyCFunction)reader_isatty, METH_NOARGS, PyDoc_STR("Returns False") },
{ "readable", (PyCFunction)reader_readable, METH_NOARGS,
@@ -354,6 +329,12 @@
{ NULL, NULL }
};
+static PyMemberDef reader_members[] = {
+ { "closed", T_BOOL, offsetof(ZstdCompressionReader, closed),
+ READONLY, "whether stream is closed" },
+ { NULL }
+};
+
PyTypeObject ZstdCompressionReaderType = {
PyVarObject_HEAD_INIT(NULL, 0)
"zstd.ZstdCompressionReader", /* tp_name */
@@ -383,7 +364,7 @@
reader_iter, /* tp_iter */
reader_iternext, /* tp_iternext */
reader_methods, /* tp_methods */
- 0, /* tp_members */
+ reader_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */