diff options
| author | Matthieu Longo <matthieu.longo@arm.com> | 2026-01-28 14:34:20 +0000 |
|---|---|---|
| committer | Matthieu Longo <matthieu.longo@arm.com> | 2026-03-04 15:38:11 +0000 |
| commit | 7a45ab6fb3a99fb264138a1b649aaf9dde4b1677 (patch) | |
| tree | c769560c8c050629ca1a3a1b7ef40d1c64435054 /gdb/python/python.c | |
| parent | c204edafd4c9430d7c1a999aebb4ae04814b13b4 (diff) | |
| download | binutils-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/python.c')
| -rw-r--r-- | gdb/python/python.c | 5 |
1 files changed, 3 insertions, 2 deletions
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 (); } |
