Don't add cdata to seen!

This commit is contained in:
R.E.J. Wellner 2020-04-29 01:42:38 +02:00
parent cd6ac6f7cb
commit 1a9f3d7631
3 changed files with 5 additions and 5 deletions

View File

@ -242,7 +242,7 @@ serialize_value = function(value, seen)
return
end
local t = type(value)
if t ~= 'number' and t ~= 'boolean' and t ~= 'nil' then
if t ~= 'number' and t ~= 'boolean' and t ~= 'nil' and t ~= 'cdata' then
seen[value] = seen[SEEN_LEN]
seen[SEEN_LEN] = seen[SEEN_LEN] + 1
end

View File

@ -12,12 +12,9 @@ struct nested_struct {
};
]]
local bitser = require 'bitser'
local int_data = ffi.new('int', 5)
local struct_data = ffi.new('struct nested_struct', {10, {20, 30}})
local value = ffi.new('struct { int a; double b; }', 42, 1.25)
return {int_data, struct_data, value}, 1000, 3
return {int_data, struct_data, {ffi.new("int",1),5,ffi.new("int",67)}}, 1000, 3

View File

@ -332,4 +332,7 @@ describe("bitser", function()
local v = bitser.dumps(ffi.new('struct { int a; }'))
assert.has_error(function() bitser.loads(v) end)
end)
it("can read and write simple multiple cdata of the same ctype without getting confused", function()
test_serdeser({ffi.new('double', 42.5), ffi.new('double', 12), ffi.new('double', 0.01)})
end)
end)