diff options
| author | gfx <gfuji@cpan.org> | 2010-09-19 15:16:08 +0900 |
|---|---|---|
| committer | gfx <gfuji@cpan.org> | 2010-09-19 15:16:08 +0900 |
| commit | d6a825981d14079bf4fa74a0605ecec8e873f94b (patch) | |
| tree | 0b17041345304ec5faa5f0f31047fe2930356a20 /perl/lib/Data/MessagePack | |
| parent | a1c01c6722a50db0aedcc73f2bb6cdd6f16c8f3a (diff) | |
| download | msgpack-python-d6a825981d14079bf4fa74a0605ecec8e873f94b.tar.gz | |
perl: fix unpacking int64_t in PP (based on makamaka's patch)
Diffstat (limited to 'perl/lib/Data/MessagePack')
| -rw-r--r-- | perl/lib/Data/MessagePack/PP.pm | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/perl/lib/Data/MessagePack/PP.pm b/perl/lib/Data/MessagePack/PP.pm index 8a904a9..44940de 100644 --- a/perl/lib/Data/MessagePack/PP.pm +++ b/perl/lib/Data/MessagePack/PP.pm @@ -22,10 +22,19 @@ BEGIN { if(!eval { pack 'Q', 1 }) { # don't have quad types $unpack_int64_slow = sub { require Math::BigInt; - my $high = Math::BigInt->new( unpack_int32( $_[0], $_[1]) ); - my $low = Math::BigInt->new( unpack_uint32( $_[0], $_[1] + 4) ); + my $high = unpack_uint32( $_[0], $_[1] ); + my $low = unpack_uint32( $_[0], $_[1] + 4); - return +($high << 32 | $low)->bstr; + if($high < 0xF0000000) { # positive + $high = Math::BigInt->new( $high ); + $low = Math::BigInt->new( $low ); + return +($high << 32 | $low)->bstr; + } + else { # negative + $high = Math::BigInt->new( ~$high ); + $low = Math::BigInt->new( ~$low ); + return +( -($high << 32 | $low + 1) )->bstr; + } }; $unpack_uint64_slow = sub { require Math::BigInt; |
