Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,17 +1808,18 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
}

if (s->markers != Py_None) {
int has_key;
ident = PyLong_FromVoidPtr(dct);
if (ident == NULL)
goto bail;
has_key = PyDict_Contains(s->markers, ident);
if (has_key) {
if (has_key != -1)
PyErr_SetString(PyExc_ValueError, "Circular reference detected");
PyObject *existing = NULL;
int res = PyDict_SetDefaultRef(s->markers, ident, dct, &existing);
if (res < 0) {
goto bail;
}
if (PyDict_SetItem(s->markers, ident, dct)) {
Py_DECREF(existing);
if (res > 0) {
/* The key was already present: circular reference. */
PyErr_SetString(PyExc_ValueError, "Circular reference detected");
goto bail;
}
}
Expand Down Expand Up @@ -1928,17 +1929,18 @@ encoder_listencode_list(PyEncoderObject *s, PyUnicodeWriter *writer,
}

if (s->markers != Py_None) {
int has_key;
ident = PyLong_FromVoidPtr(seq);
if (ident == NULL)
goto bail;
has_key = PyDict_Contains(s->markers, ident);
if (has_key) {
if (has_key != -1)
PyErr_SetString(PyExc_ValueError, "Circular reference detected");
PyObject *existing = NULL;
int res = PyDict_SetDefaultRef(s->markers, ident, seq, &existing);
if (res < 0) {
goto bail;
}
if (PyDict_SetItem(s->markers, ident, seq)) {
Py_DECREF(existing);
if (res > 0) {
/* The key was already present: circular reference. */
PyErr_SetString(PyExc_ValueError, "Circular reference detected");
goto bail;
}
}
Expand Down
Loading