Commit 8044e845 authored by François Perrad's avatar François Perrad
Browse files

fix behaviour with LUA_32BITS

parent 6cca8e5a
......@@ -2,6 +2,7 @@ Revision history for lua-MessagePack
0.3.6
fix pack float with Lua 5.3
fix behaviour with LUA_32BITS
0.3.5 Sat Oct 22 22:30:00 2016
fix float/integer detection
......
......@@ -866,7 +866,7 @@ unpackers['str32'] = function (c)
c.i = i
local n = ((b1 * 0x100 + b2) * 0x100 + b3) * 0x100 + b4
local e = i+n-1
if e > j then
if e > j or n < 0 then
c:underflow(e)
s, i, j = c.s, c.i, c.j
e = i+n-1
......@@ -1028,7 +1028,7 @@ unpackers['ext32'] = function (c)
i = i+1
c.i = i
local e = i+n-1
if e > j then
if e > j or n < 0 then
c:underflow(e)
s, i, j = c.s, c.i, c.j
e = i+n-1
......@@ -1107,14 +1107,14 @@ end
set_string'string_compat'
set_integer'unsigned'
if NUMBER_INTEGRAL then
packers['double'] = packers['integer']
packers['float'] = packers['integer']
set_number'integer'
elseif SIZEOF_NUMBER == 4 then
maxinteger = 16777215
mininteger = -maxinteger
packers['double'] = packers['float']
m.small_lua = true
unpackers['double'] = nil
unpackers['uint64'] = nil
unpackers['int64'] = nil
set_number'float'
else
maxinteger = 9007199254740991
......
......@@ -649,7 +649,7 @@ unpackers['str32'] = function (c)
i = i+4
c.i = i
local e = i+n-1
if e > j then
if e > j or n < 0 then
c:underflow(e)
s, i, j = c.s, c.i, c.j
e = i+n-1
......@@ -809,7 +809,7 @@ unpackers['ext32'] = function (c)
i = i+1
c.i = i
local e = i+n-1
if e > j then
if e > j or n < 0 then
c:underflow(e)
s, i, j = c.s, c.i, c.j
e = i+n-1
......@@ -891,6 +891,9 @@ if math_type(0.0) == math_type(0) then
set_number'integer'
elseif #pack('n', 0.0) == 4 then
m.small_lua = true
unpackers['double'] = nil
unpackers['uint64'] = nil
unpackers['int64'] = nil
set_number'float'
else
m.full64bits = true
......
......@@ -14,32 +14,23 @@ local data = {
0, "0 uint8",
0, "0 uint16",
0, "0 uint32",
0, "0 uint64",
0, "0 int8",
0, "0 int16",
0, "0 int32",
0, "0 int64",
-1, "-1 Negative FixNum",
-1, "-1 int8",
-1, "-1 int16",
-1, "-1 int32",
-1, "-1 int64",
127, "127 Positive FixNum",
127, "127 uint8",
255, "255 uint16",
65535, "65535 uint32",
4294967295, "4294967295 uint64",
-32, "-32 Negative FixNum",
-32, "-32 int8",
-128, "-128 int16",
-32768, "-32768 int32",
-2147483648, "-2147483648 int64",
0.0, "0.0 float",
0.0, "0.0 double",
-0.0, "-0.0 float",
-0.0, "-0.0 double",
1.0, "1.0 double",
-1.0, "-1.0 double",
"a", "\"a\" FixStr",
"a", "\"a\" str 8",
"a", "\"a\" str 16",
......@@ -78,8 +69,23 @@ local data = {
nil, "ext 16",
nil, "ext 32",
}
if not mp.small_lua then
for i, v in ipairs({
0, "0 uint64",
0, "0 int64",
-1, "-1 int64",
4294967295, "4294967295 uint64",
-2147483648, "-2147483648 int64",
0.0, "0.0 double",
-0.0, "-0.0 double",
1.0, "1.0 double",
-1.0, "-1.0 double",
}) do
data[60*2+i] = v
end
end
plan(10 * 69)
plan(10 * (mp.small_lua and 60 or 69))
-- see http://github.com/msgpack/msgpack/blob/master/test/cases_gen.rb
local source = [===[
......@@ -90,32 +96,23 @@ c0 # nil
cc 00 # 0 uint8
cd 00 00 # 0 uint16
ce 00 00 00 00 # 0 uint32
cf 00 00 00 00 00 00 00 00 # 0 uint64
d0 00 # 0 int8
d1 00 00 # 0 int16
d2 00 00 00 00 # 0 int32
d3 00 00 00 00 00 00 00 00 # 0 int64
ff # -1 Negative FixNum
d0 ff # -1 int8
d1 ff ff # -1 int16
d2 ff ff ff ff # -1 int32
d3 ff ff ff ff ff ff ff ff # -1 int64
7f # 127 Positive FixNum
cc 7f # 127 uint8
cd 00 ff # 255 uint16
ce 00 00 ff ff # 65535 uint32
cf 00 00 00 00 ff ff ff ff # 4294967295 uint64
e0 # -32 Negative FixNum
d0 e0 # -32 int8
d1 ff 80 # -128 int16
d2 ff ff 80 00 # -32768 int32
d3 ff ff ff ff 80 00 00 00 # -2147483648 int64
ca 00 00 00 00 # 0.0 float
cb 00 00 00 00 00 00 00 00 # 0.0 double
ca 80 00 00 00 # -0.0 float
cb 80 00 00 00 00 00 00 00 # -0.0 double
cb 3f f0 00 00 00 00 00 00 # 1.0 double
cb bf f0 00 00 00 00 00 00 # -1.0 double
a1 61 # "a" FixStr
d9 01 61 # "a" str 8
da 00 01 61 # "a" str 16
......@@ -154,6 +151,19 @@ c7 01 08 61 # ext 8
c8 00 01 16 61 # ext 16
c9 00 00 00 01 32 61 # ext 32
]===]
if not mp.small_lua then
source = source .. [===[
cf 00 00 00 00 00 00 00 00 # 0 uint64
d3 00 00 00 00 00 00 00 00 # 0 int64
d3 ff ff ff ff ff ff ff ff # -1 int64
cf 00 00 00 00 ff ff ff ff # 4294967295 uint64
d3 ff ff ff ff 80 00 00 00 # -2147483648 int64
cb 00 00 00 00 00 00 00 00 # 0.0 double
cb 80 00 00 00 00 00 00 00 # -0.0 double
cb 3f f0 00 00 00 00 00 00 # 1.0 double
cb bf f0 00 00 00 00 00 00 # -1.0 double
]===]
end
source = source:gsub('#[^\n]+', '')
local t = {}
......@@ -236,8 +246,8 @@ for _, val in mp.unpacker(mpac) do
end
mp.set_string'string_compat'
diag("set_integer'unsigned'")
mp.set_integer'unsigned'
diag("set_integer'signed'")
mp.set_integer'signed'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
......@@ -247,10 +257,10 @@ for _, val in mp.unpacker(mpac) do
end
i = i + 2
end
mp.set_integer'signed'
mp.set_integer'unsigned'
diag("set_number'float'")
mp.set_number'float'
diag("set_array'with_hole'")
mp.set_array'with_hole'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
......@@ -261,8 +271,8 @@ for _, val in mp.unpacker(mpac) do
i = i + 2
end
diag("set_number'integer'")
mp.set_number'integer'
diag("set_array'always_as_map'")
mp.set_array'always_as_map'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
......@@ -272,10 +282,10 @@ for _, val in mp.unpacker(mpac) do
end
i = i + 2
end
mp.set_number'double'
mp.set_array'without_hole'
diag("set_array'with_hole'")
mp.set_array'with_hole'
diag("set_number'float'")
mp.set_number'float'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
......@@ -286,8 +296,8 @@ for _, val in mp.unpacker(mpac) do
i = i + 2
end
diag("set_array'always_as_map'")
mp.set_array'always_as_map'
diag("set_number'integer'")
mp.set_number'integer'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
......@@ -297,4 +307,3 @@ for _, val in mp.unpacker(mpac) do
end
i = i + 2
end
mp.set_array'without_hole'
......@@ -80,9 +80,13 @@ is( mp.unpack(mp.pack(0xF0000000)), 0xF0000000, "packint 0xF0000000")
local buffer = {}
mp.packers.float(buffer, 0)
is( mp.unpack(table.concat(buffer)), 0)
buffer = {}
mp.packers.double(buffer, 0)
is( mp.unpack(table.concat(buffer)), 0)
if mp.small_lua then
skip("Small Lua (32 bits)", 1)
else
buffer = {}
mp.packers.double(buffer, 0)
is( mp.unpack(table.concat(buffer)), 0)
end
local mpac = string.char(0x82, 0xC0, 0x01, 0xA2, 0x69, 0x64, 0x02)
t = mp.unpack(mpac)
......
......@@ -6,20 +6,21 @@ plan(41)
local mp = require 'MessagePack'
mp.set_number'float'
local nan = mp.unpack(mp.pack(0/0))
type_ok( nan, 'number', "nan" )
ok( nan ~= nan )
is( mp.unpack(mp.pack(3.140625)), 3.140625, "3.140625" )
mp.set_number'double'
if mp.long_double then
if mp.small_lua then
skip("Small Lua (32 bits)", 2)
elseif mp.long_double then
skip("long double", 2)
else
is( mp.unpack(mp.pack(1.0e+300)), 1.0e+300, "1.0e+300" )
is( mp.unpack(mp.pack(math.pi)), math.pi, "pi" )
end
mp.set_number'float'
local nan = mp.unpack(mp.pack(0/0))
type_ok( nan, 'number', "nan" )
ok( nan ~= nan )
is( mp.unpack(mp.pack(3.140625)), 3.140625, "3.140625" )
mp.set_integer'signed'
is( mp.unpack(mp.pack(2^5)), 2^5, "2^5" )
is( mp.unpack(mp.pack(-2^5)), -2^5, "-2^5" )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment