在什么情况下 lua_close 会引发分段错误错误?
我说的是 Lua-C API。即使状态有效,调用 lua_close(lua_State *)
也会导致分段错误。我如何知道状态是否有效?因为到目前为止我已经正确使用了它。
我会发布源代码,但它太长了,我不确定它是否会有帮助。它只是向我抛出分段错误错误,我不知道为什么。调用之前Lua堆栈是空的。有人可以帮助我吗?
I'm talking about the Lua-C API. A call to lua_close(lua_State *)
results in a segmentation fault, even if the state is valid. How do I know the state is valid? Because I've used it correctly up to that point.
I'd post the source but it's too long and I'm not sure it would be helpful. It simply throws a segmentation fault error at me and I have no clue why. The Lua stack is empty before the call. Can somebody help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Lua C API 永远不应该导致分段错误。如果在调用 lua_close 时发生段错误,最可能的原因是某些具有自定义 __gc 元方法的用户数据失败。来自
lua_close
的文档:确定这些段错误原因的最佳方法是运行 gdb 并在发生时获取回溯。如果使用调试符号编译库,则应该准确到达导致错误的位置。
The Lua C API should never result in a segmentation fault. If the segfault happens when calling
lua_close
, the most probable reason is that some userdata with custom__gc
metamethods are failing. From the documentation oflua_close
:The best way to determine what is the reason for these segfaults is run
gdb
and get a backtrace when it happens. If you compile your library with debug symbols, you should get exactly to the place that causes errors.你说调用之前Lua栈是空的。但是要调用的函数是在栈上吗?即使您调用 lua_call(L,0,0) ,也应该如此。还可以尝试使用 API 断言重建 Lua。它可能会给您更好的错误消息。
You say that the Lua stack is empty before the call. But is the function to be called on the stack? It should be, even if you call
lua_call(L,0,0)
. Try also rebuilding Lua with API assertions on. It may give you a better error message.