summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-05-11 22:58:42 (GMT)
committerGitHub <noreply@github.com>2022-05-11 22:58:42 (GMT)
commitf9b67ad7701a4d51c0c895db4087ebd66743aa82 (patch)
tree685cc351188cc2524853e506ca53d48dfd5ea5b5 /Include
parentb3f99b69d03cf0ea72a567a81e8bc4bc074ab303 (diff)
downloadcpython-f9b67ad7701a4d51c0c895db4087ebd66743aa82.zip
cpython-f9b67ad7701a4d51c0c895db4087ebd66743aa82.tar.gz
cpython-f9b67ad7701a4d51c0c895db4087ebd66743aa82.tar.bz2
gh-89653: PEP 670: Convert PyDict_GET_SIZE() macro to function (#92695)
The limited C API version 3.12 no longer casts the argument.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/dictobject.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h
index 033eaeb..f249c0e 100644
--- a/Include/cpython/dictobject.h
+++ b/Include/cpython/dictobject.h
@@ -46,7 +46,15 @@ PyAPI_FUNC(int) _PyDict_Next(
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
/* Get the number of items of a dictionary. */
-#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
+static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
+ assert(PyDict_Check(op));
+ PyDictObject *mp = _Py_CAST(PyDictObject*, op);
+ return mp->ma_used;
+}
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030c0000
+# define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
+#endif
+
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);