equal
deleted
inserted
replaced
13 PyDoc_STRVAR(DecompressionObj__doc__, |
13 PyDoc_STRVAR(DecompressionObj__doc__, |
14 "Perform decompression using a standard library compatible API.\n" |
14 "Perform decompression using a standard library compatible API.\n" |
15 ); |
15 ); |
16 |
16 |
17 static void DecompressionObj_dealloc(ZstdDecompressionObj* self) { |
17 static void DecompressionObj_dealloc(ZstdDecompressionObj* self) { |
18 if (self->dstream) { |
|
19 ZSTD_freeDStream(self->dstream); |
|
20 self->dstream = NULL; |
|
21 } |
|
22 |
|
23 Py_XDECREF(self->decompressor); |
18 Py_XDECREF(self->decompressor); |
24 |
19 |
25 PyObject_Del(self); |
20 PyObject_Del(self); |
26 } |
21 } |
27 |
22 |
32 ZSTD_inBuffer input; |
27 ZSTD_inBuffer input; |
33 ZSTD_outBuffer output; |
28 ZSTD_outBuffer output; |
34 size_t outSize = ZSTD_DStreamOutSize(); |
29 size_t outSize = ZSTD_DStreamOutSize(); |
35 PyObject* result = NULL; |
30 PyObject* result = NULL; |
36 Py_ssize_t resultSize = 0; |
31 Py_ssize_t resultSize = 0; |
|
32 |
|
33 /* Constructor should ensure stream is populated. */ |
|
34 assert(self->decompressor->dstream); |
37 |
35 |
38 if (self->finished) { |
36 if (self->finished) { |
39 PyErr_SetString(ZstdError, "cannot use a decompressobj multiple times"); |
37 PyErr_SetString(ZstdError, "cannot use a decompressobj multiple times"); |
40 return NULL; |
38 return NULL; |
41 } |
39 } |
62 output.pos = 0; |
60 output.pos = 0; |
63 |
61 |
64 /* Read input until exhausted. */ |
62 /* Read input until exhausted. */ |
65 while (input.pos < input.size) { |
63 while (input.pos < input.size) { |
66 Py_BEGIN_ALLOW_THREADS |
64 Py_BEGIN_ALLOW_THREADS |
67 zresult = ZSTD_decompressStream(self->dstream, &output, &input); |
65 zresult = ZSTD_decompressStream(self->decompressor->dstream, &output, &input); |
68 Py_END_ALLOW_THREADS |
66 Py_END_ALLOW_THREADS |
69 |
67 |
70 if (ZSTD_isError(zresult)) { |
68 if (ZSTD_isError(zresult)) { |
71 PyErr_Format(ZstdError, "zstd decompressor error: %s", |
69 PyErr_Format(ZstdError, "zstd decompressor error: %s", |
72 ZSTD_getErrorName(zresult)); |
70 ZSTD_getErrorName(zresult)); |
104 } |
102 } |
105 |
103 |
106 goto finally; |
104 goto finally; |
107 |
105 |
108 except: |
106 except: |
109 Py_DecRef(result); |
107 Py_CLEAR(result); |
110 result = NULL; |
|
111 |
108 |
112 finally: |
109 finally: |
113 PyMem_Free(output.dst); |
110 PyMem_Free(output.dst); |
114 |
111 |
115 return result; |
112 return result; |