[gjs/arg-inlines: 4/9] arg: Add GIArgument setter overload for function pointers
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/arg-inlines: 4/9] arg: Add GIArgument setter overload for function pointers
- Date: Sat, 11 Jul 2020 22:24:51 +0000 (UTC)
commit d6eb51195f25bfb1f666bec137e62ffb86112f90
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Jul 10 23:04:26 2020 -0700
arg: Add GIArgument setter overload for function pointers
Without this, we'd still need to reinterpret_cast function pointers to
void*, because it's technically not legal to convert between data and
function pointers. However, having a compiler that can do this is a
requirement of GLib, so we do need to do it sometimes anyway.
gi/arg-inl.h | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/gi/arg-inl.h b/gi/arg-inl.h
index ca910107..33366aa5 100644
--- a/gi/arg-inl.h
+++ b/gi/arg-inl.h
@@ -135,6 +135,14 @@ inline void gjs_g_argument_value_set(GIArgument* arg, T* v) {
using NonconstT = std::remove_const_t<T>;
gjs_g_argument_value<NonconstT*, TAG>(arg) = const_cast<NonconstT*>(v);
}
+
+// Store function pointers as void*. It is a requirement of GLib that your
+// compiler can do this
+template <typename ReturnT, typename... Args>
+inline void gjs_g_argument_value_set(GIArgument* arg, ReturnT (*v)(Args...)) {
+ gjs_g_argument_value<void*>(arg) = reinterpret_cast<void*>(v);
+}
+
template <>
inline void gjs_g_argument_value_set<bool>(GIArgument* arg, bool v) {
gjs_g_argument_value<bool>(arg) = !!v;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]