[template-glib] expr-eval: use GITypelib to access symbol pointer
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] expr-eval: use GITypelib to access symbol pointer
- Date: Fri, 6 May 2022 21:42:31 +0000 (UTC)
commit 2ea9b011afaa2916fcbe346edc9a7f0e2c230d03
Author: Christian Hergert <chergert redhat com>
Date: Fri May 6 14:40:25 2022 -0700
expr-eval: use GITypelib to access symbol pointer
src/meson.build | 1 -
src/tmpl-expr-eval.c | 14 ++++++++++----
src/tmpl-gi-private.h | 5 +++++
src/tmpl-gi.c | 22 ++++++++++++++++++++++
4 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 8b9da7c..7ba2c62 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -64,7 +64,6 @@ libtemplate_glib_public_sources = [
libtemplate_glib_deps = [
dependency('gio-2.0'),
- dependency('gmodule-2.0'),
dependency('gobject-introspection-1.0'),
cc.find_library('m', required: false),
]
diff --git a/src/tmpl-expr-eval.c b/src/tmpl-expr-eval.c
index 723bca7..39af2a1 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -1016,15 +1016,21 @@ tmpl_expr_gi_call_eval (TmplExprGiCall *node,
(base_info = g_value_get_boxed (&left)) &&
g_base_info_get_type (base_info) == GI_INFO_TYPE_OBJECT)
{
- const char *type_init = g_object_info_get_type_init ((GIObjectInfo *)base_info);
- GType (*get_type) (void) = NULL;
+ TmplGTypeFunc gtype_func = tmpl_gi_get_gtype_func (base_info);
- if ((get_type = dlsym (NULL, type_init)))
+ if (gtype_func != NULL &&
+ (type = gtype_func ()) &&
+ g_type_is_a (type, G_TYPE_OBJECT))
{
- type = get_type ();
object = NULL;
goto lookup_for_object;
}
+
+ g_set_error (error,
+ TMPL_ERROR,
+ TMPL_ERROR_NOT_AN_OBJECT,
+ "Failed to locate GType function for object");
+ goto cleanup;
}
if (!G_VALUE_HOLDS_OBJECT (&left))
diff --git a/src/tmpl-gi-private.h b/src/tmpl-gi-private.h
index ed73d17..483ab5f 100644
--- a/src/tmpl-gi-private.h
+++ b/src/tmpl-gi-private.h
@@ -24,6 +24,8 @@ G_BEGIN_DECLS
#define TMPL_TYPE_TYPELIB (tmpl_typelib_get_type())
#define TMPL_TYPE_BASE_INFO (tmpl_base_info_get_type())
+typedef GType (*TmplGTypeFunc) (void);
+
GType tmpl_typelib_get_type (void);
GType tmpl_base_info_get_type (void);
gboolean tmpl_gi_argument_from_g_value (const GValue *value,
@@ -36,6 +38,9 @@ gboolean tmpl_gi_argument_to_g_value (GValue *value,
GIArgument *arg,
GITransfer xfer,
GError **error);
+TmplGTypeFunc
+ tmpl_gi_get_gtype_func (GIBaseInfo *base_info);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GIBaseInfo, g_base_info_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GIArgInfo, g_base_info_unref)
diff --git a/src/tmpl-gi.c b/src/tmpl-gi.c
index 709e49e..5db8572 100644
--- a/src/tmpl-gi.c
+++ b/src/tmpl-gi.c
@@ -479,3 +479,25 @@ tmpl_gi_argument_to_g_value (GValue *value,
return FALSE;
}
+
+TmplGTypeFunc
+tmpl_gi_get_gtype_func (GIBaseInfo *base_info)
+{
+ GITypelib *typelib;
+ const char *symbol_name;
+ TmplGTypeFunc symbol = NULL;
+
+ if (base_info == NULL || GI_INFO_TYPE_OBJECT != g_base_info_get_type (base_info))
+ return NULL;
+
+ if (!(typelib = g_base_info_get_typelib (base_info)))
+ return NULL;
+
+ if (!(symbol_name = g_object_info_get_type_init (base_info)))
+ return NULL;
+
+ if (!g_typelib_symbol (typelib, symbol_name, (gpointer *)&symbol))
+ return NULL;
+
+ return symbol;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]