lua-users home
lua-l archive

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


Thank you!
The provided information helped me a lot.

Although I believe that this is not the case, I will also modify my memory allocator, to stop allocations when a specific limit is reached (e.g. 90% of total memory) to ensure stable operation of the rest of the system.

Στις Τετ, 10 Απρ 2019 στις 5:43 μ.μ., ο/η Roberto Ierusalimschy <roberto@inf.puc-rio.br> έγραψε:
> I would like to ask, at which cases can a Lua state be invalid? (And thus
> no other operations are allowed).
>
>    - Is it always safe to call lua_close()?

Yes.


>    - If a lua_pcall() fails, is it allowed to use again lua_pcall() calling
>    another function?

Yes. (By "fails" you mean returns an error code, right?)


>    - In case lua_pcall() fails with "not enough memory", can any
>    assumptions be made about the memory state? Can lua_close() be called
>    then, or generally any other Lua API function?

Yes. Bar unkown bugs, "not enough memory" should be like any other
error, and should leave Lua in a normal state.  Of course, due to its
nature, subsequent operations may fail too, while there is not enough
memory. However, critical paths like 'pcall' and 'lua_close' do not
allocate any memory and should work correctly even without any memory
left.

The standard tests include extensive tests around "not enough memory"
errors, using a special allocator that forces these errors. However,
in our experience, this is far from the norm in software practice.
Therefore, many other parts of a system (e.g., external libraries or
even libc) may not be as well behaved as Lua regarding this scenario.
(Of course, there may be bugs in Lua, too.)

-- Roberto