Skip to content

Commit 4b25029

Browse files
committed
repr string building with mutex
1 parent ea212dd commit 4b25029

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
#include "dragon4.h"
1717

1818
#ifdef Py_GIL_DISABLED
19-
static PyMutex quad_creation_mutex = {0};
19+
static PyMutex scalar_mutex = {0};
2020
#endif
2121

2222
QuadPrecisionObject *
2323
QuadPrecision_raw_new(QuadBackendType backend)
2424
{
2525
QuadPrecisionObject *new;
2626
#ifdef Py_GIL_DISABLED
27-
PyMutex_Lock(&quad_creation_mutex);
27+
PyMutex_Lock(&scalar_mutex);
2828
#endif
2929
new = PyObject_New(QuadPrecisionObject, &QuadPrecision_Type);
3030
#ifdef Py_GIL_DISABLED
31-
PyMutex_Unlock(&quad_creation_mutex);
31+
PyMutex_Unlock(&scalar_mutex);
3232
#endif
3333

3434
if (!new)
@@ -196,13 +196,19 @@ QuadPrecision_str(QuadPrecisionObject *self)
196196
static PyObject *
197197
QuadPrecision_repr(QuadPrecisionObject *self)
198198
{
199+
#ifdef Py_GIL_DISABLED
200+
PyMutex_Lock(&scalar_mutex);
201+
#endif
199202
PyObject *str = QuadPrecision_str(self);
200203
if (str == NULL) {
201204
return NULL;
202205
}
203206
const char *backend_str = (self->backend == BACKEND_SLEEF) ? "sleef" : "longdouble";
204207
PyObject *res = PyUnicode_FromFormat("QuadPrecision('%S', backend='%s')", str, backend_str);
205208
Py_DECREF(str);
209+
#ifdef Py_GIL_DISABLED
210+
PyMutex_Unlock(&scalar_mutex);
211+
#endif
206212
return res;
207213
}
208214

0 commit comments

Comments
 (0)