bpo-29867: Add asserts in PyTuple_GET_SIZE, PyList_GET_SIZE and PySet_GET_SIZE. (#751)

This commit is contained in:
Serhiy Storchaka 2017-04-22 02:48:11 +03:00 committed by Victor Stinner
parent a36e939aeb
commit 1a5856bf92
4 changed files with 4 additions and 4 deletions

View File

@ -71,7 +71,7 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
#define PyList_GET_SIZE(op) Py_SIZE(op) #define PyList_GET_SIZE(op) (assert(PyList_Check(op)),Py_SIZE(op))
#define _PyList_ITEMS(op) (((PyListObject *)(op))->ob_item) #define _PyList_ITEMS(op) (((PyListObject *)(op))->ob_item)
#endif #endif

View File

@ -64,7 +64,7 @@ typedef struct {
PyObject *weakreflist; /* List of weak references */ PyObject *weakreflist; /* List of weak references */
} PySetObject; } PySetObject;
#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used) #define PySet_GET_SIZE(so) (assert(PyAnySet_Check(so)),(((PySetObject *)(so))->used))
PyAPI_DATA(PyObject *) _PySet_Dummy; PyAPI_DATA(PyObject *) _PySet_Dummy;

View File

@ -56,7 +56,7 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
#define PyTuple_GET_SIZE(op) Py_SIZE(op) #define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)),Py_SIZE(op))
/* Macro, *only* to be used to fill in brand new tuples */ /* 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) (((PyTupleObject *)(op))->ob_item[i] = v)

View File

@ -1519,7 +1519,7 @@ odict_repr(PyODictObject *self)
count++; count++;
} }
if (count < PyList_GET_SIZE(pieces)) if (count < PyList_GET_SIZE(pieces))
PyList_GET_SIZE(pieces) = count; Py_SIZE(pieces) = count;
} }
else { else {
PyObject *items = _PyObject_CallMethodIdObjArgs((PyObject *)self, PyObject *items = _PyObject_CallMethodIdObjArgs((PyObject *)self,