[gjs: 3/4] function: Cleanup function call GError on failures




commit 056a2df6ba04efd8d36a7860bcfca321eaa5832f
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Oct 26 18:13:58 2020 +0100

    function: Cleanup function call GError on failures
    
    Use a GjsAutoError to handle this, so that we'll have automatic cleanup

 gi/function.cpp | 4 ++--
 gi/function.h   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 8922332c..0ef9bff1 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -931,7 +931,7 @@ bool Function::invoke(JSContext* context, const JS::CallArgs& args,
     }
 
     // This pointer needs to exist on the stack across the ffi_call() call
-    GError** errorp = &state.local_error;
+    GError** errorp = state.local_error.out();
 
     /* Did argument conversion fail?  In that case, skip invocation and jump to release
      * processing. */
@@ -1072,7 +1072,7 @@ bool Function::finish_invoke(JSContext* cx, const JS::CallArgs& args,
     }
 
     if (!state->failed && state->did_throw_gerror()) {
-        return gjs_throw_gerror(cx, state->local_error);
+        return gjs_throw_gerror(cx, state->local_error.release());
     } else if (state->failed) {
         return false;
     } else {
diff --git a/gi/function.h b/gi/function.h
index 3476b622..74143c4c 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -92,7 +92,7 @@ struct GjsFunctionCallState {
     std::unordered_set<GIArgument*> ignore_release;
     JS::RootedObject instance_object;
     JS::RootedValueVector return_values;
-    GError* local_error = nullptr;
+    GjsAutoError local_error;
     int gi_argc = 0;
     unsigned processed_c_args = 0;
     bool failed : 1;
@@ -121,7 +121,7 @@ struct GjsFunctionCallState {
     constexpr int first_arg_offset() const { return is_method ? 2 : 1; }
 
     constexpr bool did_throw_gerror() const {
-        return can_throw_gerror && local_error != nullptr;
+        return can_throw_gerror && local_error;
     }
 
     constexpr bool call_completed() { return !failed && !did_throw_gerror(); }


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