[gjs: 8/12] function: Use a vector to hold the completed trampolines
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 8/12] function: Use a vector to hold the completed trampolines
- Date: Sun, 20 Sep 2020 22:13:03 +0000 (UTC)
commit 8b42e173e8eb1a03bf8045412818563b6f9b5ee0
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Thu Sep 3 20:22:57 2020 +0200
function: Use a vector to hold the completed trampolines
Other than being more c++ style, it allows us to handle cleanups
automatically.
gi/function.cpp | 11 ++++-------
tools/process_iwyu.py | 1 +
2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index ad2f0af7..5adacc62 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -31,6 +31,7 @@
#include <new>
#include <string>
#include <type_traits>
+#include <vector>
#include <ffi.h>
#include <girepository.h>
@@ -88,7 +89,7 @@ extern struct JSClass gjs_function_class;
* while it's in use, this list keeps track of ones that
* will be freed the next time we invoke a C function.
*/
-static GSList *completed_trampolines = NULL; /* GjsCallbackTrampoline */
+static std::vector<GjsAutoCallbackTrampoline> completed_trampolines;
GJS_DEFINE_PRIV_FROM_JS(Function, gjs_function_class)
@@ -525,7 +526,7 @@ out:
if (trampoline->scope == GI_SCOPE_TYPE_ASYNC) {
// We don't release the trampoline here as we've an extra ref that has
// been set in gjs_marshal_callback_in()
- completed_trampolines = g_slist_prepend(completed_trampolines, trampoline);
+ completed_trampolines.emplace_back(trampoline.get());
}
gjs->schedule_gc_if_needed();
@@ -637,11 +638,7 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
g_base_info_get_name(function->info));
}
-void gjs_function_clear_async_closures() {
- g_slist_free_full(
- static_cast<GSList*>(g_steal_pointer(&completed_trampolines)),
- (GDestroyNotify)gjs_callback_trampoline_unref);
-}
+void gjs_function_clear_async_closures() { completed_trampolines.clear(); }
static void* get_return_ffi_pointer_from_giargument(
GjsArgumentCache* return_arg, GIFFIReturnValue* return_value) {
diff --git a/tools/process_iwyu.py b/tools/process_iwyu.py
index 9cfa8f5a..1e63ac1d 100755
--- a/tools/process_iwyu.py
+++ b/tools/process_iwyu.py
@@ -63,6 +63,7 @@ FALSE_POSITIVES = (
# IWYU weird false positive when using std::vector::emplace_back() or
# std::vector::push_back()
+ ('gi/function.cpp', '#include <algorithm>', 'for max'),
('gi/private.cpp', '#include <algorithm>', 'for max'),
('gjs/importer.cpp', '#include <algorithm>', 'for max'),
('modules/cairo-context.cpp', '#include <algorithm>', 'for max'),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]