[template-glib] eval: make ctor for GI type work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] eval: make ctor for GI type work
- Date: Thu, 5 May 2022 01:32:05 +0000 (UTC)
commit 0d2c278b3b112e8343e349b1b41756714b87a98a
Author: Christian Hergert <chergert redhat com>
Date: Wed May 4 18:30:42 2022 -0700
eval: make ctor for GI type work
src/meson.build | 1 +
src/tmpl-expr-eval.c | 30 ++++++++++++++++++++++++++++--
src/tmpl-expr-parser.y | 22 +++++++++++-----------
tests/test1.script | 4 ++++
4 files changed, 44 insertions(+), 13 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 63d27da..bc654e1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -64,6 +64,7 @@ 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 a363a6f..6188877 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <dlfcn.h>
#include <girepository.h>
#include <math.h>
#include <string.h>
@@ -744,6 +745,7 @@ tmpl_expr_gi_call_eval (TmplExprGiCall *node,
GType type;
guint dispatch_len = 0;
guint n_args;
+ guint offset = 0;
guint i;
g_assert (node != NULL);
@@ -906,6 +908,21 @@ tmpl_expr_gi_call_eval (TmplExprGiCall *node,
goto apply_args;
}
+ if (G_VALUE_HOLDS (&left, TMPL_TYPE_BASE_INFO) &&
+ (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;
+
+ if ((get_type = dlsym (NULL, type_init)))
+ {
+ type = get_type ();
+ object = NULL;
+ goto lookup_for_object;
+ }
+ }
+
if (!G_VALUE_HOLDS_OBJECT (&left))
{
g_set_error (error,
@@ -929,6 +946,7 @@ tmpl_expr_gi_call_eval (TmplExprGiCall *node,
type = G_OBJECT_TYPE (object);
+lookup_for_object:
while (g_type_is_a (type, G_TYPE_OBJECT))
{
guint n_ifaces;
@@ -985,7 +1003,15 @@ tmpl_expr_gi_call_eval (TmplExprGiCall *node,
in_args = g_array_new (FALSE, TRUE, sizeof (GIArgument));
g_array_set_size (in_args, n_args + 1);
- g_array_index (in_args, GIArgument, 0).v_pointer = object;
+ if (object != NULL)
+ {
+ g_array_index (in_args, GIArgument, 0).v_pointer = object;
+ offset = 1;
+ }
+ else
+ {
+ in_args->len--;
+ }
dispatch_args = (GIArgument *)(gpointer)in_args->data;
dispatch_len = in_args->len;
@@ -996,7 +1022,7 @@ apply_args:
for (i = 0; i < n_args; i++)
{
g_autoptr(GIArgInfo) arg_info = g_callable_info_get_arg ((GICallableInfo *)function, i);
- GIArgument *arg = &g_array_index (in_args, GIArgument, i + 1);
+ GIArgument *arg = &g_array_index (in_args, GIArgument, i + offset);
GValue *value = &g_array_index (values, GValue, i);
GITypeInfo type_info = { 0 };
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index a1d7e16..9a8efd2 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -237,6 +237,17 @@ exp: exp CMP exp {
$$ = tmpl_expr_new_symbol_assign ($1, $3);
g_free ($1);
}
+ | BUILTIN '(' explist ')' {
+ $$ = tmpl_expr_new_fn_call ($1, $3);
+ }
+ | NAME '(' explist ')' {
+ $$ = tmpl_expr_new_user_fn_call ($1, $3);
+ g_free ($1);
+ }
+ | NAME '(' ')' {
+ $$ = tmpl_expr_new_user_fn_call ($1, NULL);
+ g_free ($1);
+ }
| exp '.' NAME '(' ')' {
$$ = tmpl_expr_new_gi_call ($1, $3, NULL);
g_free ($3);
@@ -253,17 +264,6 @@ exp: exp CMP exp {
$$ = tmpl_expr_new_setattr ($1, $3, $5);
g_free ($3);
}
- | BUILTIN '(' explist ')' {
- $$ = tmpl_expr_new_fn_call ($1, $3);
- }
- | NAME '(' explist ')' {
- $$ = tmpl_expr_new_user_fn_call ($1, $3);
- g_free ($1);
- }
- | NAME '(' ')' {
- $$ = tmpl_expr_new_user_fn_call ($1, NULL);
- g_free ($1);
- }
| exp '(' ')' {
$$ = tmpl_expr_new_anon_call ($1, NULL);
}
diff --git a/tests/test1.script b/tests/test1.script
index fb5809d..0bb0e4f 100644
--- a/tests/test1.script
+++ b/tests/test1.script
@@ -56,4 +56,8 @@ end
myfunc = func() 9*3
assert(myfunc() == 27);
+# test out construction
+group = Gio.SimpleActionGroup.new()
+assert(group)
+
1234;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]