[gjs/ewlsh/fix-int64-conversion] gi: Convert GJS values to 64-bit GValue integers




commit 54cdb0564a24dab1ff1fdbc7b8abab9aba81adcc
Author: Evan Welsh <contact evanwelsh com>
Date:   Wed Aug 25 01:28:15 2021 -0700

    gi: Convert GJS values to 64-bit GValue integers
    
    Previously we relied on g_value_type_transformable to transform JS
    numbers to uint64 and int64 values, this coerced the values into
    ints and broke setting values larger than GLib.MAXINT32 during
    construction.
    
    Fixes #92

 gi/value.cpp | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/gi/value.cpp b/gi/value.cpp
index ec64f0ac..4ba2160d 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -423,6 +423,13 @@ gjs_value_to_g_value_internal(JSContext      *context,
         } else {
             return throw_expect_type(context, value, "integer");
         }
+    } else if (gtype == G_TYPE_INT64) {
+        gint64 i;
+        if (Gjs::js_value_to_c(context, value, &i)) {
+            g_value_set_int64(gvalue, i);
+        } else {
+            return throw_expect_type(context, value, "64-bit integer");
+        }
     } else if (gtype == G_TYPE_DOUBLE) {
         gdouble d;
         if (Gjs::js_value_to_c(context, value, &d)) {
@@ -446,10 +453,18 @@ gjs_value_to_g_value_internal(JSContext      *context,
         } else {
             return throw_expect_type(context, value, "unsigned integer");
         }
+    } else if (gtype == G_TYPE_UINT64) {
+        guint64 i;
+        if (Gjs::js_value_to_c(context, value, &i)) {
+            g_value_set_uint64(gvalue, i);
+        } else {
+            return throw_expect_type(context, value, "unsigned 64-bit integer");
+        }
     } else if (gtype == G_TYPE_BOOLEAN) {
         /* JS::ToBoolean() can't fail */
         g_value_set_boolean(gvalue, JS::ToBoolean(value));
-    } else if (g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_INTERFACE)) {
+    } else if (g_type_is_a(gtype, G_TYPE_OBJECT) ||
+               g_type_is_a(gtype, G_TYPE_INTERFACE)) {
         GObject *gobj;
 
         gobj = NULL;


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