Skip to content

Commit

Permalink
decompressionwriter: use goto for control flow in write()
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Jun 11, 2017
1 parent ae9405a commit a7bc1c0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions c-ext/decompressionwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static PyObject* ZstdDecompressionWriter_memory_size(ZstdDecompressionWriter* se
}

static PyObject* ZstdDecompressionWriter_write(ZstdDecompressionWriter* self, PyObject* args) {
PyObject* result = NULL;
const char* source;
Py_ssize_t sourceSize;
size_t zresult = 0;
Expand All @@ -72,14 +73,15 @@ static PyObject* ZstdDecompressionWriter_write(ZstdDecompressionWriter* self, Py

if (!self->entered) {
PyErr_SetString(ZstdError, "write must be called from an active context manager");
return NULL;
goto finally;
}

assert(self->decompressor->dstream);

output.dst = PyMem_Malloc(self->outSize);
if (!output.dst) {
return PyErr_NoMemory();
PyErr_NoMemory();
goto finally;
}
output.size = self->outSize;
output.pos = 0;
Expand All @@ -97,7 +99,7 @@ static PyObject* ZstdDecompressionWriter_write(ZstdDecompressionWriter* self, Py
PyMem_Free(output.dst);
PyErr_Format(ZstdError, "zstd decompress error: %s",
ZSTD_getErrorName(zresult));
return NULL;
goto finally;
}

if (output.pos) {
Expand All @@ -115,7 +117,10 @@ static PyObject* ZstdDecompressionWriter_write(ZstdDecompressionWriter* self, Py

PyMem_Free(output.dst);

return PyLong_FromSsize_t(totalWrite);
result = PyLong_FromSsize_t(totalWrite);

finally:
return result;
}

static PyMethodDef ZstdDecompressionWriter_methods[] = {
Expand Down

0 comments on commit a7bc1c0

Please sign in to comment.