diff --git a/Doc/c-api/tuple.rst b/Doc/c-api/tuple.rst index b3710560ebe7ac..80a47488e24a71 100644 --- a/Doc/c-api/tuple.rst +++ b/Doc/c-api/tuple.rst @@ -54,10 +54,21 @@ Tuple Objects no error checking is performed. +.. c:function:: PyObject* PyTuple_GetItemRef(PyObject *p, Py_ssize_t pos) + + Return a :term:`strong reference` to the object at position *pos* in the + tuple pointed to by *p*. + + If *pos* is negative or out of bounds, return ``NULL`` and set an + :exc:`IndexError` exception. + + .. versionadded:: 3.13 + + .. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) - Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is - negative or out of bounds, return ``NULL`` and set an :exc:`IndexError` exception. + Similar to :c:func:`PyTuple_GetItemRef`, but return a :term:`borrowed + reference`. .. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 2763bea5137cc7..26cc43d6ccad62 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -662,6 +662,7 @@ function,PyTraceBack_Print,3.2,, var,PyTraceBack_Type,3.2,, var,PyTupleIter_Type,3.2,, function,PyTuple_GetItem,3.2,, +function,PyTuple_GetItemRef,3.13,, function,PyTuple_GetSlice,3.2,, function,PyTuple_New,3.2,, function,PyTuple_Pack,3.2,, diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 7f6a86efc61bf7..63581534b0038b 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1773,6 +1773,11 @@ New Features * Add :c:func:`PyType_GetModuleByDef` to the limited C API (Contributed by Victor Stinner in :gh:`116936`.) +* Add :c:func:`PyTuple_GetItemRef` function, similar to + :c:func:`PyTuple_GetItem` but return a :term:`strong reference` instead of a + :term:`borrowed reference`. + (Contributed by Victor Stinner in :gh:`117518`.) + Porting to Python 3.13 ---------------------- diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index aa87dc413876f0..48b8b4336d7622 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -1038,7 +1038,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[268] = { [FOR_ITER_GEN] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ESCAPES_FLAG }, [FOR_ITER_LIST] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_DEOPT_FLAG }, [FOR_ITER_RANGE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG }, - [FOR_ITER_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_DEOPT_FLAG }, + [FOR_ITER_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_DEOPT_FLAG | HAS_ESCAPES_FLAG }, [GET_AITER] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [GET_ANEXT] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, [GET_AWAITABLE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, @@ -1162,7 +1162,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[268] = { [UNPACK_SEQUENCE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [UNPACK_SEQUENCE_LIST] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_DEOPT_FLAG }, [UNPACK_SEQUENCE_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_DEOPT_FLAG }, - [UNPACK_SEQUENCE_TWO_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_DEOPT_FLAG }, + [UNPACK_SEQUENCE_TWO_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ESCAPES_FLAG }, [WITH_EXCEPT_START] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [YIELD_VALUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ESCAPES_FLAG }, [JUMP] = { true, -1, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index 111824a938f6cc..1491a28370c8ae 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -93,7 +93,7 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_STORE_NAME] = HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_DELETE_NAME] = HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_UNPACK_SEQUENCE] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, - [_UNPACK_SEQUENCE_TWO_TUPLE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, + [_UNPACK_SEQUENCE_TWO_TUPLE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ESCAPES_FLAG, [_UNPACK_SEQUENCE_TUPLE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, [_UNPACK_SEQUENCE_LIST] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, [_UNPACK_EX] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -172,7 +172,7 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_ITER_NEXT_LIST] = 0, [_ITER_CHECK_TUPLE] = HAS_DEOPT_FLAG | HAS_PASSTHROUGH_FLAG, [_GUARD_NOT_EXHAUSTED_TUPLE] = HAS_DEOPT_FLAG | HAS_PASSTHROUGH_FLAG, - [_ITER_NEXT_TUPLE] = 0, + [_ITER_NEXT_TUPLE] = HAS_ESCAPES_FLAG, [_ITER_CHECK_RANGE] = HAS_DEOPT_FLAG | HAS_PASSTHROUGH_FLAG, [_GUARD_NOT_EXHAUSTED_RANGE] = HAS_DEOPT_FLAG | HAS_PASSTHROUGH_FLAG, [_ITER_NEXT_RANGE] = HAS_ERROR_FLAG, diff --git a/Include/tupleobject.h b/Include/tupleobject.h index 1f9ab54be65f87..d762d793d1eb41 100644 --- a/Include/tupleobject.h +++ b/Include/tupleobject.h @@ -30,6 +30,9 @@ PyAPI_DATA(PyTypeObject) PyTupleIter_Type; PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000 +PyAPI_FUNC(PyObject *) PyTuple_GetItemRef(PyObject *, Py_ssize_t); +#endif PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index d22698168615e2..b609ae753992cb 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -695,6 +695,7 @@ def test_windows_feature_macros(self): "PyTraceBack_Type", "PyTupleIter_Type", "PyTuple_GetItem", + "PyTuple_GetItemRef", "PyTuple_GetSlice", "PyTuple_New", "PyTuple_Pack", diff --git a/Misc/NEWS.d/next/C API/2024-04-03-21-37-08.gh-issue-117518.F17sQ6.rst b/Misc/NEWS.d/next/C API/2024-04-03-21-37-08.gh-issue-117518.F17sQ6.rst new file mode 100644 index 00000000000000..7e0990195abfaf --- /dev/null +++ b/Misc/NEWS.d/next/C API/2024-04-03-21-37-08.gh-issue-117518.F17sQ6.rst @@ -0,0 +1,3 @@ +Add :c:func:`PyTuple_GetItemRef` function, similar to +:c:func:`PyTuple_GetItem` but return a :term:`strong reference` instead of a +:term:`borrowed reference`. Patch by Victor Stinner. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 14dda7db1c323e..781780a8fe343d 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -2506,3 +2506,5 @@ added = '3.13' [function.PyType_GetModuleByDef] added = '3.13' +[function.PyTuple_GetItemRef] + added = '3.13' diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index a626bda2ea9be9..db48312aa8647b 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -213,7 +213,7 @@ divide_nearest(PyObject *m, PyObject *n) temp = _PyLong_DivmodNear(m, n); if (temp == NULL) return NULL; - result = Py_NewRef(PyTuple_GET_ITEM(temp, 0)); + result = PyTuple_GetItemRef(temp, 0); Py_DECREF(temp); return result; @@ -1978,7 +1978,7 @@ microseconds_to_delta_ex(PyObject *pyus, PyTypeObject *type) goto BadDivmod; } - num = Py_NewRef(PyTuple_GET_ITEM(tuple, 0)); /* leftover seconds */ + num = PyTuple_GetItemRef(tuple, 0); /* leftover seconds */ Py_DECREF(tuple); tuple = checked_divmod(num, st->seconds_per_day); @@ -1996,7 +1996,7 @@ microseconds_to_delta_ex(PyObject *pyus, PyTypeObject *type) goto BadDivmod; } - num = Py_NewRef(PyTuple_GET_ITEM(tuple, 0)); /* leftover days */ + num = PyTuple_GetItemRef(tuple, 0); /* leftover days */ d = PyLong_AsInt(num); if (d == -1 && PyErr_Occurred()) { goto Done; diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c index 4526583a8059d9..f2dea381456221 100644 --- a/Modules/_testcapi/heaptype.c +++ b/Modules/_testcapi/heaptype.c @@ -164,7 +164,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED( "TypeError args are not a one-tuple"); goto finally; } - message = Py_NewRef(PyTuple_GET_ITEM(args, 0)); + message = PyTuple_GetItemRef(args, 0); meta_error_string = PyUnicode_FromString("metaclass conflict:"); if (meta_error_string == NULL) { goto finally; @@ -1028,7 +1028,7 @@ HeapCCollection_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) } for (Py_ssize_t i = 0; i < size; i++) { - data[i] = Py_NewRef(PyTuple_GET_ITEM(args, i)); + data[i] = PyTuple_GetItemRef(args, i); } result = self; diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 63c461d34fb4ff..80c4083309c976 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -641,7 +641,7 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) if (size == 0) return 0; if (size == 1) { - Py_XSETREF(self->code, Py_NewRef(PyTuple_GET_ITEM(args, 0))); + Py_XSETREF(self->code, PyTuple_GetItemRef(args, 0)); } else { /* size > 1 */ Py_XSETREF(self->code, Py_NewRef(args)); @@ -1546,7 +1546,7 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) Py_XSETREF(self->name_from, Py_XNewRef(name_from)); if (PyTuple_GET_SIZE(args) == 1) { - msg = Py_NewRef(PyTuple_GET_ITEM(args, 0)); + msg = PyTuple_GetItemRef(args, 0); } Py_XSETREF(self->msg, msg); @@ -2034,8 +2034,8 @@ OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) if (!args) return NULL; - PyTuple_SET_ITEM(args, 0, Py_NewRef(PyTuple_GET_ITEM(self->args, 0))); - PyTuple_SET_ITEM(args, 1, Py_NewRef(PyTuple_GET_ITEM(self->args, 1))); + PyTuple_SET_ITEM(args, 0, PyTuple_GetItemRef(self->args, 0)); + PyTuple_SET_ITEM(args, 1, PyTuple_GetItemRef(self->args, 1)); PyTuple_SET_ITEM(args, 2, Py_NewRef(self->filename)); if (self->filename2) { @@ -2389,7 +2389,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) return -1; if (lenargs >= 1) { - Py_XSETREF(self->msg, Py_NewRef(PyTuple_GET_ITEM(args, 0))); + Py_XSETREF(self->msg, PyTuple_GetItemRef(args, 0)); } if (lenargs == 2) { info = PyTuple_GET_ITEM(args, 1); diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 6a38952fdc1f3b..7d8c392deab0fc 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -2121,7 +2121,7 @@ struct_unpack_single(const char *ptr, struct unpacker *x) return NULL; if (PyTuple_GET_SIZE(v) == 1) { - PyObject *res = Py_NewRef(PyTuple_GET_ITEM(v, 0)); + PyObject *res = PyTuple_GetItemRef(v, 0); Py_DECREF(v); return res; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index d9dc00da368a84..6ac7de4cf3e56c 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -109,6 +109,15 @@ PyTuple_GetItem(PyObject *op, Py_ssize_t i) return ((PyTupleObject *)op) -> ob_item[i]; } + +PyObject * +PyTuple_GetItemRef(PyObject *op, Py_ssize_t index) +{ + PyObject *item = PyTuple_GetItem(op, index); + return Py_XNewRef(item); +} + + int PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 51ceb7d7de1cb6..97e6d24184bf99 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6453,8 +6453,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) Py_DECREF(newargs); return -1; } - *args = Py_NewRef(PyTuple_GET_ITEM(newargs, 0)); - *kwargs = Py_NewRef(PyTuple_GET_ITEM(newargs, 1)); + *args = PyTuple_GetItemRef(newargs, 0); + *kwargs = PyTuple_GetItemRef(newargs, 1); Py_DECREF(newargs); /* XXX We should perhaps allow None to be passed here. */ diff --git a/Objects/unionobject.c b/Objects/unionobject.c index bf5605686f8df7..9a8bc37c3396aa 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -293,7 +293,7 @@ union_getitem(PyObject *self, PyObject *item) res = make_union(newargs); } else { - res = Py_NewRef(PyTuple_GET_ITEM(newargs, 0)); + res = PyTuple_GetItemRef(newargs, 0); for (Py_ssize_t iarg = 1; iarg < nargs; iarg++) { PyObject *arg = PyTuple_GET_ITEM(newargs, iarg); Py_SETREF(res, PyNumber_Or(res, arg)); diff --git a/PC/python3dll.c b/PC/python3dll.c index c6fdc0bd73b9fe..83fa4066173492 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -626,6 +626,7 @@ EXPORT_FUNC(PyThreadState_Swap) EXPORT_FUNC(PyTraceBack_Here) EXPORT_FUNC(PyTraceBack_Print) EXPORT_FUNC(PyTuple_GetItem) +EXPORT_FUNC(PyTuple_GetItemRef) EXPORT_FUNC(PyTuple_GetSlice) EXPORT_FUNC(PyTuple_New) EXPORT_FUNC(PyTuple_Pack) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index fa53c969fe361e..25bd4aa78fd493 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1237,8 +1237,8 @@ dummy_func( DEOPT_IF(!PyTuple_CheckExact(seq)); DEOPT_IF(PyTuple_GET_SIZE(seq) != 2); STAT_INC(UNPACK_SEQUENCE, hit); - val0 = Py_NewRef(PyTuple_GET_ITEM(seq, 0)); - val1 = Py_NewRef(PyTuple_GET_ITEM(seq, 1)); + val0 = PyTuple_GetItemRef(seq, 0); + val1 = PyTuple_GetItemRef(seq, 1); DECREF_INPUTS(); } @@ -2702,7 +2702,7 @@ dummy_func( PyTupleObject *seq = it->it_seq; assert(seq); assert(it->it_index < PyTuple_GET_SIZE(seq)); - next = Py_NewRef(PyTuple_GET_ITEM(seq, it->it_index++)); + next = PyTuple_GetItemRef((PyObject*)seq, it->it_index++); } macro(FOR_ITER_TUPLE) = diff --git a/Python/ceval.c b/Python/ceval.c index f3b73165e9f28b..1f28245d8d9714 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2031,8 +2031,8 @@ _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, } assert(PyTuple_CheckExact(pair)); assert(PyTuple_GET_SIZE(pair) == 2); - *match = Py_NewRef(PyTuple_GET_ITEM(pair, 0)); - *rest = Py_NewRef(PyTuple_GET_ITEM(pair, 1)); + *match = PyTuple_GetItemRef(pair, 0); + *rest = PyTuple_GetItemRef(pair, 1); Py_DECREF(pair); return 0; } diff --git a/Python/codecs.c b/Python/codecs.c index d8fe7b22063a80..92876092c8b244 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -411,7 +411,7 @@ _PyCodec_EncodeInternal(PyObject *object, "encoder must return a tuple (object, integer)"); goto onError; } - v = Py_NewRef(PyTuple_GET_ITEM(result,0)); + v = PyTuple_GetItemRef(result, 0); /* We don't check or use the second (integer) entry. */ Py_DECREF(args); @@ -455,7 +455,7 @@ _PyCodec_DecodeInternal(PyObject *object, "decoder must return a tuple (object,integer)"); goto onError; } - v = Py_NewRef(PyTuple_GET_ITEM(result,0)); + v = PyTuple_GetItemRef(result, 0); /* We don't check or use the second (integer) entry. */ Py_DECREF(args); @@ -550,7 +550,7 @@ PyObject *codec_getitem_checked(const char *encoding, if (codec == NULL) return NULL; - v = Py_NewRef(PyTuple_GET_ITEM(codec, index)); + v = PyTuple_GetItemRef(codec, index); Py_DECREF(codec); return v; } diff --git a/Python/compile.c b/Python/compile.c index d9312f93d0680f..91177f51af1cfd 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1064,7 +1064,7 @@ merge_consts_recursive(PyObject *const_cache, PyObject *o) } PyObject *u; if (PyTuple_CheckExact(k)) { - u = Py_NewRef(PyTuple_GET_ITEM(k, 1)); + u = PyTuple_GetItemRef(k, 1); Py_DECREF(k); } else { diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 98476798fbbbdf..4a7d4195382a0d 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -1075,8 +1075,8 @@ if (!PyTuple_CheckExact(seq)) JUMP_TO_JUMP_TARGET(); if (PyTuple_GET_SIZE(seq) != 2) JUMP_TO_JUMP_TARGET(); STAT_INC(UNPACK_SEQUENCE, hit); - val0 = Py_NewRef(PyTuple_GET_ITEM(seq, 0)); - val1 = Py_NewRef(PyTuple_GET_ITEM(seq, 1)); + val0 = PyTuple_GetItemRef(seq, 0); + val1 = PyTuple_GetItemRef(seq, 1); Py_DECREF(seq); stack_pointer[-1] = val1; stack_pointer[0] = val0; @@ -2458,7 +2458,7 @@ PyTupleObject *seq = it->it_seq; assert(seq); assert(it->it_index < PyTuple_GET_SIZE(seq)); - next = Py_NewRef(PyTuple_GET_ITEM(seq, it->it_index++)); + next = PyTuple_GetItemRef((PyObject*)seq, it->it_index++); stack_pointer[0] = next; stack_pointer += 1; break; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 6ee794a05b51d4..30102f87ec1554 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2787,7 +2787,7 @@ PyTupleObject *seq = it->it_seq; assert(seq); assert(it->it_index < PyTuple_GET_SIZE(seq)); - next = Py_NewRef(PyTuple_GET_ITEM(seq, it->it_index++)); + next = PyTuple_GetItemRef((PyObject*)seq, it->it_index++); } stack_pointer[0] = next; stack_pointer += 1; @@ -5962,8 +5962,8 @@ DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE); STAT_INC(UNPACK_SEQUENCE, hit); - val0 = Py_NewRef(PyTuple_GET_ITEM(seq, 0)); - val1 = Py_NewRef(PyTuple_GET_ITEM(seq, 1)); + val0 = PyTuple_GetItemRef(seq, 0); + val1 = PyTuple_GetItemRef(seq, 1); Py_DECREF(seq); stack_pointer[-1] = val1; stack_pointer[0] = val0; diff --git a/Python/getargs.c b/Python/getargs.c index bec981698767ca..1239013b11f7f9 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1625,7 +1625,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, if (!skip) { PyObject *current_arg; if (i < nargs) { - current_arg = Py_NewRef(PyTuple_GET_ITEM(args, i)); + current_arg = PyTuple_GetItemRef(args, i); } else if (nkwargs && i >= pos) { if (PyDict_GetItemStringRef(kwargs, kwlist[i], ¤t_arg) < 0) {