lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 10/6/23 16:24, kovserg33@gmail.com wrote:

It is because you allocating by 49 elements each time.

There is optimizations in https://github.com/lua/lua/blob/master/lparser.c#L872 that cause problem

It won't flush until LFIELDS_PER_FLUSH (defined as 50 https://github.com/lua/lua/blob/master/lopcodes.h#L403 )

So 5 levels by 50 registers gives 250 registers So 6th level will for sure exceed amount of free registers

You discover aт antique bug.

Exact:

> lua5.4 -e "io.stdout:setvbuf('no')" "nestedTableParserIssue.oOo"
lua5.4: nestedTableParserIssue.oOo:1: function or _expression_ needs too many registers near '6'
> exit status: 256

Code:
```
t = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, {6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, {}}}}}}}
print(t[1])
```


On 06.10.2023 14:29, Andrey Dobrovolsky wrote:
Hi,
The nesting depth of the table to be parsed successfully depends on how the nested levels are filled. Here is the code to produce the worst case for the parser:

local depth = 5
local list_size= 49
io.write("return { ")
for i = 1, depth do
  for j = 1, list_size do
    io.write(i, ", ")
  end
  io.write("{")
end
for i = depth, 1, -1  do
  io.write("}")
end
io.write("}")

For depth = 5 the output is valid code, while for the depth = 6 parser fails. If You will play with list_size values You may obtain much deeper nested tables to be parsed successfully. But the guaranteed depth to be parsed is 5. My patch increases it up to 29.

Родион Горковенко wrote:
> Perhaps, provide a small straightforward example please?