lua-users home
lua-l archive

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

Hmm, no replies so far :/  .... is it because of the old Lua version that I'm using?

Maybe I should phrase this as a simpler question: Let's forget about the old
bytecode compatibility issues. I'll find a way to work this out myself. I'd just
like to know: Is it safe to set MAXSTACK to 1000 on Lua 5.0.2 to increase
stack space for functions? Or will this have unwanted side effects?



On 28.12.2011 at 15:26 Andreas Falkenhahn wrote:

>could somebody tell me a little bit more about the implications of
>increasing MAXSTACK?
>There's no word of warning in llimits.h so it looks as if I could just
>increase this to 1000
>or so if a script is running out of stack space. For example, I have some
>scripts that need
>to pass tables containing lots of values to a function and then Lua exits
>with a stack overflow
>Thus, I tried to increase MAXSTACK but I'm not sure whether that was a
>good idea. First,
>it seems that the maximum number of function arguments is stored in 8bits
>so it's not
>possible to pass more than 255 arguments to a function. I can live with
>that because I'm
>passing all my arguments inside a table anyway. However, I think that this
>limit should be
>mentioned in llimits.h.
>Also, there seem to be other implications: With MAXSTACK set to 1000, lua
>is no
>longer able to load bytecode that has been compiled using the default
>MAXSTACK setting
>of 250. Specifically, the checkRK() function in ldebug.c fails then
>because in bytecode
>compiled with the old MAXSTACK of 250 "r" could e.g. be set to 253 (i.e.
>but now MAXSTACK is 1000 so that condition fails and leads to a corrupt
>bytecode error.
>So there seems to be no easy way to change the MAXSTACK value without
>bytecode compatibility of scripts compiled with a different MAXSTACK
>setting. Or could
>this be worked around somehow without having to hack into the Lua core?
>If there is no easy way to increase the stack without having to deal with
>all kinds of
>issues, I'd suggest that a word of warning is put as a comment before the
>definition in llimits.h. Because as it currently is, it looks as if one
>could just increase
>this as desired which apparently is not the case.
>So my question is: What could I do to increase stack space for my
>functions without
>breaking compatibility with old bytecode? I do not need to pass more than
>255 arguments
>to my functions but I need to pass tables with tons of items and they
>require more stack
>space than 250 items. The only thing that comes to my mind is to hack a
>flag into new
>bytecode that signals that the new stack limit is in effect in this
>bytecode. Whenever
>this flag is not there, I know that it is old bytecode and have to adapt
>all the opcode
>arguments accordingly so that the args are relative to the new MAXSTACK
>then. So
>a value of 253 would be adapted into 1003 etc.
>But I'd like to hear other suggestions. Maybe it can be achieved in a
>simpler way?
>I'm still using Lua 5.0.2 for what it's worth.