lua-users home
lua-l archive

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


> Am 25.07.2016 um 21:03 schrieb Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
> 
>>> p = lua_newuserdate(L, sizeof int)
>>> *p = 42
>>> 
>>> /* Do a Lua API call that might error (longjmp) out */
>> 
>> This has the risk of the memory being invalidated by the
>> garbage collector.
> 
> No, if the userdata is properly anchored (e.g, in the stack). Just
> leave the the userdata in the stack (where lua_newuserdate put it)
> and everything should work fine.


Thanks to all that replied.  After I sprinkled some lua_checkstack()
calls, the crashes went away.  Time for a release...

Out of curiosity, why does lua_newuserdata() not call lua_checkstack()
internally?  When calling lua_newuserdata(), isn't it quite obvious
that you want the result on the stack?

- mb