luvit / luv

Bare libuv bindings for lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

new_thread function dump not working with lua 5.4.3

cryptomilk opened this issue · comments

I've tried to get the lua-luv building on Fedora 34, but it fails with the first tests:

+ lua tests/run.lua                                                                           
1..107                                                                                        
  ./tests/test-async.lua:16: Error: unable to dump given function                             
  stack traceback:                                                                            
        [C]: in function 'luv.new_thread'
        ./tests/test-async.lua:16: in field 'fn'                                              
        ./lib/tap.lua:59: in function <./lib/tap.lua:48>
        [C]: in function 'xpcall'          
        ./lib/tap.lua:48: in upvalue 'run'  
        ./lib/tap.lua:146: in function 'lib/tap'
        tests/run.lua:23: in main chunk
        [C]: in ?                       
not ok 1 async - test pass async between threads

https://kojipkgs.fedoraproject.org//work/tasks/9063/71199063/build.log

The correct label would be test I guess ;-)

Relevant code:
https://github.com/luvit/luv/blob/master/tests/test-async.lua

luv/src/thread.c

Lines 210 to 233 in b85b9ef

int thread_dump(lua_State* L, const void* p, size_t sz, void* B) {
(void)L;
luaL_addlstring((luaL_Buffer*) B, (const char*) p, sz);
return 0;
}
static int luv_thread_dumped(lua_State* L, int idx) {
if (lua_isstring(L, idx)) {
lua_pushvalue(L, idx);
} else {
int ret;
luaL_Buffer b;
luaL_checktype(L, idx, LUA_TFUNCTION);
lua_pushvalue(L, idx);
luaL_buffinit(L, &b);
ret = lua_dump(L, thread_dump, &b, 1);
lua_pop(L, 1);
if (ret==0) {
luaL_pushresult(&b);
} else
luaL_error(L, "Error: unable to dump given function");
}
return 1;
}

https://www.lua.org/source/5.4/lapi.c.html#lua_dump

I wonder if the value of the return is useful.

Can reproduce this locally after updating the submodule to Lua 5.4.3 and using WITH_LUA_ENGINE=Lua. Seems to be new in either Lua 5.4.2 or 5.4.3, as the tests pass fine on 5.4.0 and 5.4.1.

EDIT: Specifically this is a 5.4.3-introduced problem. Tests pass on 5.4.2 as well.

Specifically, this check in lua_dump

if (isLfunction(o))

is failing in 5.4.3

Bisected it down to:

cf23a93d820558acdb8b1f0db85fdb94e709fee2 is the first bad commit
commit cf23a93d820558acdb8b1f0db85fdb94e709fee2
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue Mar 2 11:39:42 2021 -0300

    Added assertions for proper use of string buffers

 lauxlib.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)