Skip to content

Commit df108dc

Browse files
authored
Add assertion to _PyTuple_CAST(op) (pythonGH-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.
1 parent c2e1607 commit df108dc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Include/tupleobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
5656
/* Macro, trading safety for speed */
5757
#ifndef Py_LIMITED_API
5858
/* Cast argument to PyTupleObject* type. */
59-
#define _PyTuple_CAST(op) ((PyTupleObject *)(op))
59+
#define _PyTuple_CAST(op) (assert(PyTuple_Check(op)), (PyTupleObject *)(op))
6060

6161
#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))
62+
#define PyTuple_GET_SIZE(op) Py_SIZE(_PyTuple_CAST(op))
6363

6464
/* Macro, *only* to be used to fill in brand new tuples */
6565
#define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v)

0 commit comments

Comments
 (0)