Skip to content

Commit eebccac

Browse files
committed
add lock around result of PyMapping_Items
1 parent 2fe760b commit eebccac

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Modules/_json.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,21 +1600,26 @@ encoder_listencode_dict(PyEncoderObject *s, _PyUnicodeWriter *writer,
16001600
if (items == NULL || (s->sort_keys && PyList_Sort(items) < 0))
16011601
goto bail;
16021602

1603+
Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(items);
16031604
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(items); i++) {
16041605
PyObject *item = PyList_GET_ITEM(items, i);
16051606

16061607
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 2) {
16071608
PyErr_SetString(PyExc_ValueError, "items must return 2-tuples");
1609+
Py_EXIT_CRITICAL_SECTION_SEQUENCE_FAST();
16081610
goto bail;
16091611
}
16101612

16111613
key = PyTuple_GET_ITEM(item, 0);
16121614
value = PyTuple_GET_ITEM(item, 1);
16131615
if (encoder_encode_key_value(s, writer, &first, dct, key, value,
16141616
new_newline_indent,
1615-
current_item_separator) < 0)
1617+
current_item_separator) < 0) {
1618+
Py_EXIT_CRITICAL_SECTION_SEQUENCE_FAST();
16161619
goto bail;
1620+
}
16171621
}
1622+
Py_END_CRITICAL_SECTION_SEQUENCE_FAST(items);
16181623
Py_CLEAR(items);
16191624

16201625
} else {

0 commit comments

Comments
 (0)