Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set UTF-8 flag on strings passed to Perl 5.
  • Loading branch information
niner committed Sep 17, 2014
1 parent 8462b03 commit 0513cdd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion p5helper.c
Expand Up @@ -103,7 +103,9 @@ SV *p5_int_to_sv(PerlInterpreter *my_perl, int value) {
}

SV *p5_str_to_sv(PerlInterpreter *my_perl, char* value) {
return newSVpv(value, 0);
SV * const sv = newSVpv(value, 0);
SvUTF8_on(sv);
return sv;
}

int p5_av_top_index(PerlInterpreter *my_perl, AV *av) {
Expand Down
10 changes: 9 additions & 1 deletion t/eval.t
Expand Up @@ -3,7 +3,7 @@
use v6;
use Inline::Perl5;

say '1..2';
say '1..3';

my $p5 = Inline::Perl5.new();

Expand All @@ -18,6 +18,14 @@ $p5.run('
say "ok 2 - loading XS modules";
');

$p5.run('
use 5.10.0;
use utf8;
say utf8::is_utf8("Pörl 5")
? "ok 3 - Inlined Perl 5 source code is UTF-8 encoded"
: "not ok 3 - Inlined Perl 5 source code is UTF-8 encoded";
');

$p5.DESTROY;

# vim: ft=perl6
5 changes: 5 additions & 0 deletions t/p5_to_p6.t
Expand Up @@ -15,6 +15,11 @@ is_deeply $p5.run('{a => 1, b => {c => 3}}'), {a => 1, b => {c => 3}};
is_deeply $p5.run('[1, {b => {c => 3}}]'), [1, {b => {c => 3}}];
ok $p5.run('undef') === Any, 'p5 undef maps to p6 Any';

is $p5.run('
use utf8;
"Pörl 5"
'), 'Pörl 5';

$p5.DESTROY;

done;
Expand Down
15 changes: 13 additions & 2 deletions t/p6_to_p5.t
Expand Up @@ -4,18 +4,29 @@ use v6;
use Test;
use Inline::Perl5;

plan 6;
plan 7;

my $p5 = Inline::Perl5.new();
$p5.run(q[ sub identity { return $_[1] }; ]);

class Foo {
}

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

$p5.run(q/
use utf8;
sub check_utf8 {
my ($str) = @_;
return $str eq 'Töst';
};
/);

ok($p5.call('check_utf8', 'Töst'), 'UTF-8 string recognized in Perl 5');

$p5.DESTROY;

# vim: ft=perl6

0 comments on commit 0513cdd

Please sign in to comment.