[gjs] arg: Generate heap values using a single template function
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: Generate heap values using a single template function
- Date: Sun, 5 Jul 2020 01:19:31 +0000 (UTC)
commit 4163c853f3c7f5878ca17e07102488b8904cd464
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Mon May 18 15:52:05 2020 +0200
arg: Generate heap values using a single template function
gi/arg.cpp | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 45d0ad24..b31905d7 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -670,6 +670,14 @@ value_to_ghashtable_key(JSContext *cx,
return true;
}
+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);
+
+ return heap_val;
+}
+
GJS_JSAPI_RETURN_CONVENTION
static bool
gjs_object_to_g_hash(JSContext *context,
@@ -727,21 +735,13 @@ gjs_object_to_g_hash(JSContext *context,
GITypeTag val_type = g_type_info_get_tag(val_param_info);
/* Use heap-allocated values for types that don't fit in a pointer */
if (val_type == GI_TYPE_TAG_INT64) {
- int64_t *heap_val = g_new(int64_t, 1);
- *heap_val = val_arg.v_int64;
- val_ptr = heap_val;
+ val_ptr = heap_value_new_from_arg<int64_t>(&val_arg);
} else if (val_type == GI_TYPE_TAG_UINT64) {
- uint64_t *heap_val = g_new(uint64_t, 1);
- *heap_val = val_arg.v_uint64;
- val_ptr = heap_val;
+ val_ptr = heap_value_new_from_arg<uint64_t>(&val_arg);
} else if (val_type == GI_TYPE_TAG_FLOAT) {
- float *heap_val = g_new(float, 1);
- *heap_val = val_arg.v_float;
- val_ptr = heap_val;
+ val_ptr = heap_value_new_from_arg<float>(&val_arg);
} else if (val_type == GI_TYPE_TAG_DOUBLE) {
- double *heap_val = g_new(double, 1);
- *heap_val = val_arg.v_double;
- val_ptr = heap_val;
+ val_ptr = heap_value_new_from_arg<double>(&val_arg);
} else {
// Other types are simply stuffed inside the pointer
val_ptr = _g_type_info_hash_pointer_from_argument(val_param_info,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]