]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35081: Add _PyTuple_CAST() (GH-10704)
authorVictor Stinner <vstinner@redhat.com>
Sun, 25 Nov 2018 22:30:32 +0000 (23:30 +0100)
committerGitHub <noreply@github.com>
Sun, 25 Nov 2018 22:30:32 +0000 (23:30 +0100)
Include/tupleobject.h

index 257e05aeae8f30c75e439599a03f918c30a435c6..a150d07d3e0a4f07c979582c7943c41819400f06 100644 (file)
@@ -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);