[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question about lua_toclose()
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Thu, 3 Sep 2020 10:18:53 +0800
Roberto Ierusalimschy <roberto@inf.puc-rio.br> 于2020年9月2日周三 下午11:52写道:
>
> What do you mean by "safe"? What is exactly your concerns?
I mean, if the C stack unwind before calling __close when raising an
error, the pointer is unsafe. because it's on the C stack.
> (A detail in your code: you do not need the last three calls [pushnil,
> setvalue, mystruct_exit]. If you do not set nil, when you return
> Lua will call close_foo and then mystruct_exit for you.)
I think `close_foo` would be called after `foobar(lua_State *L)`
returns, and the `&foo` is invalid because of C stack unwinding.
(`struct mystruct foo` is on the C stack)
Maybe I can call `lua_settop(L, 0)` before returns to trigger __close,
but calling `mystruct_exit` manually would be better performance
(IMO).
--
http://blog.codingnow.com