diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-05-11 23:23:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-11 23:23:29 (GMT) |
commit | a1bef8c2e305178fae2ff90b5772e785a97d2201 (patch) | |
tree | 3abd613bf2e358df877f2cd07650bdab5cfe1799 /Include/cpython | |
parent | c7b9da5204b44fd3e9960a2326d431e3ff5c8667 (diff) | |
download | cpython-a1bef8c2e305178fae2ff90b5772e785a97d2201.zip cpython-a1bef8c2e305178fae2ff90b5772e785a97d2201.tar.gz cpython-a1bef8c2e305178fae2ff90b5772e785a97d2201.tar.bz2 |
gh-89653: PEP 670: Use PyObject* type for parameters (GH-92694)
Use the PyObject* type for parameters of static inline functions:
* Py_SIZE(): same parameter type than PyObject_Size()
* PyList_GET_SIZE(), PyList_SET_ITEM(): same parameter type than
PyList_Size() and PyList_SetItem()
* PyTuple_GET_SIZE(), PyTuple_SET_ITEM(): same parameter type than
PyTuple_Size() and PyTuple_SetItem().
(cherry picked from commit 6de78ef96afbaa127472bb9dc0a4e41e44555d00)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Include/cpython')
-rw-r--r-- | Include/cpython/listobject.h | 14 | ||||
-rw-r--r-- | Include/cpython/tupleobject.h | 14 |
2 files changed, 16 insertions, 12 deletions
diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h index 4989ccc..1add821 100644 --- a/Include/cpython/listobject.h +++ b/Include/cpython/listobject.h @@ -30,20 +30,22 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out); // Macros and static inline functions, trading safety for speed -static inline Py_ssize_t PyList_GET_SIZE(PyListObject *op) { - return Py_SIZE(op); +static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) { + PyListObject *list = _PyList_CAST(op); + return Py_SIZE(list); } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 -# define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyList_CAST(op)) +# define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op)) #endif #define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[index]) static inline void -PyList_SET_ITEM(PyListObject *op, Py_ssize_t index, PyObject *value) { - op->ob_item[index] = value; +PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) { + PyListObject *list = _PyList_CAST(op); + list->ob_item[index] = value; } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 #define PyList_SET_ITEM(op, index, value) \ - PyList_SET_ITEM(_PyList_CAST(op), index, _PyObject_CAST(value)) + PyList_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value)) #endif diff --git a/Include/cpython/tupleobject.h b/Include/cpython/tupleobject.h index a41cee1..3d9c1af 100644 --- a/Include/cpython/tupleobject.h +++ b/Include/cpython/tupleobject.h @@ -19,23 +19,25 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); // Macros and static inline functions, trading safety for speed -static inline Py_ssize_t PyTuple_GET_SIZE(PyTupleObject *op) { - return Py_SIZE(op); +static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) { + PyTupleObject *tuple = _PyTuple_CAST(op); + return Py_SIZE(tuple); } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 -# define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyTuple_CAST(op)) +# define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op)) #endif #define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[index]) /* Function *only* to be used to fill in brand new tuples */ static inline void -PyTuple_SET_ITEM(PyTupleObject *op, Py_ssize_t index, PyObject *value) { - op->ob_item[index] = value; +PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) { + PyTupleObject *tuple = _PyTuple_CAST(op); + tuple->ob_item[index] = value; } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 #define PyTuple_SET_ITEM(op, index, value) \ - PyTuple_SET_ITEM(_PyTuple_CAST(op), index, _PyObject_CAST(value)) + PyTuple_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value)) #endif PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out); |