[gimp] libgimp: change the return values of GimpPlugIn::init_procedures()



commit a50069e176932ec403b2c09b2af7333edca0c7de
Author: Michael Natterer <mitch gimp org>
Date:   Fri Aug 2 19:10:13 2019 +0200

    libgimp: change the return values of GimpPlugIn::init_procedures()
    
    and ::query_procedures() to a GList* of strings.

 libgimp/gimpplugin-private.c    | 42 ++++++++++++++++++++---------------------
 libgimp/gimpplugin.c            |  4 ++--
 libgimp/gimpplugin.h            | 37 ++++++++++++++++++------------------
 plug-ins/common/goat-exercise.c | 10 +++-------
 plug-ins/help/help.c            | 10 +++-------
 5 files changed, 47 insertions(+), 56 deletions(-)
---
diff --git a/libgimp/gimpplugin-private.c b/libgimp/gimpplugin-private.c
index 5f0920cf29..e4f9128ff1 100644
--- a/libgimp/gimpplugin-private.c
+++ b/libgimp/gimpplugin-private.c
@@ -34,7 +34,7 @@
 /*  local function prototpes  */
 
 static void   gimp_plug_in_register          (GimpPlugIn      *plug_in,
-                                              gboolean         init);
+                                              GList           *procedures);
 static void   gimp_plug_in_loop              (GimpPlugIn      *plug_in);
 static void   gimp_plug_in_proc_run          (GimpPlugIn      *plug_in,
                                               GPProcRun       *proc_run);
@@ -52,10 +52,13 @@ _gimp_plug_in_query (GimpPlugIn *plug_in)
 {
   g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
-  if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures)
-    return;
+  if (GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures)
+    {
+      GList *procedures =
+        GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures (plug_in);
 
-  gimp_plug_in_register (plug_in, FALSE);
+      gimp_plug_in_register (plug_in, procedures);
+    }
 }
 
 void
@@ -63,10 +66,13 @@ _gimp_plug_in_init (GimpPlugIn *plug_in)
 {
   g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
-  if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures)
-    return;
+  if (GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures)
+    {
+      GList *procedures =
+        GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures (plug_in);
 
-  gimp_plug_in_register (plug_in, TRUE);
+      gimp_plug_in_register (plug_in, procedures);
+    }
 }
 
 void
@@ -103,22 +109,16 @@ _gimp_plug_in_extension_read (GIOChannel  *channel,
 
 static void
 gimp_plug_in_register (GimpPlugIn *plug_in,
-                       gboolean    init)
+                       GList      *procedures)
 {
-  gchar **procedures;
-  gchar **name;
-  GList  *list;
-
-  if (init)
-    procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures (plug_in);
-  else
-    procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures (plug_in);
+  GList *list;
 
-  for (name = procedures; *name; name++)
+  for (list = procedures; list; list = g_list_next (list))
     {
+      const gchar   *name = list->data;
       GimpProcedure *procedure;
 
-      procedure = gimp_plug_in_create_procedure (plug_in, *name);
+      procedure = gimp_plug_in_create_procedure (plug_in, name);
       if (procedure)
         {
           _gimp_procedure_register (procedure);
@@ -126,11 +126,11 @@ gimp_plug_in_register (GimpPlugIn *plug_in,
         }
       else
         {
-          g_warning ("Plug-in failed to create procedure '%s'\n",
-                     *name);
+          g_warning ("Plug-in failed to create procedure '%s'\n", name);
         }
     }
-  g_clear_pointer (&procedures, g_strfreev);
+
+  g_list_free_full (procedures, g_free);
 
   if (plug_in->priv->translation_domain_name)
     {
diff --git a/libgimp/gimpplugin.c b/libgimp/gimpplugin.c
index 445b646d91..fac4b66e98 100644
--- a/libgimp/gimpplugin.c
+++ b/libgimp/gimpplugin.c
@@ -225,8 +225,8 @@ gimp_plug_in_add_menu_branch (GimpPlugIn  *plug_in,
  * %GIMP_EXTENSION procedures it implements is invoked.
  *
  * This function will only ever be called with names returned by
- * implementations of GimpPlugIn::init_procedures() or
- * GimpPlugIn::query_procedures().
+ * implementations of GimpPlugInClass::init_procedures() or
+ * GimpPlugInClass::query_procedures().
  *
  * Returns: (transfer full): The newly created #GimpProcedure.
  **/
diff --git a/libgimp/gimpplugin.h b/libgimp/gimpplugin.h
index 7f5c364b5e..2d8c4bb3be 100644
--- a/libgimp/gimpplugin.h
+++ b/libgimp/gimpplugin.h
@@ -58,41 +58,40 @@ struct _GimpPlugInClass
    * @plug_in: a #GimpPlugIn.
    *
    * This method can be overridden by all plug-ins to return a newly
-   * allocated array of allocated strings naming the procedures
+   * allocated GList of allocated strings naming the procedures
    * registered by this plug-in.
-   * This array of strings must be NULL-terminated (i.e. freeable by
-   * g_strfreev()).
    *
-   * See documentation of init_procedures() for differences.
+   * See documentation of GimpPlugInClass::init_procedures() for
+   * differences.
    *
-   * Returns: (array zero-terminated=1) (transfer full):
+   * Returns: (element-type gchar*) (transfer full):
    *          the names of the procedures registered by @plug_in.
    */
-  gchar         ** (* query_procedures) (GimpPlugIn  *plug_in);
+  GList          * (* query_procedures) (GimpPlugIn  *plug_in);
 
   /**
    * GimpPlugInClass::init_procedures:
    * @plug_in: a #GimpPlugIn.
    *
    * This method can be overridden by all plug-ins to return a newly
-   * allocated array of allocated strings naming procedures registered
+   * allocated #GList of allocated strings naming procedures registered
    * by this plug-in.
-   * This array of strings must be NULL-terminated (i.e. freeable by
-   * g_strfreev()).
    *
-   * It is different from query_procedures() in that init happens at every
-   * startup, whereas query happens only once in the life of a plug-in
-   * (right after installation or update). Hence init_procedures()
-   * typically returns procedures dependent to runtime conditions (such
-   * as the presence of a third-party tool), whereas query_procedures()
-   * would usually return unconditional and always available procedures.
-   * Most of the time, you only want to override query_procedures() and
-   * leave init_procedures() untouched.
+   * It is different from GimpPlugInClass::query_procedures() in that
+   * init happens at every startup, whereas query happens only once in
+   * the life of a plug-in (right after installation or update). Hence
+   * GimpPlugInClass::init_procedures() typically returns procedures
+   * dependent to runtime conditions (such as the presence of a
+   * third-party tool), whereas GimpPlugInClass::query_procedures()
+   * would usually return unconditional and always available
+   * procedures.  Most of the time, you only want to override
+   * GimpPlugInClass::query_procedures() and leave
+   * GimpPlugInClass::init_procedures() untouched.
    *
-   * Returns: (array zero-terminated=1) (transfer full):
+   * Returns: (element-type gchar*) (transfer full):
    *          the names of the procedures registered by @plug_in.
    */
-  gchar         ** (* init_procedures)  (GimpPlugIn  *plug_in);
+  GList          * (* init_procedures)  (GimpPlugIn  *plug_in);
 
   /**
    * GimpPlugInClass::create_procedure:
diff --git a/plug-ins/common/goat-exercise.c b/plug-ins/common/goat-exercise.c
index 986dd2ed54..8820f22edb 100644
--- a/plug-ins/common/goat-exercise.c
+++ b/plug-ins/common/goat-exercise.c
@@ -52,7 +52,7 @@ struct _GoatClass
 
 GType                   goat_get_type         (void) G_GNUC_CONST;
 
-static gchar         ** goat_query_procedures (GimpPlugIn           *plug_in);
+static GList          * goat_query_procedures (GimpPlugIn           *plug_in);
 static GimpProcedure  * goat_create_procedure (GimpPlugIn           *plug_in,
                                                const gchar          *name);
 
@@ -80,14 +80,10 @@ goat_init (Goat *goat)
 {
 }
 
-static gchar **
+static GList *
 goat_query_procedures (GimpPlugIn *plug_in)
 {
-  gchar **procedures = g_new0 (gchar *, 2);
-
-  procedures[0] = g_strdup (PLUG_IN_PROC);
-
-  return procedures;
+  return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
 }
 
 static GimpProcedure *
diff --git a/plug-ins/help/help.c b/plug-ins/help/help.c
index ffa1f5b365..dfa331b13b 100644
--- a/plug-ins/help/help.c
+++ b/plug-ins/help/help.c
@@ -70,7 +70,7 @@ typedef struct
 
 GType                   help_get_type          (void) G_GNUC_CONST;
 
-static gchar         ** help_query_procedures  (GimpPlugIn           *plug_in);
+static GList          * help_query_procedures  (GimpPlugIn           *plug_in);
 static GimpProcedure  * help_create_procedure  (GimpPlugIn           *plug_in,
                                                 const gchar          *name);
 
@@ -112,14 +112,10 @@ help_init (Help *help)
 {
 }
 
-static gchar **
+static GList *
 help_query_procedures (GimpPlugIn *plug_in)
 {
-  gchar **procedures = g_new0 (gchar *, 2);
-
-  procedures[0] = g_strdup (GIMP_HELP_EXT_PROC);
-
-  return procedures;
+  return g_list_append (NULL, g_strdup (GIMP_HELP_EXT_PROC));
 }
 
 static GimpProcedure *


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