@@ -37,13 +37,21 @@ static void expect_thread_busy(lua_State *L, lua_CFunction fn,
3737 const char * what )
3838{
3939 int status ;
40+ const char * msg ;
4041 lua_pushcfunction (L , fn );
4142 status = lua_pcall (L , 0 , 0 , 0 );
42- assert (status == LUA_ERRRUN );
43- assert (lua_tostring (L , -1 ) != NULL );
44- assert (strstr (lua_tostring (L , -1 ), "thread busy" ) != NULL );
43+ if (status != LUA_ERRRUN ) {
44+ fprintf (stderr , "%s: expected LUA_ERRRUN, got %d\n" , what , status );
45+ assert (status == LUA_ERRRUN );
46+ }
47+ msg = lua_tostring (L , -1 );
48+ if (msg == NULL || strstr (msg , "thread busy" ) == NULL ) {
49+ fprintf (stderr , "%s: unexpected error object type=%s message=%s\n" ,
50+ what , lua_typename (L , lua_type (L , -1 )), msg ? msg : "<null>" );
51+ assert (msg != NULL );
52+ assert (strstr (msg , "thread busy" ) != NULL );
53+ }
4554 lua_pop (L , 1 );
46- (void )what ;
4755}
4856
4957static uint32_t foreign_tid (lua_State * L )
@@ -455,6 +463,16 @@ static void check_upvalue_api_unowned(lua_State *L)
455463 assert (lua_tointeger (co , -1 ) == 80 );
456464 assert (lj_state_owner_acq (co ) == 0 );
457465
466+ lua_settop (L , 0 );
467+ co = load_ownerless_results (L ,
468+ "local function make(x) return function() return x end end\n"
469+ "return make(1), make(2)" , 2 );
470+ lua_upvaluejoin (co , 1 , 1 , 2 , 1 );
471+ lua_pushvalue (co , 1 );
472+ lua_call (co , 0 , 1 );
473+ assert (lua_tointeger (co , -1 ) == 2 );
474+ assert (lj_state_owner_acq (co ) == 0 );
475+
458476 lua_settop (L , 0 );
459477}
460478
@@ -1189,6 +1207,19 @@ static int busy_lua_setupvalue(lua_State *L)
11891207 return 0 ;
11901208}
11911209
1210+ static int busy_lua_upvaluejoin (lua_State * L )
1211+ {
1212+ lua_State * co = lua_newthread (L );
1213+ assert (luaL_loadstring (L ,
1214+ "local function make(x) return function() return x end end\n"
1215+ "return make(1), make(2)" ) == 0 );
1216+ lua_call (L , 0 , 2 );
1217+ lua_xmove (L , co , 2 );
1218+ lj_state_owner_rel (co , foreign_tid (L ));
1219+ lua_upvaluejoin (co , 1 , 1 , 2 , 1 );
1220+ return 0 ;
1221+ }
1222+
11921223static lua_State * busy_udata_prepare (lua_State * L )
11931224{
11941225 lua_State * co ;
@@ -1602,6 +1633,7 @@ int main(void)
16021633 expect_thread_busy (L , busy_lua_getupvalue , "busy lua_getupvalue" );
16031634 expect_thread_busy (L , busy_lua_upvalueid , "busy lua_upvalueid" );
16041635 expect_thread_busy (L , busy_lua_setupvalue , "busy lua_setupvalue" );
1636+ expect_thread_busy (L , busy_lua_upvaluejoin , "busy lua_upvaluejoin" );
16051637 expect_thread_busy (L , busy_luaL_testudata , "busy luaL_testudata" );
16061638 expect_thread_busy (L , busy_luaL_checkudata , "busy luaL_checkudata" );
16071639 expect_thread_busy (L , busy_luaL_getmetafield , "busy luaL_getmetafield" );
0 commit comments