From 995cf2f8feb57aa564eb4ec1191e3290affc574b Mon Sep 17 00:00:00 2001 From: Matthieu Longo Date: Fri, 20 Feb 2026 10:45:27 +0000 Subject: 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. 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 --- gdb/python/py-color.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'gdb/python') 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, 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; -- cgit v1.2.3