[perl-Glib-Object-Introspection/more-arrays] WIP: array → SV: support GArray, GPtrArray and GByteArray



commit 3fd0f011ccab9131ace192a99593c988f6314c67
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Tue Feb 17 22:08:27 2015 +0100

    WIP: array → SV: support GArray, GPtrArray and GByteArray

 gperl-i11n-marshal-array.c |    2 ++
 t/arrays.t                 |   36 +++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/gperl-i11n-marshal-array.c b/gperl-i11n-marshal-array.c
index e557f55..3ced420 100644
--- a/gperl-i11n-marshal-array.c
+++ b/gperl-i11n-marshal-array.c
@@ -89,6 +89,8 @@ array_to_sv (GITypeInfo *info,
         * specially.  Prime example: GValue *values = g_new0 (GValue, n);
         */
        need_struct_value_semantics =
+               /* is a raw C array, and ... */
+               GI_ARRAY_TYPE_C == array_type &&
                /* is a compound type, and... */
                !G_TYPE_TAG_IS_BASIC (param_tag) &&
                /* ... a non-pointer is wanted */
diff --git a/t/arrays.t b/t/arrays.t
index c7d99c9..a2e71f1 100644
--- a/t/arrays.t
+++ b/t/arrays.t
@@ -6,7 +6,7 @@ use strict;
 use warnings;
 use utf8;
 
-plan tests => 30;
+plan tests => 38;
 
 ok (Regress::test_strv_in ([ '1', '2', '3' ]));
 
@@ -53,12 +53,34 @@ is (Regress::test_gslist_null_out (), undef);
 
 # -----------------------------------------------------------------------------
 
+my $int_array_ref = [-1, 0, 1, 2];
+my $boxed_array_ref = [map { Glib::Boxed::new ('GI::BoxedStruct', long_ => $_) } (1, 2, 3)];
+
+# Init-like.
 is_deeply ([GI::init_function ([qw/a b c/])], [Glib::TRUE, [qw/a b/]]);
 
-my $test_array_ref = [-1, 0, 1, 2];
-is_deeply (GI::array_fixed_int_return (), $test_array_ref);
-is_deeply (GI::array_fixed_short_return (), $test_array_ref);
-GI::array_fixed_int_in ($test_array_ref);
-GI::array_fixed_short_in ($test_array_ref);
-is_deeply (GI::array_fixed_out (), $test_array_ref);
+# Fixed size.
+is_deeply (GI::array_fixed_int_return (), $int_array_ref);
+is_deeply (GI::array_fixed_short_return (), $int_array_ref);
+GI::array_fixed_int_in ($int_array_ref);
+GI::array_fixed_short_in ($int_array_ref);
+is_deeply (GI::array_fixed_out (), $int_array_ref);
 is_deeply (GI::array_fixed_out_struct (), [{long_ => 7, int8 => 6}, {long_ => 6, int8 => 7}]);
+is_deeply (GI::array_fixed_inout ($int_array_ref), [2, 1, 0, -1]);
+
+# Variable size.
+is_deeply (GI::array_return (), $int_array_ref);
+is_deeply ([GI::array_return_etc (23, 42)], [[23, 0, 1, 42], 65]);
+GI::array_in ($int_array_ref);
+GI::array_in_len_before ($int_array_ref);
+GI::array_in_len_zero_terminated ($int_array_ref);
+GI::array_string_in ([qw/foo bar/]);
+GI::array_uint8_in ([map { ord } qw/a b c d/]);
+GI::array_struct_in ($boxed_array_ref);
+GI::array_struct_value_in ($boxed_array_ref);
+GI::array_struct_take_in ($boxed_array_ref);
+is ($boxed_array_ref->[2]->long_, 3);
+GI::array_simple_struct_in ([map { { long_ => $_ } } (1, 2, 3)]);
+GI::multi_array_key_value_in ([qw/one two three/],
+                              [map { Glib::Object::Introspection::GValueWrapper->new ('Glib::Int', $_) } (1, 
2, 3)]);
+# FIXME: GI::array_enum_in ([qw/value1 value2 value3/]);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]