Mercurial > hg
diff contrib/python-zstandard/c-ext/decompressoriterator.c @ 37495:b1fb341d8a61
zstandard: vendor python-zstandard 0.9.0
This was just released. It features a number of goodies. More info at
https://gregoryszorc.com/blog/2018/04/09/release-of-python-zstandard-0.9/.
The clang-format ignore list was updated to reflect the new source
of files.
The project contains a vendored copy of zstandard 1.3.4. The old
version was 1.1.3. One of the changes between those versions is that
zstandard is now dual licensed BSD + GPLv2 and the patent rights grant
has been removed. Good riddance.
The API should be backwards compatible. So no changes in core
should be needed. However, there were a number of changes in the
library that we'll want to adapt to. Those will be addressed in
subsequent commits.
Differential Revision: https://phab.mercurial-scm.org/D3198
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 09 Apr 2018 10:13:29 -0700 |
parents | e0dc40530c5a |
children | 675775c33ab6 |
line wrap: on
line diff
--- a/contrib/python-zstandard/c-ext/decompressoriterator.c Sun Apr 08 01:08:43 2018 +0200 +++ b/contrib/python-zstandard/c-ext/decompressoriterator.c Mon Apr 09 10:13:29 2018 -0700 @@ -20,10 +20,9 @@ Py_XDECREF(self->decompressor); Py_XDECREF(self->reader); - if (self->buffer) { - PyBuffer_Release(self->buffer); - PyMem_FREE(self->buffer); - self->buffer = NULL; + if (self->buffer.buf) { + PyBuffer_Release(&self->buffer); + memset(&self->buffer, 0, sizeof(self->buffer)); } if (self->input.src) { @@ -45,8 +44,6 @@ DecompressorIteratorResult result; size_t oldInputPos = self->input.pos; - assert(self->decompressor->dstream); - result.chunk = NULL; chunk = PyBytes_FromStringAndSize(NULL, self->outSize); @@ -60,7 +57,7 @@ self->output.pos = 0; Py_BEGIN_ALLOW_THREADS - zresult = ZSTD_decompressStream(self->decompressor->dstream, &self->output, &self->input); + zresult = ZSTD_decompress_generic(self->decompressor->dctx, &self->output, &self->input); Py_END_ALLOW_THREADS /* We're done with the pointer. Nullify to prevent anyone from getting a @@ -86,7 +83,8 @@ /* If it produced output data, return it. */ if (self->output.pos) { if (self->output.pos < self->outSize) { - if (_PyBytes_Resize(&chunk, self->output.pos)) { + if (safe_pybytes_resize(&chunk, self->output.pos)) { + Py_XDECREF(chunk); result.errored = 1; return result; } @@ -137,15 +135,15 @@ PyBytes_AsStringAndSize(readResult, &readBuffer, &readSize); } else { - assert(self->buffer && self->buffer->buf); + assert(self->buffer.buf); /* Only support contiguous C arrays for now */ - assert(self->buffer->strides == NULL && self->buffer->suboffsets == NULL); - assert(self->buffer->itemsize == 1); + assert(self->buffer.strides == NULL && self->buffer.suboffsets == NULL); + assert(self->buffer.itemsize == 1); /* TODO avoid memcpy() below */ - readBuffer = (char *)self->buffer->buf + self->bufferOffset; - bufferRemaining = self->buffer->len - self->bufferOffset; + readBuffer = (char *)self->buffer.buf + self->bufferOffset; + bufferRemaining = self->buffer.len - self->bufferOffset; readSize = min(bufferRemaining, (Py_ssize_t)self->inSize); self->bufferOffset += readSize; }