[gimp] libgimpcolor: Fix gimp_rgb_list_names() for introspection



commit dcd1dd29a8baa65f79035b7779012943bf642d1a
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Thu Dec 2 12:43:47 2021 +0100

    libgimpcolor: Fix gimp_rgb_list_names() for introspection
    
    This functions has 2 `(out) (array)` arguments, where the array length
    is defined by the return value. This can't be expressed in GIR
    annotations unfortunately, so just add it as another `(out)` argument.
    
    Also, by default `(out)` args are assumed to be `(transfer full)`, while
    these were actually `(transfer container)`.

 libgimpcolor/gimprgb-parse.c       | 22 ++++++++++------------
 libgimpcolor/gimprgb.h             |  5 +++--
 libgimpwidgets/gimpcolorhexentry.c |  2 +-
 3 files changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/libgimpcolor/gimprgb-parse.c b/libgimpcolor/gimprgb-parse.c
index 1b8bb074d1..3f81d40309 100644
--- a/libgimpcolor/gimprgb-parse.c
+++ b/libgimpcolor/gimprgb-parse.c
@@ -375,8 +375,9 @@ gimp_rgba_parse_css (GimpRGB     *rgba,
 
 /**
  * gimp_rgb_list_names:
- * @names: (out): return location for an array of color names
- * @colors: (out): return location for an array of GimpRGB structs
+ * @names: (out) (array length=n_colors) (transfer container): return location for an array of color names
+ * @colors: (out) (array length=n_colors) (transfer container): return location for an array of GimpRGB 
structs
+ * @n_colors: (out): The number of named colors
  *
  * Returns the list of <ulink
  * url="https://www.w3.org/TR/SVG/types.html";>SVG 1.0 color
@@ -386,22 +387,22 @@ gimp_rgba_parse_css (GimpRGB     *rgba,
  * arrays are allocated dynamically. You must call g_free() on the
  * @names and @colors arrays when they are not any longer needed.
  *
- * Returns: the number of named colors
- *               (i.e. the length of the returned arrays)
- *
  * Since: 2.2
  **/
-gint
+void
 gimp_rgb_list_names (const gchar ***names,
-                     GimpRGB      **colors)
+                     GimpRGB      **colors,
+                     gint          *n_colors)
 {
   gint i;
 
-  g_return_val_if_fail (names != NULL, 0);
-  g_return_val_if_fail (colors != NULL, 0);
+  g_return_if_fail (names != NULL);
+  g_return_if_fail (colors != NULL);
+  g_return_if_fail (n_colors != NULL);
 
   *names  = g_new (const gchar *, G_N_ELEMENTS (named_colors));
   *colors = g_new (GimpRGB, G_N_ELEMENTS (named_colors));
+  *n_colors = G_N_ELEMENTS (named_colors);
 
   for (i = 0; i < G_N_ELEMENTS (named_colors); i++)
     {
@@ -413,11 +414,8 @@ gimp_rgb_list_names (const gchar ***names,
                            named_colors[i].blue,
                            0xFF);
     }
-
-  return G_N_ELEMENTS (named_colors);
 }
 
-
 static gchar *
 gimp_rgb_parse_strip (const gchar *str,
                       gint         len)
diff --git a/libgimpcolor/gimprgb.h b/libgimpcolor/gimprgb.h
index 0ccce00f4c..144880f3dd 100644
--- a/libgimpcolor/gimprgb.h
+++ b/libgimpcolor/gimprgb.h
@@ -139,8 +139,9 @@ void      gimp_rgb_composite       (GimpRGB              *color1,
                                     GimpRGBCompositeMode  mode);
 
 /*  access to the list of color names  */
-gint      gimp_rgb_list_names      (const gchar ***names,
-                                    GimpRGB      **colors);
+void      gimp_rgb_list_names      (const gchar ***names,
+                                    GimpRGB      **colors,
+                                    gint          *n_colors);
 
 
 void      gimp_rgba_set            (GimpRGB       *rgba,
diff --git a/libgimpwidgets/gimpcolorhexentry.c b/libgimpwidgets/gimpcolorhexentry.c
index 5c6e057f2a..1ac6fc8fa2 100644
--- a/libgimpwidgets/gimpcolorhexentry.c
+++ b/libgimpwidgets/gimpcolorhexentry.c
@@ -139,7 +139,7 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
 
   store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GIMP_TYPE_RGB);
 
-  num_colors = gimp_rgb_list_names (&names, &colors);
+  gimp_rgb_list_names (&names, &colors, &num_colors);
 
   for (i = 0; i < num_colors; i++)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]