[gjs] arg: Add arguments setter/getter to use implicit types
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: Add arguments setter/getter to use implicit types
- Date: Sun, 5 Jul 2020 01:19:36 +0000 (UTC)
commit cacc79b3bc24b9d17e91821fa7cbd9d4f8efd75c
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Fri May 8 21:00:04 2020 +0200
arg: Add arguments setter/getter to use implicit types
gi/arg-inl.h | 10 ++++++++++
gi/arg.cpp | 6 +++---
2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gi/arg-inl.h b/gi/arg-inl.h
index 4c97b2b6..6f20e5d7 100644
--- a/gi/arg-inl.h
+++ b/gi/arg-inl.h
@@ -110,3 +110,13 @@ template <>
GJS_USE inline decltype(auto) gjs_g_argument_value<void*>(GIArgument* arg) {
return gjs_g_argument_value(arg, &GIArgument::v_pointer);
}
+
+template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
+inline void gjs_g_argument_value_set(GIArgument* arg, T v) {
+ gjs_g_argument_value<T, TAG>(arg) = v;
+}
+
+template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
+GJS_USE inline T gjs_g_argument_value_get(GIArgument* arg) {
+ return gjs_g_argument_value<T, TAG>(arg);
+}
diff --git a/gi/arg.cpp b/gi/arg.cpp
index b31905d7..2097acd8 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -673,7 +673,7 @@ value_to_ghashtable_key(JSContext *cx,
template <typename T>
GJS_USE static T* heap_value_new_from_arg(GIArgument* val_arg) {
T* heap_val = g_new(T, 1);
- *heap_val = gjs_g_argument_value<T>(val_arg);
+ *heap_val = gjs_g_argument_value_get<T>(val_arg);
return heap_val;
}
@@ -2450,7 +2450,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool fill_vector_from_carray(
JSContext* cx, JS::RootedValueVector& elems, // NOLINT(runtime/references)
GITypeInfo* param_info, GIArgument* arg, void* array, size_t length) {
for (size_t i = 0; i < length; i++) {
- gjs_g_argument_value<T>(arg) = *(static_cast<T*>(array) + i);
+ gjs_g_argument_value_set(arg, *(static_cast<T*>(array) + i));
if (!gjs_value_from_g_argument(cx, elems[i], param_info, arg, true))
return false;
@@ -2696,7 +2696,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool fill_vector_from_zero_terminated_carray(
T* array = static_cast<T*>(c_array);
for (size_t i = 0; array[i]; i++) {
- gjs_g_argument_value<T>(arg) = array[i];
+ gjs_g_argument_value_set(arg, array[i]);
if (!elems.growBy(1)) {
JS_ReportOutOfMemory(cx);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]