[gjs/ewlsh/fix-fundamental-parameters: 1/2] arg-cache: Add fundamental marshaller.




commit 6353d1e6712f07bc2e1a9758d5f8d8d11dae4bf2
Author: Evan Welsh <noreply evanwelsh com>
Date:   Tue Oct 6 22:55:46 2020 -0500

    arg-cache: Add fundamental marshaller.
    
    Addresses regression where fundamental objects cannot be passed into functions.
    
    Fixes #353

 gi/arg-cache.cpp | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 737afe56..dc8bcd62 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -29,6 +29,7 @@
 #include "gi/boxed.h"
 #include "gi/foreign.h"
 #include "gi/function.h"
+#include "gi/fundamental.h"
 #include "gi/gerror.h"
 #include "gi/gtype.h"
 #include "gi/js-value-inl.h"
@@ -666,6 +667,25 @@ static bool gjs_marshal_object_in_in(JSContext* cx, GjsArgumentCache* self,
                                                self->transfer, gtype);
 }
 
+GJS_JSAPI_RETURN_CONVENTION
+static bool gjs_marshal_fundamental_in_in(JSContext* cx, GjsArgumentCache* self,
+                                          GjsFunctionCallState*,
+                                          GIArgument* arg,
+                                          JS::HandleValue value) {
+    if (value.isNull())
+        return self->handle_nullable(cx, arg);
+
+    GType gtype = g_registered_type_info_get_g_type(self->contents.info);
+    g_assert(gtype != G_TYPE_NONE);
+
+    if (!value.isObject())
+        return report_gtype_mismatch(cx, self->arg_name, value, gtype);
+
+    JS::RootedObject object(cx, &value.toObject());
+    return FundamentalBase::transfer_to_gi_argument(
+        cx, object, arg, GI_DIRECTION_IN, self->transfer, gtype);
+}
+
 GJS_JSAPI_RETURN_CONVENTION
 static bool gjs_marshal_gtype_struct_instance_in(JSContext* cx,
                                                  GjsArgumentCache* self,
@@ -1054,6 +1074,14 @@ static const GjsArgumentMarshallers object_in_marshallers = {
     gjs_arg_cache_interface_free,  // free
 };
 
+static const GjsArgumentMarshallers fundamental_in_marshallers = {
+    gjs_marshal_fundamental_in_in,  // in
+    gjs_marshal_skipped_out,        // out
+    // This is a smart marshaller, no release needed
+    gjs_marshal_skipped_release,   // release
+    gjs_arg_cache_interface_free,  // free
+};
+
 static const GjsArgumentMarshallers union_in_marshallers = {
     gjs_marshal_union_in_in,  // in
     gjs_marshal_skipped_out,  // out
@@ -1359,6 +1387,11 @@ static bool gjs_arg_cache_build_interface_in_arg(JSContext* cx,
                 return true;
             }
 
+            if (G_TYPE_IS_INSTANTIATABLE(gtype)) {
+                self->marshallers = &fundamental_in_marshallers;
+                return true;
+            }
+
             // generic boxed type
             if (gtype == G_TYPE_NONE && self->transfer != GI_TRANSFER_NOTHING) {
                 // Can't transfer ownership of a structure type not


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