gh-99300: Replace Py_INCREF() with Py_NewRef() (#99530)

Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef()
and Py_XNewRef().
This commit is contained in:
Victor Stinner 2022-11-16 18:34:24 +01:00 committed by GitHub
parent 19c1462e8d
commit 8211cf5d28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 40 additions and 74 deletions

View file

@ -1883,13 +1883,11 @@ _PyDict_SetItem_KnownHash(PyObject *op, PyObject *key, PyObject *value,
assert(hash != -1);
mp = (PyDictObject *)op;
Py_INCREF(key);
Py_INCREF(value);
if (mp->ma_keys == Py_EMPTY_KEYS) {
return insert_to_emptydict(mp, key, hash, value);
return insert_to_emptydict(mp, Py_NewRef(key), hash, Py_NewRef(value));
}
/* insertdict() handles any resizing that might be necessary */
return insertdict(mp, key, hash, value);
return insertdict(mp, Py_NewRef(key), hash, Py_NewRef(value));
}
static void
@ -2197,9 +2195,8 @@ _PyDict_Pop_KnownHash(PyObject *dict, PyObject *key, Py_hash_t hash, PyObject *d
return NULL;
}
assert(old_value != NULL);
Py_INCREF(old_value);
uint64_t new_version = _PyDict_NotifyEvent(PyDict_EVENT_DELETED, mp, key, NULL);
delitem_common(mp, hash, ix, old_value, new_version);
delitem_common(mp, hash, ix, Py_NewRef(old_value), new_version);
ASSERT_CONSISTENT(mp);
return old_value;