diff options
author | Benoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m> | 2018-11-03 15:39:14 +0100 |
---|---|---|
committer | Benoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m> | 2018-11-03 15:39:14 +0100 |
commit | ebaadef11d4cb55a5dde78ed392b7d7e4ad15030 (patch) | |
tree | 0c91345c4e21f5dd1c9006d8545684442aa97e5a | |
parent | 94c794c8e06a848868509927eefde0741cd8bbe6 (diff) | |
download | lanes-ebaadef11d4cb55a5dde78ed392b7d7e4ad15030.tar.gz lanes-ebaadef11d4cb55a5dde78ed392b7d7e4ad15030.tar.bz2 lanes-ebaadef11d4cb55a5dde78ed392b7d7e4ad15030.zip |
fix an internal error trying to call on_state_create in a lane without any libs loaded
always duplicate the config structure in new lanes even when no
libraries are initialized by the generator
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | src/lanes.c | 9 | ||||
-rw-r--r-- | src/tools.c | 47 | ||||
-rw-r--r-- | src/tools.h | 1 | ||||
-rw-r--r-- | src/universe.h | 2 |
5 files changed, 25 insertions, 38 deletions
@@ -1,5 +1,9 @@ | |||
1 | CHANGES: | 1 | CHANGES: |
2 | 2 | ||
3 | CHANGE 130: BGe 2-Nov-18 | ||
4 | * always duplicate the config structure in new lanes even when no libraries are initialized by the generator | ||
5 | (fixes an internal error trying to call on_state_create in a lane without any libs loaded) | ||
6 | |||
3 | CHANGE 129: BGe 2-Nov-18 | 7 | CHANGE 129: BGe 2-Nov-18 |
4 | * Bumped version to 3.13 | 8 | * Bumped version to 3.13 |
5 | * fix error when autodetecting protect_allocator when running under LuaJIT | 9 | * fix error when autodetecting protect_allocator when running under LuaJIT |
diff --git a/src/lanes.c b/src/lanes.c index f2e7927..7b1a707 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -2296,12 +2296,6 @@ LUAG_FUNC( lane_new) | |||
2296 | } | 2296 | } |
2297 | else | 2297 | else |
2298 | { | 2298 | { |
2299 | // if is it "lanes" or "lanes.core", make sure we have copied the initial settings over | ||
2300 | // which might not be the case if the libs list didn't include lanes.core or "*" | ||
2301 | if( strncmp( name, "lanes.core", len) == 0) // this works both both "lanes" and "lanes.core" because of len | ||
2302 | { | ||
2303 | luaG_copy_one_time_settings( U, L, L2); | ||
2304 | } | ||
2305 | lua_pushlstring( L2, name, len); // require() name | 2299 | lua_pushlstring( L2, name, len); // require() name |
2306 | if( lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode | 2300 | if( lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode |
2307 | { | 2301 | { |
@@ -3116,6 +3110,9 @@ LUAG_FUNC( configure) | |||
3116 | lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors | 3110 | lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors |
3117 | U->verboseErrors = lua_toboolean( L, -1); | 3111 | U->verboseErrors = lua_toboolean( L, -1); |
3118 | lua_pop( L, 1); // settings | 3112 | lua_pop( L, 1); // settings |
3113 | lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata | ||
3114 | U->demoteFullUserdata = lua_toboolean( L, -1); | ||
3115 | lua_pop( L, 1); // settings | ||
3119 | #if HAVE_LANE_TRACKING | 3116 | #if HAVE_LANE_TRACKING |
3120 | MUTEX_INIT( &U->tracking_cs); | 3117 | MUTEX_INIT( &U->tracking_cs); |
3121 | lua_getfield( L, 1, "track_lanes"); // settings track_lanes | 3118 | lua_getfield( L, 1, "track_lanes"); // settings track_lanes |
diff --git a/src/tools.c b/src/tools.c index c13d80d..0ef779a 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -140,7 +140,7 @@ void initialize_on_state_create( Universe* U, lua_State* L) | |||
140 | // ################################################################################################ | 140 | // ################################################################################################ |
141 | 141 | ||
142 | // just like lua_xmove, args are (from, to) | 142 | // just like lua_xmove, args are (from, to) |
143 | void luaG_copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) | 143 | static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) |
144 | { | 144 | { |
145 | STACK_GROW( L, 1); | 145 | STACK_GROW( L, 1); |
146 | // copy settings from from source to destination registry | 146 | // copy settings from from source to destination registry |
@@ -213,11 +213,6 @@ static void open1lib( Universe* U, lua_State* L, char const* name_, size_t len_, | |||
213 | bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" | 213 | bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" |
214 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); | 214 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); |
215 | STACK_CHECK( L); | 215 | STACK_CHECK( L); |
216 | if( isLanesCore == TRUE) | ||
217 | { | ||
218 | // copy settings from from source to destination registry | ||
219 | luaG_copy_one_time_settings( U, from_, L); | ||
220 | } | ||
221 | // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) | 216 | // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) |
222 | luaL_requiref( L, name_, libfunc, !isLanesCore); | 217 | luaL_requiref( L, name_, libfunc, !isLanesCore); |
223 | // lanes.core doesn't declare a global, so scan it here and now | 218 | // lanes.core doesn't declare a global, so scan it here and now |
@@ -666,10 +661,14 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
666 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END)); | 661 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END)); |
667 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 662 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
668 | 663 | ||
664 | // copy settings (for example because it may contain a Lua on_state_create function) | ||
665 | copy_one_time_settings( U, from_, L); | ||
666 | |||
669 | // 'lua.c' stops GC during initialization so perhaps its a good idea. :) | 667 | // 'lua.c' stops GC during initialization so perhaps its a good idea. :) |
670 | lua_gc( L, LUA_GCSTOP, 0); | 668 | lua_gc( L, LUA_GCSTOP, 0); |
671 | 669 | ||
672 | // Anything causes 'base' to be taken in | 670 | |
671 | // Anything causes 'base' to be taken in | ||
673 | // | 672 | // |
674 | if( libs_ != NULL) | 673 | if( libs_ != NULL) |
675 | { | 674 | { |
@@ -1657,8 +1656,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
1657 | ret = FALSE; | 1656 | ret = FALSE; |
1658 | break; | 1657 | break; |
1659 | } | 1658 | } |
1660 | /* Allow only deep userdata entities to be copied across | 1659 | // Allow only deep userdata entities to be copied across |
1661 | */ | ||
1662 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); | 1660 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); |
1663 | if( !copydeep( U, L, L2, i, mode_)) | 1661 | if( !copydeep( U, L, L2, i, mode_)) |
1664 | { | 1662 | { |
@@ -1694,29 +1692,16 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
1694 | } | 1692 | } |
1695 | lua_pop( L, 2); // ... | 1693 | lua_pop( L, 2); // ... |
1696 | } | 1694 | } |
1695 | |||
1696 | // Not a deep or clonable full userdata | ||
1697 | if( U->demoteFullUserdata) // attempt demotion to light userdata | ||
1697 | { | 1698 | { |
1698 | // Not a deep or clonable full userdata | 1699 | void* lud = lua_touserdata( L, i); |
1699 | bool_t demote = FALSE; | 1700 | lua_pushlightuserdata( L2, lud); |
1700 | lua_getfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); | 1701 | } |
1701 | if( lua_istable( L, -1)) // should not happen, but who knows... | 1702 | else // raise an error |
1702 | { | 1703 | { |
1703 | lua_getfield( L, -1, "demote_full_userdata"); | 1704 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); |
1704 | demote = lua_toboolean( L, -1); | ||
1705 | lua_pop( L, 2); | ||
1706 | } | ||
1707 | else | ||
1708 | { | ||
1709 | lua_pop( L, 1); | ||
1710 | } | ||
1711 | if( demote) // attempt demotion to light userdata | ||
1712 | { | ||
1713 | void* lud = lua_touserdata( L, i); | ||
1714 | lua_pushlightuserdata( L2, lud); | ||
1715 | } | ||
1716 | else // raise an error | ||
1717 | { | ||
1718 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); | ||
1719 | } | ||
1720 | } | 1705 | } |
1721 | } | 1706 | } |
1722 | break; | 1707 | break; |
diff --git a/src/tools.h b/src/tools.h index 11a541c..09ae050 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -21,7 +21,6 @@ typedef struct s_Universe Universe; | |||
21 | void luaG_dump( lua_State* L ); | 21 | void luaG_dump( lua_State* L ); |
22 | 22 | ||
23 | lua_State* luaG_newstate( Universe* U, lua_State* _from, char const* libs); | 23 | lua_State* luaG_newstate( Universe* U, lua_State* _from, char const* libs); |
24 | void luaG_copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2); | ||
25 | 24 | ||
26 | // ################################################################################################ | 25 | // ################################################################################################ |
27 | 26 | ||
diff --git a/src/universe.h b/src/universe.h index a75cead..359dc90 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -32,6 +32,8 @@ struct s_Universe | |||
32 | // for verbose errors | 32 | // for verbose errors |
33 | bool_t verboseErrors; | 33 | bool_t verboseErrors; |
34 | 34 | ||
35 | bool_t demoteFullUserdata; | ||
36 | |||
35 | lua_CFunction on_state_create_func; | 37 | lua_CFunction on_state_create_func; |
36 | 38 | ||
37 | Keepers* keepers; | 39 | Keepers* keepers; |