[gjs] Handle inout array/length pairs more correctly
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Handle inout array/length pairs more correctly
- Date: Fri, 17 Jun 2011 15:04:55 +0000 (UTC)
commit c501e3df35c00e6011eb1548496262a8d4f5519f
Author: Colin Walters <walters verbum org>
Date: Thu Jun 16 19:51:28 2011 -0400
Handle inout array/length pairs more correctly
In particular if we saw "null" for an inout array, we need to
also pass null for the length argument.
https://bugzilla.gnome.org/show_bug.cgi?id=651558
gi/function.c | 16 +++++++++++++++-
test/js/testGIMarshalling.js | 14 ++++++++++++++
2 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/gi/function.c b/gi/function.c
index 156607f..a8b0d26 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -577,6 +577,20 @@ gjs_invoke_c_function(JSContext *context,
failed = TRUE;
break;
}
+ if (direction == GI_DIRECTION_INOUT) {
+ if (in_value->v_pointer == NULL) {
+ /* Special case where we were given JS null to
+ * also pass null for length, and not a
+ * pointer to an integer that derefs to 0.
+ */
+ in_arg_cvalues[array_length_pos].v_pointer = NULL;
+ out_arg_cvalues[array_length_pos].v_pointer = NULL;
+ inout_original_arg_cvalues[array_length_pos].v_pointer = NULL;
+ } else {
+ out_arg_cvalues[array_length_pos] = inout_original_arg_cvalues[array_length_pos] = *(in_arg_cvalues + array_length_pos);
+ in_arg_cvalues[array_length_pos].v_pointer = &out_arg_cvalues[array_length_pos];
+ }
+ }
}
case PARAM_NORMAL:
/* Ok, now just convert argument normally */
@@ -588,7 +602,7 @@ gjs_invoke_c_function(JSContext *context,
}
}
- if (!failed && direction == GI_DIRECTION_INOUT) {
+ if (direction == GI_DIRECTION_INOUT && !arg_removed && !failed) {
out_arg_cvalues[c_arg_pos] = inout_original_arg_cvalues[c_arg_pos] = in_arg_cvalues[c_arg_pos];
in_arg_cvalues[c_arg_pos].v_pointer = &out_arg_cvalues[c_arg_pos];
}
diff --git a/test/js/testGIMarshalling.js b/test/js/testGIMarshalling.js
index 858b9b3..12d9623 100644
--- a/test/js/testGIMarshalling.js
+++ b/test/js/testGIMarshalling.js
@@ -8,6 +8,20 @@ const Lang = imports.lang;
function testCArray() {
var array, sum;
+ var result = GIMarshallingTests.init_function(null);
+ assertEquals(result.length, 2);
+ var success = result[0];
+ var newArray = result[1];
+ assertEquals(newArray.length, 0);
+
+ array = ["foo","bar","baz"];
+ var result = GIMarshallingTests.init_function(array);
+ var success = result[0];
+ var newArray = result[1];
+ assertEquals(2, newArray.length);
+ assertEquals(newArray[0], "foo");
+ assertEquals(newArray[1], "bar");
+
array = GIMarshallingTests.array_zero_terminated_return();
assertEquals("0", array[0]);
assertEquals("1", array[1]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]