Skip to content

Commit f02ff5a

Browse files
committed
Move bytes operations out of Py_BEGIN_ALLOW_THREADS
1 parent e825285 commit f02ff5a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Modules/_zstd/_zstdmodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ _zstd__train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
250250
}
251251

252252
/* Train the dictionary */
253+
char *dst_dict_buffer = PyBytes_AS_STRING(dst_dict_bytes);
254+
char *samples_buffer = PyBytes_AS_STRING(samples_bytes);
253255
Py_BEGIN_ALLOW_THREADS
254-
zstd_ret = ZDICT_trainFromBuffer(PyBytes_AS_STRING(dst_dict_bytes), dict_size,
255-
PyBytes_AS_STRING(samples_bytes),
256+
zstd_ret = ZDICT_trainFromBuffer(dst_dict_buffer, dict_size,
257+
samples_buffer,
256258
chunk_sizes, (uint32_t)chunks_number);
257259
Py_END_ALLOW_THREADS
258260

Modules/_zstd/compressor.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ _get_CDict(ZstdDict *self, int compressionLevel)
151151
}
152152

153153
/* Create ZSTD_CDict instance */
154+
char *dict_buffer = PyBytes_AS_STRING(self->dict_content);
155+
Py_ssize_t dict_len = Py_SIZE(self->dict_content);
154156
Py_BEGIN_ALLOW_THREADS
155-
cdict = ZSTD_createCDict(PyBytes_AS_STRING(self->dict_content),
156-
Py_SIZE(self->dict_content), compressionLevel);
157+
cdict = ZSTD_createCDict(dict_buffer,
158+
dict_len,
159+
compressionLevel);
157160
Py_END_ALLOW_THREADS
158161

159162
if (cdict == NULL) {

Modules/_zstd/decompressor.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ _get_DDict(ZstdDict *self)
3636
Py_BEGIN_CRITICAL_SECTION(self);
3737
if (self->d_dict == NULL) {
3838
/* Create ZSTD_DDict instance from dictionary content */
39+
char *dict_buffer = PyBytes_AS_STRING(self->dict_content);
40+
Py_ssize_t dict_len = Py_SIZE(self->dict_content);
3941
Py_BEGIN_ALLOW_THREADS
40-
self->d_dict = ZSTD_createDDict(PyBytes_AS_STRING(self->dict_content),
41-
Py_SIZE(self->dict_content));
42+
self->d_dict = ZSTD_createDDict(dict_buffer,
43+
dict_len);
4244
Py_END_ALLOW_THREADS
4345

4446
if (self->d_dict == NULL) {

0 commit comments

Comments
 (0)