diff options
author | Victor Stinner <vstinner@python.org> | 2020-02-06 23:38:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-06 23:38:59 (GMT) |
commit | a93c51e3a8e15f1a486d11d5b55a64f3381babe0 (patch) | |
tree | a84997f6ca55cb27c92248dc04eda44e01a07a2a /Modules | |
parent | 446463f8dbce0556be8020914f37089b63bb8ab6 (diff) | |
download | cpython-a93c51e3a8e15f1a486d11d5b55a64f3381babe0.zip cpython-a93c51e3a8e15f1a486d11d5b55a64f3381babe0.tar.gz cpython-a93c51e3a8e15f1a486d11d5b55a64f3381babe0.tar.bz2 |
bpo-39573: Use Py_REFCNT() macro (GH-18388)
Replace direct acccess to PyObject.ob_refcnt with usage of the
Py_REFCNT() macro.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_functoolsmodule.c | 4 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 987087b..50d8c58 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -649,7 +649,7 @@ functools_reduce(PyObject *self, PyObject *args) for (;;) { PyObject *op2; - if (args->ob_refcnt > 1) { + if (Py_REFCNT(args) > 1) { Py_DECREF(args); if ((args = PyTuple_New(2)) == NULL) goto Fail; @@ -666,7 +666,7 @@ functools_reduce(PyObject *self, PyObject *args) result = op2; else { /* Update the args tuple in-place */ - assert(args->ob_refcnt == 1); + assert(Py_REFCNT(args) == 1); Py_XSETREF(_PyTuple_ITEMS(args)[0], result); Py_XSETREF(_PyTuple_ITEMS(args)[1], op2); if ((result = PyObject_Call(func, args, NULL)) == NULL) { diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c5812f8..27db86a 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3550,8 +3550,8 @@ slot_tp_del(PyObject *self) PyObject *error_type, *error_value, *error_traceback; /* Temporarily resurrect the object. */ - assert(self->ob_refcnt == 0); - self->ob_refcnt = 1; + assert(Py_REFCNT(self) == 0); + Py_REFCNT(self) = 1; /* Save the current exception, if any. */ PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -3573,17 +3573,19 @@ slot_tp_del(PyObject *self) /* Undo the temporary resurrection; can't use DECREF here, it would * cause a recursive call. */ - assert(self->ob_refcnt > 0); - if (--self->ob_refcnt == 0) - return; /* this is the normal path out */ + assert(Py_REFCNT(self) > 0); + if (--Py_REFCNT(self) == 0) { + /* this is the normal path out */ + return; + } /* __del__ resurrected it! Make it look like the original Py_DECREF * never happened. */ { - Py_ssize_t refcnt = self->ob_refcnt; + Py_ssize_t refcnt = Py_REFCNT(self); _Py_NewReference(self); - self->ob_refcnt = refcnt; + Py_REFCNT(self) = refcnt; } assert(!PyType_IS_GC(Py_TYPE(self)) || _PyObject_GC_IS_TRACKED(self)); /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased |