[gjs: 3/16] function: Allocate ffi_arg_pointers using an unique_ptr array




commit a6c943273e9ba6775c3550e3c47a433edb563a7c
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Oct 26 18:00:04 2020 +0100

    function: Allocate ffi_arg_pointers using an unique_ptr array
    
    As commit before, better not to use alloca(), while we've c++ handling
    the lifetime of our array.

 gi/function.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 39f41f62..96c1959a 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -778,7 +778,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
     // index inside ffi_arg_pointers.
     GjsFunctionCallState state(context, function->info, gi_argc);
 
-    void** ffi_arg_pointers = g_newa(void*, ffi_argc);
+    auto ffi_arg_pointers = std::make_unique<void*[]>(ffi_argc);
 
     failed = false;
     unsigned ffi_arg_pos = 0;  // index into ffi_arg_pointers
@@ -873,7 +873,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
     return_value_p = get_return_ffi_pointer_from_giargument(
         &function->arguments[-1], &return_value);
     ffi_call(&(function->invoker.cif), FFI_FN(function->invoker.native_address),
-             return_value_p, ffi_arg_pointers);
+             return_value_p, ffi_arg_pointers.get());
 
     /* Return value and out arguments are valid only if invocation doesn't
      * return error. In arguments need to be released always.


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