summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-02-07 00:24:29 (GMT)
committerGitHub <noreply@github.com>2020-02-07 00:24:29 (GMT)
commitc86a11221df7e37da389f9c6ce6e47ea22dc44ff (patch)
treec27a35a01bde1554488268dd3bbeb8b4c46e193c /Objects
parenta93c51e3a8e15f1a486d11d5b55a64f3381babe0 (diff)
downloadcpython-c86a11221df7e37da389f9c6ce6e47ea22dc44ff.zip
cpython-c86a11221df7e37da389f9c6ce6e47ea22dc44ff.tar.gz
cpython-c86a11221df7e37da389f9c6ce6e47ea22dc44ff.tar.bz2
bpo-39573: Add Py_SET_REFCNT() function (GH-18389)
Add a Py_SET_REFCNT() function to set the reference counter of an object.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c2
-rw-r--r--Objects/object.c9
-rw-r--r--Objects/unicodeobject.c4
3 files changed, 8 insertions, 7 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 49cfd57..da329b4 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -51,7 +51,7 @@ PyModuleDef_Init(struct PyModuleDef* def)
return NULL;
if (def->m_base.m_index == 0) {
max_module_number++;
- Py_REFCNT(def) = 1;
+ Py_SET_REFCNT(def, 1);
Py_TYPE(def) = &PyModuleDef_Type;
def->m_base.m_index = max_module_number;
}
diff --git a/Objects/object.c b/Objects/object.c
index f9682fe..aca20e8 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -213,7 +213,7 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
}
/* Temporarily resurrect the object. */
- Py_REFCNT(self) = 1;
+ Py_SET_REFCNT(self, 1);
PyObject_CallFinalizer(self);
@@ -223,7 +223,8 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
/* Undo the temporary resurrection; can't use DECREF here, it would
* cause a recursive call. */
- if (--Py_REFCNT(self) == 0) {
+ Py_SET_REFCNT(self, Py_REFCNT(self) - 1);
+ if (Py_REFCNT(self) == 0) {
return 0; /* this is the normal path out */
}
@@ -231,7 +232,7 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
* never happened. */
Py_ssize_t refcnt = Py_REFCNT(self);
_Py_NewReference(self);
- Py_REFCNT(self) = refcnt;
+ Py_SET_REFCNT(self, refcnt);
_PyObject_ASSERT(self,
(!PyType_IS_GC(Py_TYPE(self))
@@ -1818,7 +1819,7 @@ _Py_NewReference(PyObject *op)
#ifdef Py_REF_DEBUG
_Py_RefTotal++;
#endif
- Py_REFCNT(op) = 1;
+ Py_SET_REFCNT(op, 1);
#ifdef Py_TRACE_REFS
_Py_AddToAllObjects(op, 1);
#endif
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 7c8bc06..fa48ee1 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}