summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-25 22:30:32 (GMT)
committerGitHub <noreply@github.com>2018-11-25 22:30:32 (GMT)
commit8ac6539d85b481fc6b5e9145446b07e591b2caba (patch)
tree44ac825f8203295396f3bb46f6acf9e9e0037728 /Include
parent158695817d736df8b18682866033c87e46252309 (diff)
downloadcpython-8ac6539d85b481fc6b5e9145446b07e591b2caba.zip
cpython-8ac6539d85b481fc6b5e9145446b07e591b2caba.tar.gz
cpython-8ac6539d85b481fc6b5e9145446b07e591b2caba.tar.bz2
bpo-35081: Add _PyTuple_CAST() (GH-10704)
Diffstat (limited to 'Include')
-rw-r--r--Include/tupleobject.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index 257e05a..a150d07 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -55,15 +55,18 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
/* Macro, trading safety for speed */
#ifndef Py_LIMITED_API
-#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
-#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)),Py_SIZE(op))
+/* Cast argument to PyTupleObject* type. */
+#define _PyTuple_CAST(op) ((PyTupleObject *)(op))
+
+#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])
+#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)), Py_SIZE(op))
#ifdef Py_BUILD_CORE
-# define _PyTuple_ITEMS(op) ((((PyTupleObject *)(op))->ob_item))
+# define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item)
#endif
/* Macro, *only* to be used to fill in brand new tuples */
-#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
+#define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v)
#endif
PyAPI_FUNC(int) PyTuple_ClearFreeList(void);