Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
37494:1ce7a55b09d1 | 37495:b1fb341d8a61 |
---|---|
18 | 18 |
19 static void ZstdDecompressorIterator_dealloc(ZstdDecompressorIterator* self) { | 19 static void ZstdDecompressorIterator_dealloc(ZstdDecompressorIterator* self) { |
20 Py_XDECREF(self->decompressor); | 20 Py_XDECREF(self->decompressor); |
21 Py_XDECREF(self->reader); | 21 Py_XDECREF(self->reader); |
22 | 22 |
23 if (self->buffer) { | 23 if (self->buffer.buf) { |
24 PyBuffer_Release(self->buffer); | 24 PyBuffer_Release(&self->buffer); |
25 PyMem_FREE(self->buffer); | 25 memset(&self->buffer, 0, sizeof(self->buffer)); |
26 self->buffer = NULL; | |
27 } | 26 } |
28 | 27 |
29 if (self->input.src) { | 28 if (self->input.src) { |
30 PyMem_Free((void*)self->input.src); | 29 PyMem_Free((void*)self->input.src); |
31 self->input.src = NULL; | 30 self->input.src = NULL; |
43 size_t zresult; | 42 size_t zresult; |
44 PyObject* chunk; | 43 PyObject* chunk; |
45 DecompressorIteratorResult result; | 44 DecompressorIteratorResult result; |
46 size_t oldInputPos = self->input.pos; | 45 size_t oldInputPos = self->input.pos; |
47 | 46 |
48 assert(self->decompressor->dstream); | |
49 | |
50 result.chunk = NULL; | 47 result.chunk = NULL; |
51 | 48 |
52 chunk = PyBytes_FromStringAndSize(NULL, self->outSize); | 49 chunk = PyBytes_FromStringAndSize(NULL, self->outSize); |
53 if (!chunk) { | 50 if (!chunk) { |
54 result.errored = 1; | 51 result.errored = 1; |
58 self->output.dst = PyBytes_AsString(chunk); | 55 self->output.dst = PyBytes_AsString(chunk); |
59 self->output.size = self->outSize; | 56 self->output.size = self->outSize; |
60 self->output.pos = 0; | 57 self->output.pos = 0; |
61 | 58 |
62 Py_BEGIN_ALLOW_THREADS | 59 Py_BEGIN_ALLOW_THREADS |
63 zresult = ZSTD_decompressStream(self->decompressor->dstream, &self->output, &self->input); | 60 zresult = ZSTD_decompress_generic(self->decompressor->dctx, &self->output, &self->input); |
64 Py_END_ALLOW_THREADS | 61 Py_END_ALLOW_THREADS |
65 | 62 |
66 /* We're done with the pointer. Nullify to prevent anyone from getting a | 63 /* We're done with the pointer. Nullify to prevent anyone from getting a |
67 handle on a Python object. */ | 64 handle on a Python object. */ |
68 self->output.dst = NULL; | 65 self->output.dst = NULL; |
84 } | 81 } |
85 | 82 |
86 /* If it produced output data, return it. */ | 83 /* If it produced output data, return it. */ |
87 if (self->output.pos) { | 84 if (self->output.pos) { |
88 if (self->output.pos < self->outSize) { | 85 if (self->output.pos < self->outSize) { |
89 if (_PyBytes_Resize(&chunk, self->output.pos)) { | 86 if (safe_pybytes_resize(&chunk, self->output.pos)) { |
87 Py_XDECREF(chunk); | |
90 result.errored = 1; | 88 result.errored = 1; |
91 return result; | 89 return result; |
92 } | 90 } |
93 } | 91 } |
94 } | 92 } |
135 } | 133 } |
136 | 134 |
137 PyBytes_AsStringAndSize(readResult, &readBuffer, &readSize); | 135 PyBytes_AsStringAndSize(readResult, &readBuffer, &readSize); |
138 } | 136 } |
139 else { | 137 else { |
140 assert(self->buffer && self->buffer->buf); | 138 assert(self->buffer.buf); |
141 | 139 |
142 /* Only support contiguous C arrays for now */ | 140 /* Only support contiguous C arrays for now */ |
143 assert(self->buffer->strides == NULL && self->buffer->suboffsets == NULL); | 141 assert(self->buffer.strides == NULL && self->buffer.suboffsets == NULL); |
144 assert(self->buffer->itemsize == 1); | 142 assert(self->buffer.itemsize == 1); |
145 | 143 |
146 /* TODO avoid memcpy() below */ | 144 /* TODO avoid memcpy() below */ |
147 readBuffer = (char *)self->buffer->buf + self->bufferOffset; | 145 readBuffer = (char *)self->buffer.buf + self->bufferOffset; |
148 bufferRemaining = self->buffer->len - self->bufferOffset; | 146 bufferRemaining = self->buffer.len - self->bufferOffset; |
149 readSize = min(bufferRemaining, (Py_ssize_t)self->inSize); | 147 readSize = min(bufferRemaining, (Py_ssize_t)self->inSize); |
150 self->bufferOffset += readSize; | 148 self->bufferOffset += readSize; |
151 } | 149 } |
152 | 150 |
153 if (readSize) { | 151 if (readSize) { |