Mercurial > public > mercurial-scm > hg
diff contrib/python-zstandard/c-ext/compressionreader.c @ 40121:73fef626dae3
zstandard: vendor python-zstandard 0.10.1
This was just released.
The upstream source distribution from PyPI was extracted. Unwanted
files were removed.
The clang-format ignore list was updated to reflect the new source
of files.
setup.py was updated to pass a new argument to python-zstandard's
function for returning an Extension instance. Upstream had to change
to use relative paths because Python 3.7's packaging doesn't
seem to like absolute paths when defining sources, includes, etc.
The default relative path calculation is relative to setup_zstd.py
which is different from the directory of Mercurial's setup.py.
The project contains a vendored copy of zstandard 1.3.6. The old
version was 1.3.4.
The API should be backwards compatible and nothing in core should
need adjusted. However, there is a new "chunker" API that we
may find useful in places where we want to emit compressed chunks
of a fixed size.
There are a pair of bug fixes in 0.10.0 with regards to
compressobj() and decompressobj() when block flushing is used. I
actually found these bugs when introducing these APIs in Mercurial!
But existing Mercurial code is not affected because we don't
perform block flushing.
# no-check-commit because 3rd party code has different style guidelines
Differential Revision: https://phab.mercurial-scm.org/D4911
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 08 Oct 2018 16:27:40 -0700 |
parents | b1fb341d8a61 |
children | 675775c33ab6 |
line wrap: on
line diff
--- 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 */