Skip to content
Browse files

char vectors are arrays again

  • Loading branch information...
1 parent b9188fd commit 990c238574292b318d6de4e7f7e9c1c6da4576a8 @wjackson committed Apr 21, 2012
Showing with 15 additions and 8 deletions.
  1. +10 −3 kparse.c
  2. +1 −1 lib/K.pm
  3. +1 −1 lib/K/Raw.pm
  4. +1 −1 t/k.t
  5. +2 −2 t/raw.t
View
13 kparse.c
@@ -431,14 +431,21 @@ SV* byte_vector_from_k(K k) {
}
SV* char_vector_from_k(K k) {
- char byte_str[k->n];
+ AV *av = newAV();
+ char byte_str[1];
int i = 0;
for (i = 0; i < k->n; i++) {
- byte_str[i] = kG(k)[i];
+ if (kG(k)[i] == 0) {
+ av_push(av, &PL_sv_undef);
+ continue;
+ }
+
+ byte_str[0] = kG(k)[i];
+ av_push(av, newSVpvn(byte_str, 1));
}
- return newSVpvn(byte_str, k->n);
+ return newRV_noinc( (SV*)av );
}
SV* short_vector_from_k(K k) {
View
2 lib/K.pm
@@ -113,7 +113,7 @@ K - Perl bindings for k (aka q, aka kdb, aka kx)
$k->cmd( '4 + 4' ); # 8
- $k->cmd( q/"abc"/ ); # "abc"
+ $k->cmd( q/"abc"/ ); # ['a', 'b', 'c']
$k->cmd( q/`foo`bar!(1;2)/ ); # { foo => 1, bar => 2 }
View
2 lib/K/Raw.pm
@@ -32,7 +32,7 @@ K::Raw - Low-level Perl bindings for k (aka q, aka kdb, aka kx)
k($handle, '4 + 4'); # 8
- k($handle, q/"abc"/); # "abc"
+ k($handle, q/"abc"/); # ['a', 'b', 'c']
k($handle, q/`foo`bar!(1;2)/); # { foo => 1, bar => 2 }
View
2 t/k.t
@@ -13,7 +13,7 @@ test_qserver {
is $k->cmd('4 + 4'), 8, 'make an int';
- is $k->cmd(q/"abc"/), "abc", 'make string';
+ is_deeply $k->cmd(q/"abc"/), [qw/a b c/], 'make string';
my $timestamp = $k->cmd(q/2012.03.24D12:13:14.15161728/);
is "$timestamp", '385906394151617280', 'timestamp';
View
4 t/raw.t
@@ -116,7 +116,7 @@ sub null_vector_tests {
is_deeply k( $handle, '(),0b' ), [ undef ], 'null boolean vector';
is_deeply k( $handle, '(),0x00'), [ 0x00 ], 'null byte vector';
- is_deeply k( $handle, '()," "' ), ' ', 'null char vector'; # this ones weird
+ is_deeply k( $handle, '()," "' ), [ ' ' ], 'null char vector'; # this ones weird
is_deeply k( $handle, '(),0Nh' ), [ undef ], 'null short vector';
is_deeply k( $handle, '(),0N' ), [ undef ], 'null int vector';
is_deeply k( $handle, '(),0Nj' ), [ undef ], 'null long vector';
@@ -158,7 +158,7 @@ sub vector_tests {
my ($handle) = @_;
is_deeply k($handle, '(0b;1b;0b)'), [undef, 1, undef], 'parse bool vector';
- is_deeply k($handle, '"abc"'), "abc", 'parse char vector';
+ is_deeply k($handle, '"abc"'), [qw/a b c/], 'parse char vector';
is_deeply k($handle, '(7h;8h;9h)'), [7, 8, 9], 'parse short vector';
is_deeply k($handle, '(7i;8i;9i)'), [7, 8, 9], 'parse int vector';

0 comments on commit 990c238

Please sign in to comment.
Something went wrong with that request. Please try again.