From 1a9f3d763158015dc463550b36437e33e3e9e29d Mon Sep 17 00:00:00 2001 From: "R.E.J. Wellner" Date: Wed, 29 Apr 2020 01:42:38 +0200 Subject: [PATCH] Don't add cdata to seen! --- bitser.lua | 2 +- cases/cdata.lua | 5 +---- spec/bitser_spec.lua | 3 +++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bitser.lua b/bitser.lua index 6a1c5b5..e04c17e 100644 --- a/bitser.lua +++ b/bitser.lua @@ -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 diff --git a/cases/cdata.lua b/cases/cdata.lua index 39f96f1..3227bed 100644 --- a/cases/cdata.lua +++ b/cases/cdata.lua @@ -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 \ No newline at end of file +return {int_data, struct_data, {ffi.new("int",1),5,ffi.new("int",67)}}, 1000, 3 \ No newline at end of file diff --git a/spec/bitser_spec.lua b/spec/bitser_spec.lua index e07861a..2692df8 100644 --- a/spec/bitser_spec.lua +++ b/spec/bitser_spec.lua @@ -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)