summaryrefslogtreecommitdiffstats
path: root/Include/cpython
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 /Include/cpython
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 'Include/cpython')
-rw-r--r--Include/cpython/cellobject.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/Include/cpython/cellobject.h b/Include/cpython/cellobject.h
index e07f9d1..f778f86 100644
--- a/Include/cpython/cellobject.h
+++ b/Include/cpython/cellobject.h
@@ -21,8 +21,23 @@ PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
-#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
-#define PyCell_SET(op, v) _Py_RVALUE(((PyCellObject *)(op))->ob_ref = (v))
+static inline PyObject* PyCell_GET(PyObject *op) {
+ assert(PyCell_Check(op));
+ PyCellObject *cell = _Py_CAST(PyCellObject*, op);
+ return cell->ob_ref;
+}
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030c0000
+# define PyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
+#endif
+
+static inline void PyCell_SET(PyObject *op, PyObject *value) {
+ assert(PyCell_Check(op));
+ PyCellObject *cell = _Py_CAST(PyCellObject*, op);
+ cell->ob_ref = value;
+}
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030c0000
+# define PyCell_SET(op, value) PyCell_SET(_PyObject_CAST(op), (value))
+#endif
#ifdef __cplusplus
}