[Python-checkins] Add assertion to _PyTuple_CAST(op) (GH-10712)

Victor Stinner webhook-mailer at python.org
Mon Nov 26 07:37:17 EST 2018


https://github.com/python/cpython/commit/df108dc6610e41c54ed064a854e3903c143f0d77
commit: df108dc6610e41c54ed064a854e3903c143f0d77
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-26T13:37:13+01:00
summary:

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.

files:
M Include/tupleobject.h

diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index eec2d98f2d95..75574bc43fb3 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)



More information about the Python-checkins mailing list