From 43343cc59b54ebf216bc3519abcf4cd3e1f0243f Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 19 Mar 2014 10:53:08 +0100 Subject: Don't mutex-wrap require() more than once --- CHANGES | 3 +++ src/keeper.c | 2 +- src/lanes.c | 2 +- src/tools.c | 9 +++++---- src/tools.h | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index ed1daee..7bda6f3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ CHANGES: +CHANGE 107: BGe 19-Mar-14 + * Make sure we don't mutex-wrap require() more than once, just in case + CHANGE 106: BGe 17-Mar-14 * Fixed crash when using protect_allocator option diff --git a/src/keeper.c b/src/keeper.c index 4d2d068..63ae7ff 100644 --- a/src/keeper.c +++ b/src/keeper.c @@ -681,7 +681,7 @@ void init_keepers( struct s_Universe* U, lua_State* L) luaL_requiref( K, "package", luaopen_package, 1); // package lua_pop( K, 1); // STACK_MID( K, 0); - serialize_require( K); + serialize_require( U, K); STACK_MID( K, 0); // copy package.path and package.cpath from the source state diff --git a/src/lanes.c b/src/lanes.c index f46046e..6b3264a 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -3108,7 +3108,7 @@ LUAG_FUNC( configure) STACK_MID( L, 0); // Serialize calls to 'require' from now on, also in the primary state - serialize_require( L); + serialize_require( U, L); // Retrieve main module interface table lua_pushvalue( L, lua_upvalueindex( 2)); // settings M diff --git a/src/tools.c b/src/tools.c index 65387e5..ea7662b 100644 --- a/src/tools.c +++ b/src/tools.c @@ -735,7 +735,7 @@ lua_State* luaG_newstate( struct s_Universe* U, lua_State* from_, char const* li } lua_gc( L, LUA_GCRESTART, 0); - serialize_require( L); + serialize_require( U, L); // call this after the base libraries are loaded and GC is restarted // will raise an error in from_ in case of problem @@ -2316,15 +2316,16 @@ int luaG_new_require( lua_State* L) /* * Serialize calls to 'require', if it exists */ -void serialize_require( lua_State* L) +void serialize_require( struct s_Universe* U, lua_State* L) { STACK_GROW( L, 1); STACK_CHECK( L); + DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "serializing require()\n" INDENT_END)); - // Check 'require' is there; if not, do nothing + // Check 'require' is there and not already wrapped; if not, do nothing // lua_getglobal( L, "require"); - if( lua_isfunction( L, -1)) + if( lua_isfunction( L, -1) && lua_tocfunction( L, -1) != luaG_new_require) { // [-1]: original 'require' function lua_pushcclosure( L, luaG_new_require, 1 /*upvalues*/); diff --git a/src/tools.h b/src/tools.h index 3152646..708421c 100644 --- a/src/tools.h +++ b/src/tools.h @@ -187,7 +187,7 @@ int luaG_nameof( lua_State* L); int luaG_new_require( lua_State* L); void populate_func_lookup_table( lua_State* L, int _i, char const* _name); -void serialize_require( lua_State *L); +void serialize_require( struct s_Universe* U, lua_State *L); void initialize_on_state_create( struct s_Universe* U, lua_State* L); void call_on_state_create( struct s_Universe* U, lua_State* L, lua_State* from_, enum eLookupMode mode_); -- cgit v1.2.3-55-g6feb