contrib/python-zstandard/c-ext/compressoriterator.c
changeset 31796 e0dc40530c5a
parent 30435 b86a448a2965
child 37495 b1fb341d8a61
equal deleted inserted replaced
31795:2b130e26c3a4 31796:e0dc40530c5a
    25 		PyBuffer_Release(self->buffer);
    25 		PyBuffer_Release(self->buffer);
    26 		PyMem_FREE(self->buffer);
    26 		PyMem_FREE(self->buffer);
    27 		self->buffer = NULL;
    27 		self->buffer = NULL;
    28 	}
    28 	}
    29 
    29 
    30 	if (self->cstream) {
       
    31 		ZSTD_freeCStream(self->cstream);
       
    32 		self->cstream = NULL;
       
    33 	}
       
    34 
       
    35 	if (self->output.dst) {
    30 	if (self->output.dst) {
    36 		PyMem_Free(self->output.dst);
    31 		PyMem_Free(self->output.dst);
    37 		self->output.dst = NULL;
    32 		self->output.dst = NULL;
    38 	}
    33 	}
    39 
    34 
    61 feedcompressor:
    56 feedcompressor:
    62 
    57 
    63 	/* If we have data left in the input, consume it. */
    58 	/* If we have data left in the input, consume it. */
    64 	if (self->input.pos < self->input.size) {
    59 	if (self->input.pos < self->input.size) {
    65 		Py_BEGIN_ALLOW_THREADS
    60 		Py_BEGIN_ALLOW_THREADS
    66 		zresult = ZSTD_compressStream(self->cstream, &self->output, &self->input);
    61 		if (self->compressor->mtcctx) {
       
    62 			zresult = ZSTDMT_compressStream(self->compressor->mtcctx,
       
    63 				&self->output, &self->input);
       
    64 		}
       
    65 		else {
       
    66 			zresult = ZSTD_compressStream(self->compressor->cstream, &self->output,
       
    67 				&self->input);
       
    68 		}
    67 		Py_END_ALLOW_THREADS
    69 		Py_END_ALLOW_THREADS
    68 
    70 
    69 		/* Release the Python object holding the input buffer. */
    71 		/* Release the Python object holding the input buffer. */
    70 		if (self->input.pos == self->input.size) {
    72 		if (self->input.pos == self->input.size) {
    71 			self->input.src = NULL;
    73 			self->input.src = NULL;
   126 		}
   128 		}
   127 	}
   129 	}
   128 
   130 
   129 	/* EOF */
   131 	/* EOF */
   130 	if (0 == readSize) {
   132 	if (0 == readSize) {
   131 		zresult = ZSTD_endStream(self->cstream, &self->output);
   133 		if (self->compressor->mtcctx) {
       
   134 			zresult = ZSTDMT_endStream(self->compressor->mtcctx, &self->output);
       
   135 		}
       
   136 		else {
       
   137 			zresult = ZSTD_endStream(self->compressor->cstream, &self->output);
       
   138 		}
   132 		if (ZSTD_isError(zresult)) {
   139 		if (ZSTD_isError(zresult)) {
   133 			PyErr_Format(ZstdError, "error ending compression stream: %s",
   140 			PyErr_Format(ZstdError, "error ending compression stream: %s",
   134 				ZSTD_getErrorName(zresult));
   141 				ZSTD_getErrorName(zresult));
   135 			return NULL;
   142 			return NULL;
   136 		}
   143 		}
   150 	self->input.src = readBuffer;
   157 	self->input.src = readBuffer;
   151 	self->input.size = readSize;
   158 	self->input.size = readSize;
   152 	self->input.pos = 0;
   159 	self->input.pos = 0;
   153 
   160 
   154 	Py_BEGIN_ALLOW_THREADS
   161 	Py_BEGIN_ALLOW_THREADS
   155 	zresult = ZSTD_compressStream(self->cstream, &self->output, &self->input);
   162 	if (self->compressor->mtcctx) {
       
   163 		zresult = ZSTDMT_compressStream(self->compressor->mtcctx, &self->output,
       
   164 			&self->input);
       
   165 	}
       
   166 	else {
       
   167 		zresult = ZSTD_compressStream(self->compressor->cstream, &self->output, &self->input);
       
   168 	}
   156 	Py_END_ALLOW_THREADS
   169 	Py_END_ALLOW_THREADS
   157 
   170 
   158 	/* The input buffer currently points to memory managed by Python
   171 	/* The input buffer currently points to memory managed by Python
   159 	(readBuffer). This object was allocated by this function. If it wasn't
   172 	(readBuffer). This object was allocated by this function. If it wasn't
   160 	fully consumed, we need to release it in a subsequent function call.
   173 	fully consumed, we need to release it in a subsequent function call.