Skip to content

Commit 808b4ab

Browse files
committed
fix _PyCriticalSection_WarnIfNotHeld further
1 parent e455fc1 commit 808b4ab

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

Include/internal/pycore_critical_section.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ _PyCriticalSection2_BeginSlow(PyThreadState *tstate, PyCriticalSection2 *c, PyMu
9595
PyAPI_FUNC(void)
9696
_PyCriticalSection_SuspendAll(PyThreadState *tstate);
9797

98-
PyAPI_FUNC(void)
98+
int
9999
_PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message);
100100

101101
#ifdef Py_GIL_DISABLED

Modules/_collectionsmodule.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,12 +2263,11 @@ PyDoc_STRVAR(defdict_missing_doc,
22632263
static PyObject *
22642264
defdict_missing(PyObject *op, PyObject *key)
22652265
{
2266-
_PyCriticalSection_WarnIfNotHeld(
2267-
op,
2266+
if (_PyCriticalSection_WarnIfNotHeld(op,
22682267
"the defaultdict.__missing__ method should not be called directly; "
22692268
"use dd.pop(key, None) to safely trigger a reset to a default value "
2270-
"the next time key is accessed"
2271-
);
2269+
"the next time key is accessed") < 0)
2270+
return NULL;
22722271
defdictobject *dd = defdictobject_CAST(op);
22732272
PyObject *factory = dd->default_factory;
22742273
PyObject *value;

Python/critical_section.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ PyCriticalSection2_End(PyCriticalSection2 *c)
202202
#endif
203203
}
204204

205-
void
205+
int
206206
_PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message)
207207
{
208208
#ifdef Py_GIL_DISABLED
@@ -212,12 +212,13 @@ _PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message)
212212
if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES) {
213213
PyCriticalSection2 *cs = (PyCriticalSection2 *)(prev & ~_Py_CRITICAL_SECTION_MASK);
214214
if (cs == NULL || (cs->_cs_base._cs_mutex != mutex && cs->_cs_mutex2 != mutex))
215-
PyErr_WarnEx(NULL, message, 2);
215+
return PyErr_WarnEx(NULL, message, 2);
216216
}
217217
else {
218218
PyCriticalSection *cs = (PyCriticalSection *)(prev & ~_Py_CRITICAL_SECTION_MASK);
219219
if (cs == NULL || cs->_cs_mutex != mutex)
220-
PyErr_WarnEx(NULL, message, 2);
220+
return PyErr_WarnEx(NULL, message, 2);
221221
}
222222
#endif
223+
return 0;
223224
}

0 commit comments

Comments
 (0)