Skip to content

Commit f9b67ad

Browse files
authored
gh-89653: PEP 670: Convert PyDict_GET_SIZE() macro to function (#92695)
The limited C API version 3.12 no longer casts the argument.
1 parent b3f99b6 commit f9b67ad

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Include/cpython/dictobject.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ PyAPI_FUNC(int) _PyDict_Next(
4646
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
4747

4848
/* Get the number of items of a dictionary. */
49-
#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
49+
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
50+
assert(PyDict_Check(op));
51+
PyDictObject *mp = _Py_CAST(PyDictObject*, op);
52+
return mp->ma_used;
53+
}
54+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030c0000
55+
# define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
56+
#endif
57+
5058
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
5159
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
5260
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);

0 commit comments

Comments
 (0)