summaryrefslogtreecommitdiffstats
path: root/Objects/cellobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-05-11 21:24:48 (GMT)
committerGitHub <noreply@github.com>2022-05-11 21:24:48 (GMT)
commit897f14d38d1b455668f9f7ce87892f5efcaf8932 (patch)
tree7b2f8461869d906f38067b583deb24927666638b /Objects/cellobject.c
parentda5727a120e426ffaf68bf3a8016491205bd2f80 (diff)
downloadcpython-897f14d38d1b455668f9f7ce87892f5efcaf8932.zip
cpython-897f14d38d1b455668f9f7ce87892f5efcaf8932.tar.gz
cpython-897f14d38d1b455668f9f7ce87892f5efcaf8932.tar.bz2
gh-89653: PEP 670: Convert PyCell macros to functions (#92653)
Convert the following macros to static inline functions: * PyCell_GET() * PyCell_SET() Limited C API version 3.12 no longer casts arguments. Fix also usage of PyCell_SET(): only delete the old value after setting the new value.
Diffstat (limited to 'Objects/cellobject.c')
-rw-r--r--Objects/cellobject.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index 86a89f02e6..1ddf4c5 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -56,22 +56,21 @@ PyCell_Get(PyObject *op)
PyErr_BadInternalCall();
return NULL;
}
- Py_XINCREF(((PyCellObject*)op)->ob_ref);
- return PyCell_GET(op);
+ PyObject *value = PyCell_GET(op);
+ return Py_XNewRef(value);
}
int
-PyCell_Set(PyObject *op, PyObject *obj)
+PyCell_Set(PyObject *op, PyObject *value)
{
- PyObject* oldobj;
if (!PyCell_Check(op)) {
PyErr_BadInternalCall();
return -1;
}
- oldobj = PyCell_GET(op);
- Py_XINCREF(obj);
- PyCell_SET(op, obj);
- Py_XDECREF(oldobj);
+ PyObject *old_value = PyCell_GET(op);
+ Py_XINCREF(value);
+ PyCell_SET(op, value);
+ Py_XDECREF(old_value);
return 0;
}