Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure package.preload exists #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Make sure package.preload exists #8

wants to merge 1 commit into from

Conversation

Kazade
Copy link

@Kazade Kazade commented May 3, 2013

Hi,

package.preload doesn't always exist when luabind::open is called which causes set_package_preload to fail. This patch initializes the package and preload tables in open() to prevent a segfault.

@Oberon00
Copy link

It doesn't work that way. First, you are discarding the previous package.preload table, which could already contain values, and second, the Lua Reference Manual states:

This variable is only a reference to the real table; assignments to this variable do not change the table used by require.

@rpavlik
Copy link
Owner

rpavlik commented Aug 14, 2013

Should some error checking be done in set_package_preload instead? (How are you missing the package table? and in that case, why are you trying to use the package system through require?)

rpavlik pushed a commit that referenced this pull request Aug 16, 2013
Also automatically fall back to 5.1 if 5.2 could not be found and no version
was explicitly set in the LUABIND_LUA_VERSION CMake variable.
rpavlik pushed a commit that referenced this pull request Aug 19, 2013
Also automatically fall back to 5.1 if 5.2 could not be found and no version
was explicitly set in the LUABIND_LUA_VERSION CMake variable.
@Kazade
Copy link
Author

Kazade commented Sep 15, 2013

Hi, sorry for the delay I've been trying to find time to do some testing to see if this bug still exists, and I've just checked and it does.

To elaborate, I'm using a GIT submodule to include luabind in my application, with my fork (including the above patch) everything works fine, but with your repository I get the following segfault:

#0  0x000000391b4206e0 in luaH_getstr () from /lib64/liblua-5.2.so
#1  0x000000391b4207d8 in luaH_get () from /lib64/liblua-5.2.so
#2  0x000000391b408ac9 in lua_rawget () from /lib64/liblua-5.2.so
#3  0x00007ffff67a70d9 in luabind::rawget<luabind::adl::object, char [8]> (table=..., key=...) at /home/kazade/Git/KGLT/submodules/luabind/luabind/detail/object.hpp:1271
#4  0x00007ffff67a6fb5 in luabind::set_package_preload (L=0x9ebad0, modulename=0x7ffff67c2647 "luabind.function_introspection", loader=
    0x7ffff67a7d60 <luabind::bind_function_introspection(lua_State*)>) at /home/kazade/Git/KGLT/submodules/luabind/src/set_package_preload.cpp:52
#5  0x00007ffff67a5cf3 in luabind::open (L=0x9ebad0) at /home/kazade/Git/KGLT/submodules/luabind/src/open.cpp:147
#6  0x00007ffff65ee2c8 in kglt::Interpreter::Interpreter (this=0x8f14f0) at /home/kazade/Git/KGLT/kglt/lua/interpreter.cpp:10

And here is my calling code:

    L_INFO("Initializing LUA interpreter");
    state_ = luaL_newstate();
    luabind::open(state_);

This is on Fedora (if it matters) and the clang compiler. Is this my error? Am I supposed to do something else before calling luabind::open ?

Thanks

@Kazade
Copy link
Author

Kazade commented Sep 15, 2013

Aha! This seems to fix it!

state_ = luaL_newstate();
luaL_openlibs(state_);
luabind::open(state_);

Should I be required to call luaL_openlibs(), is that normal?

@rpavlik
Copy link
Owner

rpavlik commented Sep 16, 2013

Yes, I think so - the "package" library is one that the package preload
mechanism interacts with. I probably shouldn't have this branch
automatically set that unless it finds that table already existing, but for
that particular feature to work, it does require that library.

Ryan

On Sun, Sep 15, 2013 at 3:00 PM, Luke Benstead notifications@github.comwrote:

Aha! This seems to fix it!

state_ = luaL_newstate();
luaL_openlibs(state_);
luabind::open(state_);

Should I be required to call luaL_openlibs(), is that normal?


Reply to this email directly or view it on GitHubhttps://github.com//pull/8#issuecomment-24478866
.

Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik@iastate.edu
http://academic.cleardefinition.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants