mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 16:01:09 +00:00
Fixed LuaJIT when not compiled with COMPAT mode (#6605)
LuaJIT as installed by apt doesn't include the COMPAT mode for using Lua5.2 features. So this change just makes the flatbuffer code use a common implementation.
This commit is contained in:
@@ -70,7 +70,7 @@ function mt:Clear()
|
|||||||
self.minalign = 1
|
self.minalign = 1
|
||||||
self.currentVTable = nil
|
self.currentVTable = nil
|
||||||
self.objectEnd = nil
|
self.objectEnd = nil
|
||||||
self.head = #self.bytes -- place the head at the end of the binary array
|
self.head = self.bytes.size -- place the head at the end of the binary array
|
||||||
|
|
||||||
-- clear vtables instead of making a new table
|
-- clear vtables instead of making a new table
|
||||||
local vtable = self.vtables
|
local vtable = self.vtables
|
||||||
@@ -118,7 +118,7 @@ function mt:WriteVtable()
|
|||||||
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.size - vt2Offset
|
||||||
local vt2lenstr = self.bytes:Slice(vt2Start, vt2Start+1)
|
local vt2lenstr = self.bytes:Slice(vt2Start, vt2Start+1)
|
||||||
local vt2Len = string_unpack(VOffsetT.packFmt, vt2lenstr, 1)
|
local vt2Len = string_unpack(VOffsetT.packFmt, vt2lenstr, 1)
|
||||||
|
|
||||||
@@ -154,12 +154,12 @@ function mt:WriteVtable()
|
|||||||
vBytes = vBytes * 2
|
vBytes = vBytes * 2
|
||||||
self:PrependVOffsetT(vBytes)
|
self:PrependVOffsetT(vBytes)
|
||||||
|
|
||||||
local objectStart = #self.bytes - objectOffset
|
local objectStart = self.bytes.size - objectOffset
|
||||||
self.bytes:Set(SOffsetT:Pack(self:Offset() - objectOffset),objectStart)
|
self.bytes:Set(SOffsetT:Pack(self:Offset() - objectOffset),objectStart)
|
||||||
|
|
||||||
table.insert(self.vtables, self:Offset())
|
table.insert(self.vtables, self:Offset())
|
||||||
else
|
else
|
||||||
local objectStart = #self.bytes - objectOffset
|
local objectStart = self.bytes.size - objectOffset
|
||||||
self.head = objectStart
|
self.head = objectStart
|
||||||
self.bytes:Set(SOffsetT:Pack(exisitingVTable - objectOffset),self.head)
|
self.bytes:Set(SOffsetT:Pack(exisitingVTable - objectOffset),self.head)
|
||||||
end
|
end
|
||||||
@@ -175,7 +175,7 @@ function mt:EndObject()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function growByteBuffer(self, desiredSize)
|
local function growByteBuffer(self, desiredSize)
|
||||||
local s = #self.bytes
|
local s = self.bytes.size
|
||||||
assert(s < MAX_BUFFER_SIZE, "Flat Buffers cannot grow buffer beyond 2 gigabytes")
|
assert(s < MAX_BUFFER_SIZE, "Flat Buffers cannot grow buffer beyond 2 gigabytes")
|
||||||
local newsize = s
|
local newsize = s
|
||||||
repeat
|
repeat
|
||||||
@@ -191,7 +191,7 @@ function mt:Head()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mt:Offset()
|
function mt:Offset()
|
||||||
return #self.bytes - self.head
|
return self.bytes.size - self.head
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt:Pad(n)
|
function mt:Pad(n)
|
||||||
@@ -210,15 +210,15 @@ function mt:Prep(size, additionalBytes)
|
|||||||
|
|
||||||
local h = self.head
|
local h = self.head
|
||||||
|
|
||||||
local k = #self.bytes - h + additionalBytes
|
local k = self.bytes.size - h + additionalBytes
|
||||||
local alignsize = getAlignSize(k, size)
|
local alignsize = getAlignSize(k, size)
|
||||||
|
|
||||||
local desiredSize = alignsize + size + additionalBytes
|
local desiredSize = alignsize + size + additionalBytes
|
||||||
|
|
||||||
while self.head < desiredSize do
|
while self.head < desiredSize do
|
||||||
local oldBufSize = #self.bytes
|
local oldBufSize = self.bytes.size
|
||||||
growByteBuffer(self, desiredSize)
|
growByteBuffer(self, desiredSize)
|
||||||
local updatedHead = self.head + #self.bytes - oldBufSize
|
local updatedHead = self.head + self.bytes.size - oldBufSize
|
||||||
self.head = updatedHead
|
self.head = updatedHead
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ local function finish(self, rootTable, sizePrefix)
|
|||||||
self:Prep(self.minalign, sizePrefix and 8 or 4)
|
self:Prep(self.minalign, sizePrefix and 8 or 4)
|
||||||
self:PrependUOffsetTRelative(rootTable)
|
self:PrependUOffsetTRelative(rootTable)
|
||||||
if sizePrefix then
|
if sizePrefix then
|
||||||
local size = #self.bytes - self.head
|
local size = self.bytes.size - self.head
|
||||||
Int32:EnforceNumber(size)
|
Int32:EnforceNumber(size)
|
||||||
self:PrependInt32(size)
|
self:PrependInt32(size)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ local Uint8Bound = 256 -- bound is the max uintN + 1
|
|||||||
local Uint16Bound = 65536
|
local Uint16Bound = 65536
|
||||||
local Uint32Bound = 4294967296
|
local Uint32Bound = 4294967296
|
||||||
|
|
||||||
|
if not table.unpack then
|
||||||
|
table.unpack = unpack
|
||||||
|
end
|
||||||
|
|
||||||
|
if not table.pack then
|
||||||
|
table.pack = pack
|
||||||
|
end
|
||||||
|
|
||||||
m.GetAlignSize = function(k, size)
|
m.GetAlignSize = function(k, size)
|
||||||
return band((bnot(k) + 1), (size - 1))
|
return band((bnot(k) + 1), (size - 1))
|
||||||
|
|||||||
@@ -19,7 +19,13 @@ test_dir="$(pwd)"
|
|||||||
|
|
||||||
${test_dir}/../flatc --lua -I include_test monster_test.fbs
|
${test_dir}/../flatc --lua -I include_test monster_test.fbs
|
||||||
|
|
||||||
echo "Run with LuaJIT:"
|
declare -a versions=(luajit lua5.3)
|
||||||
luajit luatest.lua
|
|
||||||
echo "Run with Lua 5.3:"
|
for i in "${versions[@]}"
|
||||||
lua5.3 luatest.lua
|
do
|
||||||
|
if command -v $i &> /dev/null
|
||||||
|
then
|
||||||
|
echo "[$i]"
|
||||||
|
$i luatest.lua
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package.path = string.format("../lua/?.lua;./?.lua;%s",package.path)
|
package.path = string.format("../lua/?.lua;./?.lua;%s",package.path)
|
||||||
|
local compat = require("flatbuffers.compat")
|
||||||
|
|
||||||
local performBenchmarkTests = false
|
local performBenchmarkTests = false
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ local function checkReadBuffer(buf, offset, sizePrefix)
|
|||||||
|
|
||||||
if sizePrefix then
|
if sizePrefix then
|
||||||
local size = flatbuffers.N.Int32:Unpack(buf, offset)
|
local size = flatbuffers.N.Int32:Unpack(buf, offset)
|
||||||
assert(size == #buf - offset - 4)
|
assert(size == buf.size - offset - 4)
|
||||||
offset = offset + flatbuffers.N.Int32.bytewidth
|
offset = offset + flatbuffers.N.Int32.bytewidth
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user