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.
This commit is contained in:
Victor Stinner 2018-11-26 13:37:13 +01:00 committed by GitHub
parent c2e1607a51
commit df108dc661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -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)