Skip to content

Commit bc861a6

Browse files
fix usage of Py_BEGIN_CRITICAL_SECTION
1 parent 4a9e55e commit bc861a6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Objects/codeobject.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,18 @@ static int
206206
intern_constants(PyObject *tuple, int *modified)
207207
{
208208
PyInterpreterState *interp = _PyInterpreterState_GET();
209-
// copypaste from unicodeobject.c
210209
PyObject *interned_dict = _Py_INTERP_CACHED_OBJECT(interp, interned_strings);
211-
Py_BEGIN_CRITICAL_SECTION(interned_dict);
212210
Py_INCREF(interned_dict);
213211
for (Py_ssize_t i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
214212
PyObject *v = PyTuple_GET_ITEM(tuple, i);
215213
if (PyUnicode_CheckExact(v) && PyUnicode_GET_LENGTH(v) > 1) {
216214
if (PyUnicode_CHECK_INTERNED(v) != 0) {
217215
continue;
218216
}
219-
PyObject *interned = PyDict_GetItemWithError(interned_dict, v);
217+
PyObject *interned;
218+
Py_BEGIN_CRITICAL_SECTION(interned_dict);
219+
interned = PyDict_GetItemWithError(interned_dict, v);
220+
Py_END_CRITICAL_SECTION();
220221
if (interned == NULL && PyErr_Occurred()) {
221222
goto error;
222223
}
@@ -327,12 +328,10 @@ intern_constants(PyObject *tuple, int *modified)
327328
}
328329
#endif
329330
}
330-
Py_END_CRITICAL_SECTION();
331331
Py_DECREF(interned_dict);
332332
return 0;
333333

334334
error:
335-
Py_END_CRITICAL_SECTION();
336335
Py_DECREF(interned_dict);
337336
return -1;
338337
}

0 commit comments

Comments
 (0)