bpo-39573: Use Py_REFCNT() macro (GH-18388)

Replace direct acccess to PyObject.ob_refcnt with usage of the
Py_REFCNT() macro.
This commit is contained in:
Victor Stinner 2020-02-07 00:38:59 +01:00 committed by GitHub
parent 446463f8db
commit a93c51e3a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 38 deletions

View file

@ -952,7 +952,8 @@ PyObject_ClearWeakRefs(PyObject *object)
if (object == NULL
|| !PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))
|| object->ob_refcnt != 0) {
|| Py_REFCNT(object) != 0)
{
PyErr_BadInternalCall();
return;
}
@ -975,8 +976,9 @@ PyObject_ClearWeakRefs(PyObject *object)
current->wr_callback = NULL;
clear_weakref(current);
if (callback != NULL) {
if (((PyObject *)current)->ob_refcnt > 0)
if (Py_REFCNT((PyObject *)current) > 0) {
handle_callback(current, callback);
}
Py_DECREF(callback);
}
}
@ -993,8 +995,7 @@ PyObject_ClearWeakRefs(PyObject *object)
for (i = 0; i < count; ++i) {
PyWeakReference *next = current->wr_next;
if (((PyObject *)current)->ob_refcnt > 0)
{
if (Py_REFCNT((PyObject *)current) > 0) {
Py_INCREF(current);
PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current);
PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback);