mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
gh-89653: PEP 670: Convert macros to functions (#99843)
Convert macros to static inline functions to avoid macro pitfalls, like duplication of side effects: * DK_ENTRIES() * DK_UNICODE_ENTRIES() * PyCode_GetNumFree() * PyFloat_AS_DOUBLE() * PyInstanceMethod_GET_FUNCTION() * PyMemoryView_GET_BASE() * PyMemoryView_GET_BUFFER() * PyMethod_GET_FUNCTION() * PyMethod_GET_SELF() * PySet_GET_SIZE() * _PyHeapType_GET_MEMBERS() Changes: * PyCode_GetNumFree() casts PyCode_GetNumFree.co_nfreevars from int to Py_ssize_t to be future proof, and because Py_ssize_t is commonly used in the C API. * PyCode_GetNumFree() doesn't cast its argument: the replaced macro already required the exact type PyCodeObject*. * Add assertions in some functions using "CAST" macros to check the arguments type when Python is built with assertions (debug build). * Remove an outdated comment in unicodeobject.h.
This commit is contained in:
parent
53eef27133
commit
02f72b8b93
8 changed files with 74 additions and 27 deletions
|
@ -58,8 +58,13 @@ typedef struct {
|
|||
PyObject *weakreflist; /* List of weak references */
|
||||
} PySetObject;
|
||||
|
||||
#define PySet_GET_SIZE(so) \
|
||||
(assert(PyAnySet_Check(so)), (((PySetObject *)(so))->used))
|
||||
#define _PySet_CAST(so) \
|
||||
(assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))
|
||||
|
||||
static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
|
||||
return _PySet_CAST(so)->used;
|
||||
}
|
||||
#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))
|
||||
|
||||
PyAPI_DATA(PyObject *) _PySet_Dummy;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue