Skip to content

Commit 2820a56

Browse files
serhiy-storchakaGlyphack
authored andcommitted
pythongh-111789: Use PyDict_GetItemRef() in Modules/pyexpat.c (pythongh-112079)
1 parent d61d45d commit 2820a56

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Modules/pyexpat.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,12 @@ string_intern(xmlparseobject *self, const char* str)
240240
return result;
241241
if (!self->intern)
242242
return result;
243-
value = PyDict_GetItemWithError(self->intern, result);
244-
if (!value) {
245-
if (!PyErr_Occurred() &&
246-
PyDict_SetItem(self->intern, result, result) == 0)
247-
{
248-
return result;
249-
}
250-
else {
251-
Py_DECREF(result);
252-
return NULL;
253-
}
243+
if (PyDict_GetItemRef(self->intern, result, &value) == 0 &&
244+
PyDict_SetItem(self->intern, result, result) == 0)
245+
{
246+
return result;
254247
}
255-
Py_INCREF(value);
248+
assert((value != NULL) == !PyErr_Occurred());
256249
Py_DECREF(result);
257250
return value;
258251
}

0 commit comments

Comments
 (0)