diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-07-08 14:35:32 +0200 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-07-08 14:35:32 +0200 |
commit | 0326aa6636b1dce2b2fc4c9db53b023534ca0512 (patch) | |
tree | 2265af6ccfdc7530e2d87d1d3484dc8131726ea8 | |
parent | b96ca247aa6ef2832bb4fc77826169f89219434d (diff) | |
download | lanes-0326aa6636b1dce2b2fc4c9db53b023534ca0512.tar.gz lanes-0326aa6636b1dce2b2fc4c9db53b023534ca0512.tar.bz2 lanes-0326aa6636b1dce2b2fc4c9db53b023534ca0512.zip |
fix lookup of globals created by on_state_create
* Postponed _G scan for function lookup database to after
on_state_create invocation
* Fixed a crash when USE_DEBUG_SPEW == 1
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | src/lanes.c | 16 | ||||
-rw-r--r-- | src/tools.c | 19 |
3 files changed, 35 insertions, 4 deletions
@@ -1,5 +1,9 @@ | |||
1 | CHANGES: | 1 | CHANGES: |
2 | 2 | ||
3 | CHANGE 114: BGe 8-Jul-14 | ||
4 | * Postponed _G scan for function lookup database to after on_state_create invocation | ||
5 | * Fixed a crash when USE_DEBUG_SPEW == 1 | ||
6 | |||
3 | CHANGE 113: BGe 17-Jun-14 | 7 | CHANGE 113: BGe 17-Jun-14 |
4 | * bumped version to 3.9.6 | 8 | * bumped version to 3.9.6 |
5 | * separate deep userdata code in a dedicated file to allow external modules to implement Lanes-compatible deep userdata without requiring a binary dependency against the Lanes module | 9 | * separate deep userdata code in a dedicated file to allow external modules to implement Lanes-compatible deep userdata without requiring a binary dependency against the Lanes module |
diff --git a/src/lanes.c b/src/lanes.c index 6acc711..1d60700 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -3000,6 +3000,7 @@ static volatile long s_initCount = 0; | |||
3000 | LUAG_FUNC( configure) | 3000 | LUAG_FUNC( configure) |
3001 | { | 3001 | { |
3002 | struct s_Universe* U = get_universe( L); | 3002 | struct s_Universe* U = get_universe( L); |
3003 | bool_t const from_master_state = (U == NULL); | ||
3003 | char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); | 3004 | char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); |
3004 | _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); | 3005 | _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); |
3005 | 3006 | ||
@@ -3045,7 +3046,7 @@ LUAG_FUNC( configure) | |||
3045 | STACK_CHECK( L); | 3046 | STACK_CHECK( L); |
3046 | 3047 | ||
3047 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); | 3048 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); |
3048 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 3049 | DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth); |
3049 | 3050 | ||
3050 | lua_getfield( L, 1, "protect_allocator"); // settings protect_allocator | 3051 | lua_getfield( L, 1, "protect_allocator"); // settings protect_allocator |
3051 | if( lua_toboolean( L, -1)) | 3052 | if( lua_toboolean( L, -1)) |
@@ -3070,6 +3071,7 @@ LUAG_FUNC( configure) | |||
3070 | lua_pushlightuserdata( L, UNIVERSE_REGKEY); // settings UNIVERSE_REGKEY | 3071 | lua_pushlightuserdata( L, UNIVERSE_REGKEY); // settings UNIVERSE_REGKEY |
3071 | U = (struct s_Universe*) lua_newuserdata( L, sizeof( struct s_Universe)); // settings UNIVERSE_REGKEY universe | 3072 | U = (struct s_Universe*) lua_newuserdata( L, sizeof( struct s_Universe)); // settings UNIVERSE_REGKEY universe |
3072 | memset( U, 0, sizeof( struct s_Universe)); | 3073 | memset( U, 0, sizeof( struct s_Universe)); |
3074 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
3073 | lua_newtable( L); // settings UNIVERSE_REGKEY universe mt | 3075 | lua_newtable( L); // settings UNIVERSE_REGKEY universe mt |
3074 | lua_getfield( L, 1, "shutdown_timeout"); // settings UNIVERSE_REGKEY universe mt shutdown_timeout | 3076 | lua_getfield( L, 1, "shutdown_timeout"); // settings UNIVERSE_REGKEY universe mt shutdown_timeout |
3075 | lua_pushcclosure( L, selfdestruct_gc, 1); // settings UNIVERSE_REGKEY universe mt selfdestruct_gc | 3077 | lua_pushcclosure( L, selfdestruct_gc, 1); // settings UNIVERSE_REGKEY universe mt selfdestruct_gc |
@@ -3195,9 +3197,15 @@ LUAG_FUNC( configure) | |||
3195 | 3197 | ||
3196 | // record all existing C/JIT-fast functions | 3198 | // record all existing C/JIT-fast functions |
3197 | // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack | 3199 | // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack |
3198 | lua_pushglobaltable( L); // settings M _G | 3200 | if( from_master_state) |
3199 | populate_func_lookup_table( L, -1, NULL); | 3201 | { |
3200 | lua_pop( L, 1); // settings M | 3202 | // don't do this when called during the initialization of a new lane, |
3203 | // because we will do it after on_state_create() is called, | ||
3204 | // and we don't want skip _G because of caching in case globals are created then | ||
3205 | lua_pushglobaltable( L); // settings M _G | ||
3206 | populate_func_lookup_table( L, -1, NULL); | ||
3207 | lua_pop( L, 1); // settings M | ||
3208 | } | ||
3201 | // set _R[CONFIG_REGKEY] = settings | 3209 | // set _R[CONFIG_REGKEY] = settings |
3202 | lua_pushvalue( L, -2); // settings M settings | 3210 | lua_pushvalue( L, -2); // settings M settings |
3203 | lua_setfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); // settings M | 3211 | lua_setfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); // settings M |
diff --git a/src/tools.c b/src/tools.c index 628b277..e0f4c40 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -446,6 +446,8 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
446 | // prepare the stack for database feed | 446 | // prepare the stack for database feed |
447 | lua_pushvalue( L, -1); // ... {_i} {bfc} k func "f.q.n" "f.q.n" | 447 | lua_pushvalue( L, -1); // ... {_i} {bfc} k func "f.q.n" "f.q.n" |
448 | lua_pushvalue( L, -3); // ... {_i} {bfc} k func "f.q.n" "f.q.n" func | 448 | lua_pushvalue( L, -3); // ... {_i} {bfc} k func "f.q.n" "f.q.n" func |
449 | ASSERT_L( lua_rawequal( L, -1, -4)); | ||
450 | ASSERT_L( lua_rawequal( L, -2, -3)); | ||
449 | // t["f.q.n"] = func | 451 | // t["f.q.n"] = func |
450 | lua_rawset( L, dest); // ... {_i} {bfc} k func "f.q.n" | 452 | lua_rawset( L, dest); // ... {_i} {bfc} k func "f.q.n" |
451 | // t[func] = "f.q.n" | 453 | // t[func] = "f.q.n" |
@@ -704,6 +706,23 @@ lua_State* luaG_newstate( struct s_Universe* U, lua_State* from_, char const* li | |||
704 | // after all this, register everything we find in our name<->function database | 706 | // after all this, register everything we find in our name<->function database |
705 | lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack | 707 | lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack |
706 | populate_func_lookup_table( L, -1, NULL); | 708 | populate_func_lookup_table( L, -1, NULL); |
709 | |||
710 | #if 0 && USE_DEBUG_SPEW | ||
711 | // dump the lookup database contents | ||
712 | lua_getfield( L, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // {} | ||
713 | lua_pushnil( L); // {} nil | ||
714 | while( lua_next( L, -2)) // {} k v | ||
715 | { | ||
716 | lua_getglobal( L, "print"); // {} k v print | ||
717 | lua_pushlstring( L, debugspew_indent, U->debugspew_indent_depth); // {} k v print " " | ||
718 | lua_pushvalue( L, -4); // {} k v print " " k | ||
719 | lua_pushvalue( L, -4); // {} k v print " " k v | ||
720 | lua_call( L, 3, 0); // {} k v | ||
721 | lua_pop( L, 1); // {} k | ||
722 | } | ||
723 | lua_pop( L, 1); // {} | ||
724 | #endif // USE_DEBUG_SPEW | ||
725 | |||
707 | lua_pop( L, 1); | 726 | lua_pop( L, 1); |
708 | STACK_END( L, 0); | 727 | STACK_END( L, 0); |
709 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 728 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |