lua-users home
lua-l archive

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


Hi, all.

I think this is the first time a bug in Lua has ever created problems for 
me. So that's pretty good, given the amount of time I've spent using it.

However.

The "local function" statement does not correctly update the maxstacksize 
field in the Proto. Consequently, if the last local(s) in a function are 
declared with "local function", the Proto will not indicate the actual 
number of stack slots needed. What happens after that is anyone's guess, 
but I think the result which I just lost a day fighting with is that a 
garbage collection might come along at an inopportune moment and release 
the storage associated with the Proto. That's just a guess, though... the 
actual symptoms were pretty far removed from the problem.

The patch is quite simple (not thoroughly tested, but it looks right and 
my program now works):

Replace line 1145 of lparser.c, which currently reads:
  init_exp(&v, VLOCAL, ls->fs->freereg++);

with:

  init_exp(&v, VLOCAL, ls->fs->freereg);
  luaK_reserveregs(ls->fs, 1);


Rici.