lua-users home
lua-l archive

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


2013/3/10 Ronald Steinke <rsteinke@twistedpair.cc>:
> I was doing something with chained callbacks, using recursive closures to
> call
> each other using the C interface, and was seeing some odd seg faults. I
> created
> some test code (attached), and got some weird results. The doubled output
> from
> the recursive calls is particularly weird. Have I hit a language bug, or is
> there
> something obvious about my code I'm missing?
>
> My lua version is:
>
> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>
> The exact build is whatever's current in Mint Linux.

You should build Lua with API checks enabled. I get the following
error earlier than your segfault on my Windows machine:

Lua API check failed: (nargs+1) <= (L->top - L->base), file
lua-5.1.4\src\lapi.c, line 779

That problem is in your use of lua_call. I printed the content of the
stack before the lua_call, and it only has 1 element, which is a
function. Yet you tell lua_call that there is 1 argument in addition
to the function. So that's going to fail.

However if I replace the lua_call second parameter with 0, I get
another API check failure, but in that case during the interpreter
teardown (ie. after the Lua script finished):

Lua API check failed: (p) != luaO_nilobject, file lua-5.1.4\src\lapi.c, line 184

The call stack when that happens is:

lua: exception occured: access violation (write at 0x00000000)
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lapi.c
(184): lua_remove
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lua.c (140): docall
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lua.c
(286): handle_script
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lua.c (419): pmain
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\ldo.c
(319): luaD_precall
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\ldo.c
(376): luaD_call
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lapi.c (846): f_Ccall
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\ldo.c
(118): luaD_rawrunprotected
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\ldo.c
(463): luaD_pcall
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lapi.c
(856): lua_cpcall
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lua.c (450): main_
        e:\developpement\canopywater\tempsrc\lua-5.1.4\src\lua.c (500): main
        f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (555): __tmainCRTStartup
        f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (371): mainCRTStartup
        75D733AA (kernel32): (file name not available): BaseThreadInitThunk
        77979EF2 (ntdll): (file name not available): RtlInitializeExceptionChain
        77979EC5 (ntdll): (file name not available): RtlInitializeExceptionChain

Note that I never have duplicated logs like the original poster.