[template-glib] expr-eval: recursively look for closest type



commit 47957c9be9dfe5701458e1547166ce807bfbac00
Author: Christian Hergert <chergert redhat com>
Date:   Sat May 14 17:59:11 2022 -0700

    expr-eval: recursively look for closest type

 src/tmpl-expr-eval.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/src/tmpl-expr-eval.c b/src/tmpl-expr-eval.c
index ab73bfa..9cf8b5e 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -788,6 +788,23 @@ make_title (const gchar *str)
   return g_string_free (ret, FALSE);
 }
 
+static GIBaseInfo *
+find_by_gtype (GIRepository *repository,
+               GType         type)
+{
+  while ((type != G_TYPE_INVALID))
+    {
+      GIBaseInfo *info = g_irepository_find_by_gtype (repository, type);
+
+      if (info != NULL)
+        return info;
+
+      type = g_type_parent (type);
+    }
+
+  return NULL;
+}
+
 static gboolean
 tmpl_expr_gi_call_eval (TmplExprGiCall  *node,
                         TmplScope       *scope,
@@ -1068,7 +1085,7 @@ lookup_for_object:
     {
       guint n_ifaces;
 
-      base_info = g_irepository_find_by_gtype (repository, type);
+      base_info = find_by_gtype (repository, type);
 
       if (base_info == NULL)
         {


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