From 7a45ab6fb3a99fb264138a1b649aaf9dde4b1677 Mon Sep 17 00:00:00 2001 From: Matthieu Longo Date: Wed, 28 Jan 2026 14:34:20 +0000 Subject: gdb: switch tuple object helpers to Python limited API equivalents * PyTuple_GET_ITEM -> PyTuple_GetItem * PyTuple_SET_ITEM -> PyTuple_SetItem * PyTuple_GET_SIZE -> PyTuple_Size Unlike PyTuple_SET_ITEM(), PyTuple_SetItem() returns an integer: 0 on success and -1 on error (e.g. IndexError). The existing code must therefore be updated to handle this new behaviour. Since processing now stops when PyTuple_SetItem() returns an error, some resources (such as newly allocated tuples) must be properly deallocated in error paths. To address this, this patch replaces the use of raw 'PyObject *' pointers with gdbpy_ref<>, a reference-counted wrapper around 'PyObject *', which automatically decrements the reference count on early exit. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830 Approved-By: Tom Tromey --- gdb/python/python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gdb/python/python.c') diff --git a/gdb/python/python.c b/gdb/python/python.c index 8739864a861..5474b8d644f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1043,8 +1043,9 @@ gdbpy_decode_line (PyObject *self, PyObject *args) else unparsed = gdbpy_ref<>::new_reference (Py_None); - PyTuple_SetItem (return_result.get (), 0, unparsed.release ()); - PyTuple_SetItem (return_result.get (), 1, result.release ()); + if (PyTuple_SetItem (return_result.get (), 0, unparsed.release ()) < 0 + || PyTuple_SetItem (return_result.get (), 1, result.release ()) < 0) + return nullptr; return return_result.release (); } -- cgit v1.2.3