[gjs/gnome-40: 21/30] arg-cache: Do not mark a function returning void* as skip-all




commit d4b7352f17a39600bd92c03b82ad0de4a67b452c
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Apr 29 20:24:53 2021 +0200

    arg-cache: Do not mark a function returning void* as skip-all
    
    While it's true that a void function has no return value, this is not
    true in the case it's a void pointer.
    
    Not doing this, will cause a crash at ffi level because we're passing to
    it a null return value pointer, while it's expecting to fill it with
    the returned data.
    
    Fixes: #406
    
    (cherry-picked from commit ab1a4ed0)

 gi/arg-cache.cpp                        | 3 ++-
 installed-tests/js/testGIMarshalling.js | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 1598dd02..97d15325 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -1261,7 +1261,8 @@ bool gjs_arg_cache_build_return(JSContext*, GjsArgumentCache* self,
 
     g_callable_info_load_return_type(callable, &self->type_info);
 
-    if (g_type_info_get_tag(&self->type_info) == GI_TYPE_TAG_VOID) {
+    if (g_type_info_get_tag(&self->type_info) == GI_TYPE_TAG_VOID &&
+        !g_type_info_is_pointer(&self->type_info)) {
         *inc_counter_out = false;
         gjs_arg_cache_set_skip_all(self);
         return true;
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index 4d780412..63e4b99a 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -906,6 +906,10 @@ describe('Callback', function () {
 });
 
 describe('Raw pointers', function () {
+    it('gets an allocated return value', function () {
+        expect(GIMarshallingTests.pointer_in_return(null)).toBeFalsy();
+    });
+
     xit('can be roundtripped at least if the pointer is null', function () {
         expect(GIMarshallingTests.pointer_in_return(null)).toBeNull();
     }).pend('https://gitlab.gnome.org/GNOME/gjs/merge_requests/46');


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