Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release the GIL while compressing and decompressing #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/python-lz4.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ static PyObject *compress_with(compressor compress, PyObject *self, PyObject *ar
dest = PyBytes_AS_STRING(result);
store_le32(dest, source_size);
if (source_size > 0) {
int osize = compress(source, dest + hdr_size, source_size);
int osize = -1;
Py_BEGIN_ALLOW_THREADS
osize = compress(source, dest + hdr_size, source_size);
Py_END_ALLOW_THREADS
int actual_size = hdr_size + osize;
/* Resizes are expensive; tolerate some slop to avoid. */
if (actual_size < (dest_size / 4) * 3) {
Expand Down Expand Up @@ -115,7 +118,10 @@ static PyObject *py_lz4_uncompress(PyObject *self, PyObject *args) {
result = PyBytes_FromStringAndSize(NULL, dest_size);
if (result != NULL && dest_size > 0) {
char *dest = PyBytes_AS_STRING(result);
int osize = LZ4_decompress_safe(source + hdr_size, dest, source_size - hdr_size, dest_size);
int osize = -1;
Py_BEGIN_ALLOW_THREADS
osize = LZ4_decompress_safe(source + hdr_size, dest, source_size - hdr_size, dest_size);
Py_END_ALLOW_THREADS
if (osize < 0) {
PyErr_Format(PyExc_ValueError, "corrupt input at byte %d", -osize);
Py_CLEAR(result);
Expand Down