Skip to content

Commit 5362112

Browse files
committed
gh-116738: Keep the macros
1 parent c46e975 commit 5362112

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Modules/_bz2module.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ OutputBuffer_OnError(_BlocksOutputBuffer *buffer)
9696
#define BZ2_bzDecompressEnd bzDecompressEnd
9797
#endif /* ! BZ_CONFIG_ERROR */
9898

99+
#define ACQUIRE_LOCK(obj) PyMutex_Lock(&(obj)->mutex)
100+
#define RELEASE_LOCK(obj) PyMutex_Unlock(&(obj)->mutex)
101+
99102

100103
typedef struct {
101104
PyObject_HEAD
@@ -262,12 +265,12 @@ _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data)
262265
{
263266
PyObject *result = NULL;
264267

265-
PyMutex_Lock(&self->mutex);
268+
ACQUIRE_LOCK(self);
266269
if (self->flushed)
267270
PyErr_SetString(PyExc_ValueError, "Compressor has been flushed");
268271
else
269272
result = compress(self, data->buf, data->len, BZ_RUN);
270-
PyMutex_Unlock(&self->mutex);
273+
RELEASE_LOCK(self);
271274
return result;
272275
}
273276

@@ -287,14 +290,14 @@ _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self)
287290
{
288291
PyObject *result = NULL;
289292

290-
PyMutex_Lock(&self->mutex);
293+
ACQUIRE_LOCK(self);
291294
if (self->flushed)
292295
PyErr_SetString(PyExc_ValueError, "Repeated call to flush()");
293296
else {
294297
self->flushed = 1;
295298
result = compress(self, NULL, 0, BZ_FINISH);
296299
}
297-
PyMutex_Unlock(&self->mutex);
300+
RELEASE_LOCK(self);
298301
return result;
299302
}
300303

@@ -601,12 +604,12 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
601604
{
602605
PyObject *result = NULL;
603606

604-
PyMutex_Lock(&self->mutex);
607+
ACQUIRE_LOCK(self);
605608
if (self->eof)
606609
PyErr_SetString(PyExc_EOFError, "End of stream already reached");
607610
else
608611
result = decompress(self, data->buf, data->len, max_length);
609-
PyMutex_Unlock(&self->mutex);
612+
RELEASE_LOCK(self);
610613
return result;
611614
}
612615

0 commit comments

Comments
 (0)