Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
40120:89742f1fa6cb | 40121:73fef626dae3 |
---|---|
41 | 41 |
42 PyObject_Del(self); | 42 PyObject_Del(self); |
43 } | 43 } |
44 | 44 |
45 static ZstdCompressionReader* reader_enter(ZstdCompressionReader* self) { | 45 static ZstdCompressionReader* reader_enter(ZstdCompressionReader* self) { |
46 size_t zresult; | |
47 | |
48 if (self->entered) { | 46 if (self->entered) { |
49 PyErr_SetString(PyExc_ValueError, "cannot __enter__ multiple times"); | 47 PyErr_SetString(PyExc_ValueError, "cannot __enter__ multiple times"); |
50 return NULL; | |
51 } | |
52 | |
53 zresult = ZSTD_CCtx_setPledgedSrcSize(self->compressor->cctx, self->sourceSize); | |
54 if (ZSTD_isError(zresult)) { | |
55 PyErr_Format(ZstdError, "error setting source size: %s", | |
56 ZSTD_getErrorName(zresult)); | |
57 return NULL; | 48 return NULL; |
58 } | 49 } |
59 | 50 |
60 self->entered = 1; | 51 self->entered = 1; |
61 | 52 |
128 } | 119 } |
129 | 120 |
130 static PyObject* reader_close(ZstdCompressionReader* self) { | 121 static PyObject* reader_close(ZstdCompressionReader* self) { |
131 self->closed = 1; | 122 self->closed = 1; |
132 Py_RETURN_NONE; | 123 Py_RETURN_NONE; |
133 } | |
134 | |
135 static PyObject* reader_closed(ZstdCompressionReader* self) { | |
136 if (self->closed) { | |
137 Py_RETURN_TRUE; | |
138 } | |
139 else { | |
140 Py_RETURN_FALSE; | |
141 } | |
142 } | 124 } |
143 | 125 |
144 static PyObject* reader_tell(ZstdCompressionReader* self) { | 126 static PyObject* reader_tell(ZstdCompressionReader* self) { |
145 /* TODO should this raise OSError since stream isn't seekable? */ | 127 /* TODO should this raise OSError since stream isn't seekable? */ |
146 return PyLong_FromUnsignedLongLong(self->bytesCompressed); | 128 return PyLong_FromUnsignedLongLong(self->bytesCompressed); |
156 PyObject* result = NULL; | 138 PyObject* result = NULL; |
157 char* resultBuffer; | 139 char* resultBuffer; |
158 Py_ssize_t resultSize; | 140 Py_ssize_t resultSize; |
159 size_t zresult; | 141 size_t zresult; |
160 size_t oldPos; | 142 size_t oldPos; |
161 | |
162 if (!self->entered) { | |
163 PyErr_SetString(ZstdError, "read() must be called from an active context manager"); | |
164 return NULL; | |
165 } | |
166 | 143 |
167 if (self->closed) { | 144 if (self->closed) { |
168 PyErr_SetString(PyExc_ValueError, "stream is closed"); | 145 PyErr_SetString(PyExc_ValueError, "stream is closed"); |
169 return NULL; | 146 return NULL; |
170 } | 147 } |
331 PyDoc_STR("Enter a compression context") }, | 308 PyDoc_STR("Enter a compression context") }, |
332 { "__exit__", (PyCFunction)reader_exit, METH_VARARGS, | 309 { "__exit__", (PyCFunction)reader_exit, METH_VARARGS, |
333 PyDoc_STR("Exit a compression context") }, | 310 PyDoc_STR("Exit a compression context") }, |
334 { "close", (PyCFunction)reader_close, METH_NOARGS, | 311 { "close", (PyCFunction)reader_close, METH_NOARGS, |
335 PyDoc_STR("Close the stream so it cannot perform any more operations") }, | 312 PyDoc_STR("Close the stream so it cannot perform any more operations") }, |
336 { "closed", (PyCFunction)reader_closed, METH_NOARGS, | |
337 PyDoc_STR("Whether stream is closed") }, | |
338 { "flush", (PyCFunction)reader_flush, METH_NOARGS, PyDoc_STR("no-ops") }, | 313 { "flush", (PyCFunction)reader_flush, METH_NOARGS, PyDoc_STR("no-ops") }, |
339 { "isatty", (PyCFunction)reader_isatty, METH_NOARGS, PyDoc_STR("Returns False") }, | 314 { "isatty", (PyCFunction)reader_isatty, METH_NOARGS, PyDoc_STR("Returns False") }, |
340 { "readable", (PyCFunction)reader_readable, METH_NOARGS, | 315 { "readable", (PyCFunction)reader_readable, METH_NOARGS, |
341 PyDoc_STR("Returns True") }, | 316 PyDoc_STR("Returns True") }, |
342 { "read", (PyCFunction)reader_read, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("read compressed data") }, | 317 { "read", (PyCFunction)reader_read, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("read compressed data") }, |
350 { "writable", (PyCFunction)reader_writable, METH_NOARGS, | 325 { "writable", (PyCFunction)reader_writable, METH_NOARGS, |
351 PyDoc_STR("Returns False") }, | 326 PyDoc_STR("Returns False") }, |
352 { "write", reader_write, METH_VARARGS, PyDoc_STR("Raises OSError") }, | 327 { "write", reader_write, METH_VARARGS, PyDoc_STR("Raises OSError") }, |
353 { "writelines", reader_writelines, METH_VARARGS, PyDoc_STR("Not implemented") }, | 328 { "writelines", reader_writelines, METH_VARARGS, PyDoc_STR("Not implemented") }, |
354 { NULL, NULL } | 329 { NULL, NULL } |
330 }; | |
331 | |
332 static PyMemberDef reader_members[] = { | |
333 { "closed", T_BOOL, offsetof(ZstdCompressionReader, closed), | |
334 READONLY, "whether stream is closed" }, | |
335 { NULL } | |
355 }; | 336 }; |
356 | 337 |
357 PyTypeObject ZstdCompressionReaderType = { | 338 PyTypeObject ZstdCompressionReaderType = { |
358 PyVarObject_HEAD_INIT(NULL, 0) | 339 PyVarObject_HEAD_INIT(NULL, 0) |
359 "zstd.ZstdCompressionReader", /* tp_name */ | 340 "zstd.ZstdCompressionReader", /* tp_name */ |
381 0, /* tp_richcompare */ | 362 0, /* tp_richcompare */ |
382 0, /* tp_weaklistoffset */ | 363 0, /* tp_weaklistoffset */ |
383 reader_iter, /* tp_iter */ | 364 reader_iter, /* tp_iter */ |
384 reader_iternext, /* tp_iternext */ | 365 reader_iternext, /* tp_iternext */ |
385 reader_methods, /* tp_methods */ | 366 reader_methods, /* tp_methods */ |
386 0, /* tp_members */ | 367 reader_members, /* tp_members */ |
387 0, /* tp_getset */ | 368 0, /* tp_getset */ |
388 0, /* tp_base */ | 369 0, /* tp_base */ |
389 0, /* tp_dict */ | 370 0, /* tp_dict */ |
390 0, /* tp_descr_get */ | 371 0, /* tp_descr_get */ |
391 0, /* tp_descr_set */ | 372 0, /* tp_descr_set */ |