Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix passing empty strings and bufs to Perl 5.
A 0 len parameter passed to newSVpv makes perl5 use strlen() to
determine len. We don't need this magic anymore, since we determine the
length of the buffer in Perl 6 code already for binary safety.

Works around an apparent bug in Rakudo. The pointer to the supposedly
empty string points to random garbage now.
  • Loading branch information
niner committed May 4, 2015
1 parent a52fd1b commit 8b3af84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 2 additions & 5 deletions p5helper.c
Expand Up @@ -144,14 +144,11 @@ SV *p5_float_to_sv(PerlInterpreter *my_perl, double value) {
}

SV *p5_str_to_sv(PerlInterpreter *my_perl, STRLEN len, char* value) {
SV * const sv = newSVpv(value, len);
SvUTF8_on(sv);
return sv;
return newSVpvn_flags(value, len, SVf_UTF8);
}

SV *p5_buf_to_sv(PerlInterpreter *my_perl, STRLEN len, char* value) {
SV * const sv = newSVpv(value, len);
return sv;
return newSVpvn_flags(value, len, 0);
}

I32 p5_av_top_index(PerlInterpreter *my_perl, AV *av) {
Expand Down
14 changes: 12 additions & 2 deletions t/p6_to_p5.t
Expand Up @@ -4,7 +4,7 @@ use v6;
use Test;
use Inline::Perl5;

plan 16;
plan 17;

my $p5 = Inline::Perl5.new();
$p5.run(q:heredoc/PERL5/);
Expand All @@ -16,7 +16,17 @@ $p5.run(q:heredoc/PERL5/);
class Foo {
}

for ('abcö', Buf.new('äbc'.encode('latin-1')), 24, 2.4.Num, [1, 2], { a => 1, b => 2}, Any, Foo.new) -> $obj {
for (
'',
'abcö',
Buf.new('äbc'.encode('latin-1')),
24,
2.4.Num,
[1, 2],
{ a => 1, b => 2},
Any,
Foo.new,
) -> $obj {
is_deeply $p5.call('identity', $obj), $obj, "Can round-trip " ~ $obj.^name;
}

Expand Down

0 comments on commit 8b3af84

Please sign in to comment.