bpo-39573: Add Py_SET_REFCNT() function (GH-18389)

Add a Py_SET_REFCNT() function to set the reference counter of an
object.
This commit is contained in:
Victor Stinner 2020-02-07 01:24:29 +01:00 committed by GitHub
parent a93c51e3a8
commit c86a11221d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 14 deletions

View file

@ -1903,7 +1903,7 @@ unicode_dealloc(PyObject *unicode)
case SSTATE_INTERNED_MORTAL:
/* revive dead object temporarily for DelItem */
Py_REFCNT(unicode) = 3;
Py_SET_REFCNT(unicode, 3);
if (PyDict_DelItem(interned, unicode) != 0) {
_PyErr_WriteUnraisableMsg("deletion of interned string failed",
NULL);
@ -15367,7 +15367,7 @@ PyUnicode_InternInPlace(PyObject **p)
}
/* The two references in interned are not counted by refcnt.
The deallocator will take care of this */
Py_REFCNT(s) -= 2;
Py_SET_REFCNT(s, Py_REFCNT(s) - 2);
_PyUnicode_STATE(s).interned = SSTATE_INTERNED_MORTAL;
}