aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-26 13:37:13 +0100
committerGitHub <noreply@github.com>2018-11-26 13:37:13 +0100
commitdf108dc6610e41c54ed064a854e3903c143f0d77 (patch)
treeba33524ff177a6533290f79be66523b02a6dcd3b /Include/tupleobject.h
parentbpo-34100: Merge constants recursively (GH-8341) (diff)
downloadcpython-df108dc6610e41c54ed064a854e3903c143f0d77.tar.gz
cpython-df108dc6610e41c54ed064a854e3903c143f0d77.tar.bz2
cpython-df108dc6610e41c54ed064a854e3903c143f0d77.zip
Add assertion to _PyTuple_CAST(op) (GH-10712)
Add "assert(PyTuple_Check(op));" to _PyTuple_CAST() to check that the argument is a tuple object in debug mode. PyTuple_GET_SIZE() now uses _PyTuple_CAST() to get its assertion.
Diffstat (limited to 'Include/tupleobject.h')
-rw-r--r--Include/tupleobject.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index eec2d98f2d9..75574bc43fb 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -56,10 +56,10 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
/* Macro, trading safety for speed */
#ifndef Py_LIMITED_API
/* Cast argument to PyTupleObject* type. */
-#define _PyTuple_CAST(op) ((PyTupleObject *)(op))
+#define _PyTuple_CAST(op) (assert(PyTuple_Check(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))
+#define PyTuple_GET_SIZE(op) Py_SIZE(_PyTuple_CAST(op))
/* Macro, *only* to be used to fill in brand new tuples */
#define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v)