[gjs] function: Use consistent types when setting ffi_arg from return value



commit ebcf4f4d981b6329a7f2ddce44f09a5206e57b8e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue May 12 15:28:08 2020 +0200

    function: Use consistent types when setting ffi_arg from return value
    
    Make sure we always get the same value we set in gjs_value_to_g_argument()

 gi/function.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index e194b8ec..71c1c5f6 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -114,6 +114,7 @@ set_return_ffi_arg_from_giargument (GITypeInfo  *ret_type,
                                     void        *result,
                                     GIArgument  *return_value)
 {
+    // Be consistent with gjs_value_to_g_argument()
     switch (g_type_info_get_tag(ret_type)) {
     case GI_TYPE_TAG_VOID:
         g_assert_not_reached();
@@ -165,12 +166,24 @@ set_return_ffi_arg_from_giargument (GITypeInfo  *ret_type,
         }
         break;
     case GI_TYPE_TAG_UINT64:
-    /* Other primitive and pointer types need to squeeze into 64-bit ffi_arg too */
+        // Other primitive types need to squeeze into 64-bit ffi_arg too
+        *static_cast<ffi_arg*>(result) = gjs_arg_get<uint64_t>(return_value);
+        break;
     case GI_TYPE_TAG_FLOAT:
+        *static_cast<ffi_arg*>(result) = gjs_arg_get<float>(return_value);
+        break;
     case GI_TYPE_TAG_DOUBLE:
+        *static_cast<ffi_arg*>(result) = gjs_arg_get<double>(return_value);
+        break;
     case GI_TYPE_TAG_GTYPE:
+        *static_cast<ffi_arg*>(result) =
+            gjs_arg_get<GType, GI_TYPE_TAG_GTYPE>(return_value);
+        break;
     case GI_TYPE_TAG_UTF8:
     case GI_TYPE_TAG_FILENAME:
+        *static_cast<ffi_arg*>(result) =
+            reinterpret_cast<ffi_arg>(gjs_arg_get<char*>(return_value));
+        break;
     case GI_TYPE_TAG_ARRAY:
     case GI_TYPE_TAG_GLIST:
     case GI_TYPE_TAG_GSLIST:


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