bpo-35081: Add _PyTuple_CAST() (GH-10704) · python/cpython@8ac6539 (original) (raw)

`@@ -55,15 +55,18 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);

`

55

55

``

56

56

`/* Macro, trading safety for speed */

`

57

57

`#ifndef Py_LIMITED_API

`

58

``

`-

#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])

`

59

``

`-

#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)),Py_SIZE(op))

`

``

58

`+

/* Cast argument to PyTupleObject* type. */

`

``

59

`+

#define _PyTuple_CAST(op) ((PyTupleObject *)(op))

`

``

60

+

``

61

`+

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

`

60

63

``

61

64

`#ifdef Py_BUILD_CORE

`

62

``

`-

define _PyTuple_ITEMS(op) ((((PyTupleObject *)(op))->ob_item))

`

``

65

`+

define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item)

`

63

66

`#endif

`

64

67

``

65

68

`/* Macro, only to be used to fill in brand new tuples */

`

66

``

`-

#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)

`

``

69

`+

#define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v)

`

67

70

`#endif

`

68

71

``

69

72

`PyAPI_FUNC(int) PyTuple_ClearFreeList(void);

`