summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2026-02-07 19:56:35 +0300
committershadchin <[email protected]>2026-02-07 20:23:53 +0300
commit19d43a3e6fb4cb8ea11747d7d7bca7a3542fbb44 (patch)
tree0b1418938140a0b6470953bef6069454ffdf1bd0 /contrib/tools/python3/Modules/_collectionsmodule.c
parent0879409bfc0891ab8103828a3bdbf0e960475fec (diff)
Update Python 3 to 3.13.12
commit_hash:71d3efea437a769b2b7910d196120bb02587046e
Diffstat (limited to 'contrib/tools/python3/Modules/_collectionsmodule.c')
-rw-r--r--contrib/tools/python3/Modules/_collectionsmodule.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/contrib/tools/python3/Modules/_collectionsmodule.c b/contrib/tools/python3/Modules/_collectionsmodule.c
index 2c30e5c70a6..f5fc0d02a16 100644
--- a/contrib/tools/python3/Modules/_collectionsmodule.c
+++ b/contrib/tools/python3/Modules/_collectionsmodule.c
@@ -2203,11 +2203,11 @@ defdict_missing(defdictobject *dd, PyObject *key)
value = _PyObject_CallNoArgs(factory);
if (value == NULL)
return value;
- if (PyObject_SetItem((PyObject *)dd, key, value) < 0) {
- Py_DECREF(value);
- return NULL;
- }
- return value;
+ PyObject *result = NULL;
+ (void)PyDict_SetDefaultRef((PyObject *)dd, key, value, &result);
+ // 'result' is NULL, or a strong reference to 'value' or 'dd[key]'
+ Py_DECREF(value);
+ return result;
}
static inline PyObject*
@@ -2549,7 +2549,12 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0)
goto done;
} else {
+ /* oldval is a borrowed reference. Keep it alive across
+ PyNumber_Add(), which can execute arbitrary user code and
+ mutate (or even clear) the underlying dict. */
+ Py_INCREF(oldval);
newval = PyNumber_Add(oldval, one);
+ Py_DECREF(oldval);
if (newval == NULL)
goto done;
if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0)