aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorMatthieu Longo <matthieu.longo@arm.com>2026-02-20 10:45:27 +0000
committerMatthieu Longo <matthieu.longo@arm.com>2026-03-10 11:22:28 +0000
commit995cf2f8feb57aa564eb4ec1191e3290affc574b (patch)
treea5f36b8a35b2179e88d8f49e225bf9b021e732b1 /gdb/python
parent55c46eed2c8a132df2cd98cd0115ad6862604ca2 (diff)
downloadbinutils-995cf2f8feb57aa564eb4ec1191e3290affc574b.tar.gz
binutils-995cf2f8feb57aa564eb4ec1191e3290affc574b.tar.bz2
binutils-995cf2f8feb57aa564eb4ec1191e3290affc574b.zip
gdb: introduce rgb_color type to simplify existing code
This patch replaces the raw uint8[3] buffer used to represent RGB values with a more convenient wrapper, rgb_color, around std::array<uint8_t, 3>. It also changes the return type of ui_file_style::color::get_rgb to rgb_color instead of filling a caller-provided buffer, and updates all callers accordingly. This expected benefit of this change consists in: - removing the manual size handling. - proving accessors without using hard-coded indexes. - making the API safer. - simplifying call sites. This refactoring does not introduce any functional change. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-color.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/gdb/python/py-color.c b/gdb/python/py-color.c
index 04f7addec2f..971209958cf 100644
--- a/gdb/python/py-color.c
+++ b/gdb/python/py-color.c
@@ -108,11 +108,9 @@ get_attr (PyObject *obj, PyObject *attr_name)
if (color.is_direct ()
&& !PyUnicode_CompareWithASCIIString (attr_name, "components"))
{
- uint8_t rgb[3];
- color.get_rgb (rgb);
-
- gdbpy_ref<> rgb_objects[3];
- for (int i = 0; i < 3; ++i)
+ rgb_color rgb = color.get_rgb ();
+ std::array<gdbpy_ref<>, rgb.size ()> rgb_objects;
+ for (auto i = 0u; i < rgb_objects.size (); ++i)
{
rgb_objects[i] = gdb_py_object_from_ulongest (rgb[i]);
if (rgb_objects[i] == nullptr)
@@ -123,7 +121,7 @@ get_attr (PyObject *obj, PyObject *attr_name)
if (comp == nullptr)
return nullptr;
- for (int i = 0; i < 3; ++i)
+ for (auto i = 0u; i < rgb_objects.size (); ++i)
if (PyTuple_SetItem (comp.get (), i, rgb_objects[i].release ()) < 0)
return nullptr;