aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-function.c
diff options
context:
space:
mode:
authorMatthieu Longo <matthieu.longo@arm.com>2026-01-28 14:34:20 +0000
committerMatthieu Longo <matthieu.longo@arm.com>2026-03-04 15:38:11 +0000
commit7a45ab6fb3a99fb264138a1b649aaf9dde4b1677 (patch)
treec769560c8c050629ca1a3a1b7ef40d1c64435054 /gdb/python/py-function.c
parentc204edafd4c9430d7c1a999aebb4ae04814b13b4 (diff)
downloadbinutils-7a45ab6fb3a99fb264138a1b649aaf9dde4b1677.tar.gz
binutils-7a45ab6fb3a99fb264138a1b649aaf9dde4b1677.tar.bz2
binutils-7a45ab6fb3a99fb264138a1b649aaf9dde4b1677.zip
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 <tom@tromey.com>
Diffstat (limited to 'gdb/python/py-function.c')
-rw-r--r--gdb/python/py-function.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 3bb81527a9c..23e0be0ea43 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -48,7 +48,8 @@ convert_values_to_python (int argc, struct value **argv)
gdbpy_ref<> elt = value_to_value_object (argv[i]);
if (elt == NULL)
return NULL;
- PyTuple_SetItem (result.get (), i, elt.release ());
+ if (PyTuple_SetItem (result.get (), i, elt.release ()) < 0)
+ return nullptr;
}
return result;
}