mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-02 08:38:20 +00:00
Lua library: fix vtable reuse. (#5214)
Fixed a bug that prevented vtable reuse during buffer construction in the lua library. Also fixed a bug in vtable equality check that was revealed after the first fix.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
f89badd30f
commit
1d60824d56
@@ -34,7 +34,7 @@ local function vtableEqual(a, objectStart, b)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i, elem in ipairs(a) do
|
for i, elem in ipairs(a) do
|
||||||
local x = VOffsetT:Unpack(b, i * VOffsetT.bytewidth)
|
local x = string.unpack(VOffsetT.packFmt, b, 1 + (i - 1) * VOffsetT.bytewidth)
|
||||||
if x ~= 0 or elem ~= 0 then
|
if x ~= 0 or elem ~= 0 then
|
||||||
local y = objectStart - elem
|
local y = objectStart - elem
|
||||||
if x ~= y then
|
if x ~= y then
|
||||||
@@ -96,11 +96,13 @@ function mt:WriteVtable()
|
|||||||
i = i - 1
|
i = i - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
i = #self.vtables
|
||||||
while i >= 1 do
|
while i >= 1 do
|
||||||
|
|
||||||
local vt2Offset = self.vtables[i]
|
local vt2Offset = self.vtables[i]
|
||||||
local vt2Start = #self.bytes - vt2Offset
|
local vt2Start = #self.bytes - vt2Offset
|
||||||
local vt2len = VOffsetT:Unpack(self.bytes, vt2Start)
|
local vt2lenstr = self.bytes:Slice(vt2Start, vt2Start+1)
|
||||||
|
local vt2Len = string.unpack(VOffsetT.packFmt, vt2lenstr, 1)
|
||||||
|
|
||||||
local metadata = VtableMetadataFields * VOffsetT.bytewidth
|
local metadata = VtableMetadataFields * VOffsetT.bytewidth
|
||||||
local vt2End = vt2Start + vt2Len
|
local vt2End = vt2Start + vt2Len
|
||||||
@@ -364,4 +366,4 @@ function mt:Place(x, flags)
|
|||||||
self.bytes:Set(d, h)
|
self.bytes:Set(d, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|||||||
Reference in New Issue
Block a user