Skip to content

Commit 8ac6539

Browse files
authored
bpo-35081: Add _PyTuple_CAST() (GH-10704)
1 parent 1586958 commit 8ac6539

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎Include/tupleobject.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
5555

5656
/* Macro, trading safety for speed */
5757
#ifndef Py_LIMITED_API
58-
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
59-
#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)),Py_SIZE(op))
58+
/* Cast argument to PyTupleObject* type. */
59+
#define _PyTuple_CAST(op) ((PyTupleObject *)(op))
60+
61+
#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])
62+
#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)), Py_SIZE(op))
6063

6164
#ifdef Py_BUILD_CORE
62-
# define _PyTuple_ITEMS(op) ((((PyTupleObject *)(op))->ob_item))
65+
# define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item)
6366
#endif
6467

6568
/* Macro, *only* to be used to fill in brand new tuples */
66-
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
69+
#define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v)
6770
#endif
6871

6972
PyAPI_FUNC(int) PyTuple_ClearFreeList(void);

0 commit comments

Comments
 (0)