perl: Fix utf8 mode not to be reseted by $unpacker->reset method

This commit is contained in:
Fuji, Goro 2010-10-06 17:52:32 +09:00
parent 4321b80999
commit 77a7d3d26a
3 changed files with 26 additions and 13 deletions

@ -1,3 +1,8 @@
0.30
- fix utf8 mode not to be reseted by $unpacker->reset method
0.29
- add $unpacker->utf8 mode, decoding strings as UTF-8.

@ -5,23 +5,29 @@ use Data::MessagePack;
use utf8;
my $data = [42, undef, 'foo', "\x{99f1}\x{99dd}"];
my $packed = Data::MessagePack->pack($data);
my $packed = Data::MessagePack->pack($data) x 2;
my $u = Data::MessagePack::Unpacker->new()->utf8();
ok $u->get_utf8();
$u->execute($packed);
my $d = $u->data();
$u->reset();
is_deeply $d, $data, 'decoded';
my $p = 0;
for(1 .. 2) {
ok $u->get_utf8();
$p = $u->execute($packed, $p);
my $d = $u->data();
$u->reset();
is_deeply $d, $data, 'decoded';
}
is $u->utf8(0), $u, 'utf8(0)';
ok !$u->get_utf8();
$u->execute($packed);
$d = $u->data();
$u->reset();
my $s = $data->[3];
utf8::encode($s);
is_deeply $d->[3], $s, 'not decoded';
$p = 0;
for(1 .. 2) {
ok !$u->get_utf8();
$p = $u->execute($packed, $p);
my $d = $u->data();
$u->reset();
my $s = $data->[3];
utf8::encode($s);
is_deeply $d->[3], $s, 'not decoded';
}
done_testing;

@ -443,10 +443,12 @@ XS(xs_unpacker_reset) {
}
UNPACKER(ST(0), mp);
bool const utf8 = mp->user.utf8; // save
SV* const data = template_data(mp);
SvREFCNT_dec(data);
_reset(ST(0));
mp->user.utf8 = utf8;
XSRETURN(0);
}