lua-users home
lua-l archive

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


Hi there,

I have a threaded application that randomly segfault at lua_pcall.
Unfortunately I can't figure out why.. I've compiled Lua with
LUA_APICHECK and debug symbols and there is the backtrace :

#0  luaV_execute (L=0x80201e700) at lvm.c:542
        ci = 0x802018a10
        k = 0x80214ee50
        base = <optimized out>
#1  0x00000000004a2c49 in luaD_call (L=0x80201e700, func=<optimized
out>, nResults=<optimized out>, allowyield=0) at ldo.c:395
No locals.
#2  0x00000000004a1ef8 in luaD_rawrunprotected (L=0x80201e700,
f=0x4a0120 <f_call>, ud=0x7fffffbfb050) at ldo.c:131
        oldnCcalls = 0
        lj = {previous = 0x0, b = {{_jb = {4857575, 3648,
140737484140392, 34393417472, 0, 0, 1, 1, 34772055229311,
140737484141984, 34397446640, 34397446640}}}, status = 0}
#3  0x00000000004a1f67 in luaD_pcall (L=0x80201e700, func=0x80214ef40,
u=0x802018a10, old_top=34393393680, ef=0) at ldo.c:595
        status = <optimized out>
        old_ci = 0x80201e780
        old_allowhooks = 1 '\001'
        old_nny = 1
        old_errfunc = 0
#4  0x00000000004a006f in lua_pcallk (L=0x80201e700, nargs=0,
nresults=0, errfunc=<optimized out>, ctx=0, k=0x0) at lapi.c:949
        c = {func = 0x802c08440, nresults = 0}
        status = <optimized out>
        func = 0
#5  0x0000000000462753 in irccd::LuaState::pcall (this=0x80201b4e8,
np=4, nr=0, errorh=0) at
/home/markand/work/irccd/irccd/LuaState.cpp:118
        success = 2

My function LuaState::pcall() is just a C++ wrapper around a
lua_State, and is defined as follow :

bool LuaState::pcall(int np, int nr, int errorh)
{
    bool success;

    success = lua_pcall(getState(), np, nr, errorh) == LUA_OK;
    if (!success && errorh == 0) {
        m_error = lua_tostring(getState(), -1);
        lua_pop(getState(), 1);
    }

    return success;
}

getState() is the function that returns the plain C lua_State pointer.
I've already debugged this function and everything were correct.

I'll try to compile without optimization and hope core dump will still
occurs to avoid these <optimized out> variables.

Do you have any idea what I did wrong? My function that called
LuaState::pcall is absolutely correct and does only the following :

    if (m_state.getglobal("onCommand") != LUA_TFUNCTION)
        return;

    LuaServer::pushObject(m_state, server);
    m_state.push(channel);
    m_state.push(who);
    m_state.push(message);

    if (!m_state.pcall(4, 0))
        throw ErrorException(m_name, m_state.getError());

I ensured that channel, who and message are not empty of course.

--
Demelier David