[gjs: 1/2] gi: fix the usage of closure in CallbackIn::release
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] gi: fix the usage of closure in CallbackIn::release
- Date: Fri, 29 Apr 2022 03:17:22 +0000 (UTC)
commit 8e1c28156b32765b4f6b2e41007281ddb07ccdee
Author: Xi Ruoyao <xry111 mengyan1223 wang>
Date: Mon Mar 28 20:18:12 2022 +0800
gi: fix the usage of closure in CallbackIn::release
We were getting closure pointer from in_arg. Unfortunately, in_arg
contains the native closure pointer, which does not equals to of the
pointer to ffi_closure if libffi is built without
`--disable-exec-static-tramp`.
I guess gjs has never been really tested with such a libffi build :).
gi/arg-cache.cpp | 6 +++++-
gi/function.h | 4 ++++
2 files changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 177f246f4..ef9671aea 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -708,6 +708,8 @@ struct CallbackIn : SkipAll, Callback {
bool release(JSContext*, GjsFunctionCallState*, GIArgument*,
GIArgument*) override;
+ private:
+ ffi_closure *m_ffi_closure;
};
using CArrayIn = ExplicitArrayIn;
@@ -831,6 +833,7 @@ bool CallbackIn::in(JSContext* cx, GjsFunctionCallState* state, GIArgument* arg,
if (value.isNull() && m_nullable) {
closure = nullptr;
trampoline = nullptr;
+ m_ffi_closure = nullptr;
} else {
if (JS_TypeOfValue(cx, value) != JSTYPE_FUNCTION) {
gjs_throw(cx, "Expected function for callback argument %s, got %s",
@@ -855,6 +858,7 @@ bool CallbackIn::in(JSContext* cx, GjsFunctionCallState* state, GIArgument* arg,
return false;
}
closure = trampoline->closure();
+ m_ffi_closure = trampoline->get_ffi_closure();
}
if (has_callback_destroy()) {
@@ -1411,7 +1415,7 @@ bool CallerAllocatesOut::release(JSContext*, GjsFunctionCallState*,
GJS_JSAPI_RETURN_CONVENTION
bool CallbackIn::release(JSContext*, GjsFunctionCallState*, GIArgument* in_arg,
GIArgument* out_arg [[maybe_unused]]) {
- auto* closure = gjs_arg_get<ffi_closure*>(in_arg);
+ ffi_closure *closure = m_ffi_closure;
if (!closure)
return true;
diff --git a/gi/function.h b/gi/function.h
index 799c14903..b70c7e297 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -57,6 +57,10 @@ struct GjsCallbackTrampoline : public Gjs::Closure {
#endif
}
+ ffi_closure* get_ffi_closure() const {
+ return m_closure;
+ }
+
void mark_forever();
static void prepare_shutdown();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]