[template-glib] eval: add support for pointer/pointer comparisons
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] eval: add support for pointer/pointer comparisons
- Date: Thu, 5 May 2022 22:44:09 +0000 (UTC)
commit c4d9397bc8cd14dc90173b3585f085ef8a88d8ab
Author: Christian Hergert <chergert redhat com>
Date: Thu May 5 15:30:19 2022 -0700
eval: add support for pointer/pointer comparisons
That way we can check pointer equality (although we need additional
checks for object/variant/etc comparisons).
src/tmpl-expr-eval.c | 27 +++++++++++++++++++++++++++
tests/test1.script | 2 ++
2 files changed, 29 insertions(+)
---
diff --git a/src/tmpl-expr-eval.c b/src/tmpl-expr-eval.c
index 23b65ed..c2797d0 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -1689,6 +1689,30 @@ ne_boolean_boolean (const GValue *left,
return TRUE;
}
+static gboolean
+eq_pointer_pointer (const GValue *left,
+ const GValue *right,
+ GValue *return_value,
+ GError **error)
+{
+ g_value_init (return_value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (return_value,
+ g_value_get_pointer (left) == g_value_get_pointer (right));
+ return TRUE;
+}
+
+static gboolean
+ne_pointer_pointer (const GValue *left,
+ const GValue *right,
+ GValue *return_value,
+ GError **error)
+{
+ g_value_init (return_value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (return_value,
+ g_value_get_pointer (left) != g_value_get_pointer (right));
+ return TRUE;
+}
+
static gboolean
eq_enum_string (const GValue *left,
const GValue *right,
@@ -1805,6 +1829,9 @@ build_dispatch_table (void)
ADD_DISPATCH_FUNC (TMPL_EXPR_EQ, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, eq_boolean_boolean);
ADD_DISPATCH_FUNC (TMPL_EXPR_NE, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, ne_boolean_boolean);
+ ADD_DISPATCH_FUNC (TMPL_EXPR_EQ, G_TYPE_POINTER, G_TYPE_POINTER, eq_pointer_pointer);
+ ADD_DISPATCH_FUNC (TMPL_EXPR_NE, G_TYPE_POINTER, G_TYPE_POINTER, ne_pointer_pointer);
+
#undef ADD_DISPATCH_FUNC
return table;
diff --git a/tests/test1.script b/tests/test1.script
index 8d13ee2..83b9cdc 100644
--- a/tests/test1.script
+++ b/tests/test1.script
@@ -71,4 +71,6 @@ assert(action)
assert(typeof(action) == typeof(Gio.SimpleAction))
assert(typeof(action) != typeof(Gio.SimpleActionGroup))
+assert(null == null)
+
1234;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]