From b0bb224ce6c4bd769a3f1a868e832d9d38f6e63e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Sun, 11 Nov 2018 08:50:49 +0100 Subject: fix a bunch of compilation warnings (issue #157) --- src/deep.c | 12 ++--- src/keeper.c | 2 +- src/lanes.c | 11 ++--- src/macros_and_utils.h | 12 +++-- src/tools.c | 129 +++++++++++++++++++++++++------------------------ src/tools.h | 2 +- src/uniquekey.h | 2 +- 7 files changed, 88 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/deep.c b/src/deep.c index 6a735b8..af7f580 100644 --- a/src/deep.c +++ b/src/deep.c @@ -123,13 +123,13 @@ void luaG_pushdeepversion( lua_State* L) { (void) lua_pushliteral( L, "ab8743e5- * idfunc -> metatable */ // crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/ -static DECLARE_CONST_UNIQUE_KEY( DEEP_LOOKUP_KEY, (void*)0x9fb9b4f3f633d83d); +static DECLARE_CONST_UNIQUE_KEY( DEEP_LOOKUP_KEY, 0x9fb9b4f3f633d83d); /* * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/ */ -static DECLARE_CONST_UNIQUE_KEY( DEEP_PROXY_CACHE_KEY, (void*)0x05773d6fc26be106); +static DECLARE_CONST_UNIQUE_KEY( DEEP_PROXY_CACHE_KEY, 0x05773d6fc26be106); /* * Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists. @@ -302,7 +302,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, Lo *proxy = prelude; // Get/create metatable for 'idfunc' (in this state) - lua_pushlightuserdata( L, prelude->idfunc); // DPC proxy idfunc + lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy idfunc get_deep_lookup( L); // DPC proxy metatable? if( lua_isnil( L, -1)) // // No metatable yet. @@ -351,16 +351,16 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, Lo // Memorize for later rounds lua_pushvalue( L, -1); // DPC proxy metatable metatable - lua_pushlightuserdata( L, prelude->idfunc); // DPC proxy metatable metatable idfunc + lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc set_deep_lookup( L); // DPC proxy metatable // 2 - cause the target state to require the module that exported the idfunc // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc { - int oldtop = lua_gettop( L); + int oldtop_module = lua_gettop( L); modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable // make sure the function pushed nothing on the stack! - if( lua_gettop( L) - oldtop != 0) + if( lua_gettop( L) - oldtop_module != 0) { lua_pop( L, 3); // return "Bad idfunc(eOP_module): should not push anything"; diff --git a/src/keeper.c b/src/keeper.c index b67bee2..091463e 100644 --- a/src/keeper.c +++ b/src/keeper.c @@ -676,7 +676,7 @@ void init_keepers( Universe* U, lua_State* L) luaL_requiref( K, "package", luaopen_package, 1); // package lua_pop( K, 1); // STACK_MID( K, 0); - serialize_require( U, K); + serialize_require( DEBUGSPEW_PARAM_COMMA( 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 f43a2e6..f0a5697 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -963,7 +963,6 @@ LUAG_FUNC( linda_cancel) { struct s_Linda* linda = lua_toLinda( L, 1); char const* who = luaL_optstring( L, 2, "both"); - Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); // make sure we got 3 arguments: the linda, a key and a limit luaL_argcheck( L, lua_gettop( L) <= 2, 2, "wrong number of arguments"); @@ -1255,7 +1254,6 @@ static void* linda_id( lua_State* L, DeepOp op_) lua_setfield( L, -2, "get"); lua_pushcfunction( L, LG_linda_cancel); - lua_pushcclosure( L, LG_linda_protected_call, 1); lua_setfield( L, -2, "cancel"); lua_pushcfunction( L, LG_linda_deep); @@ -1515,6 +1513,9 @@ static cancel_result thread_cancel( lua_State* L, Lane* s, double secs, bool_t f { return luaL_error( L, "force-killed lane failed to terminate within %f second%s", waitkill_timeout_, waitkill_timeout_ > 1 ? "s" : ""); } +#else + (void) waitkill_timeout_; // unused + (void) L; // unused #endif // THREADAPI == THREADAPI_PTHREAD s->mstatus = KILLED; // mark 'gc' to wait for it // note that s->status value must remain to whatever it was at the time of the kill @@ -1809,14 +1810,13 @@ LUAG_FUNC( set_singlethreaded) } // requires 'chudInitialize()' utilBindThreadToCPU(0); // # of CPU to run on (we cannot limit to 2..N CPUs?) + return 0; #else return luaL_error( L, "Not available: compile with _UTILBINDTHREADTOCPU"); #endif #else return luaL_error( L, "not implemented"); #endif - - return 0; } @@ -2204,7 +2204,6 @@ LUAG_FUNC( require) LUAG_FUNC( register) { char const* name = luaL_checkstring( L, 1); - int const nargs = lua_gettop( L); int const mod_type = lua_type( L, 2); // ignore extra parameters, just in case lua_settop( L, 2); @@ -3179,7 +3178,7 @@ LUAG_FUNC( configure) STACK_MID( L, 0); // Serialize calls to 'require' from now on, also in the primary state - serialize_require( U, L); + serialize_require( DEBUGSPEW_PARAM_COMMA( U) L); // Retrieve main module interface table lua_pushvalue( L, lua_upvalueindex( 2)); // settings M diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 9d73d50..550fc0a 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h @@ -36,8 +36,12 @@ extern char const* debugspew_indent; #define INDENT_BEGIN "%.*s " #define INDENT_END , (U ? U->debugspew_indent_depth : 0), debugspew_indent #define DEBUGSPEW_CODE(_code) _code +#define DEBUGSPEW_PARAM_COMMA( param_) param_, +#define DEBUGSPEW_COMMA_PARAM( param_) , param_ #else // USE_DEBUG_SPEW #define DEBUGSPEW_CODE(_code) +#define DEBUGSPEW_PARAM_COMMA( param_) +#define DEBUGSPEW_COMMA_PARAM( param_) #endif // USE_DEBUG_SPEW #ifdef NDEBUG @@ -56,10 +60,10 @@ extern char const* debugspew_indent; #define STACK_MID(L,change) \ do \ { \ - int a = lua_gettop( L) - _oldtop_##L; \ - int b = (change); \ - if( a != b) \ - luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", a, b, __FILE__, __LINE__ ); \ + int stack_check_a = lua_gettop( L) - _oldtop_##L; \ + int stack_check_b = (change); \ + if( stack_check_a != stack_check_b) \ + luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", stack_check_a, stack_check_b, __FILE__, __LINE__ ); \ } while( 0) #define STACK_END(L,change) STACK_MID(L,change); } diff --git a/src/tools.c b/src/tools.c index 8e886b5..6f71dd8 100644 --- a/src/tools.c +++ b/src/tools.c @@ -199,7 +199,7 @@ static const luaL_Reg libs[] = { NULL, NULL } }; -static void open1lib( Universe* U, lua_State* L, char const* name_, size_t len_, lua_State* from_) +static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) { int i; for( i = 0; libs[i].name; ++ i) @@ -679,7 +679,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening ALL standard libraries\n" INDENT_END)); luaL_openlibs( L); // don't forget lanes.core for regular lane states - open1lib( U, L, "lanes.core", 10, from_); + open1lib( DEBUGSPEW_PARAM_COMMA( U) L, "lanes.core", 10); libs_ = NULL; // done with libs } else @@ -713,12 +713,12 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) while( isalnum( p[len]) || p[len] == '.') ++ len; // open library - open1lib( U, L, p, len, from_); + open1lib( DEBUGSPEW_PARAM_COMMA( U) L, p, len); } } lua_gc( L, LUA_GCRESTART, 0); - serialize_require( U, L); + serialize_require( DEBUGSPEW_PARAM_COMMA( U) L); // call this after the base libraries are loaded and GC is restarted // will raise an error in from_ in case of problem @@ -1353,7 +1353,7 @@ static void inter_copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_ // "Otherwise, it pushes an error message" // STACK_GROW( L, 1); - luaL_error( L, "%s", lua_tostring( L2, -1)); + luaL_error( L, "%s: %s", upName_, lua_tostring( L2, -1)); } // remove the dumped string lua_pop( L, 1); // ... @@ -1567,6 +1567,12 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache valPath = (char*) alloca( strlen( upName_) + 32 + 3); sprintf( valPath, "%s[" LUA_NUMBER_FMT "]", upName_, key); } + else if( lua_type( L, key_i) == LUA_TLIGHTUSERDATA) + { + void* key = lua_touserdata( L, key_i); + valPath = (char*) alloca( strlen( upName_) + 16 + 5); + sprintf( valPath, "%s[U:%p]", upName_, key); + } } /* * Contents of metatables are copied with cache checking; @@ -1597,7 +1603,6 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) { bool_t ret = TRUE; - bool_t ignore = FALSE; int val_type = lua_type( L, i); STACK_GROW( L2, 1); STACK_CHECK( L); // L // L2 @@ -1671,71 +1676,69 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu } STACK_MID( L, 0); - if( lua_getmetatable( L, i)) // ... mt? + if( lua_getmetatable( L, i)) // ... mt? + { + lua_getfield( L, -1, "__lanesclone"); // ... mt __lanesclone? + if( lua_isnil( L, -1)) { - lua_getfield( L, -1, "__lanesclone"); // ... mt __lanesclone? - if( lua_isnil( L, -1)) - { - lua_pop( L, 2); // ... - } - else + lua_pop( L, 2); // ... + } + else + { + size_t userdata_size = 0; + void* const source = lua_touserdata( L, i); + void* clone = NULL; + lua_pushvalue( L, -1); // ... mt __lanesclone __lanesclone + // call the cloning function with 0 arguments, should return the number of bytes to allocate for the clone + lua_call( L, 0, 1); // ... mt __lanesclone size + STACK_MID( L, 3); + userdata_size = (size_t) lua_tointeger( L, -1); // ... mt __lanesclone size + lua_pop( L, 1); // ... mt __lanesclone + clone = lua_newuserdata( L2, userdata_size); // ... u + // call cloning function in source state to perform the actual memory cloning + lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone + lua_pushlightuserdata( L, source); // ... mt __lanesclone source + lua_call( L, 2, 0); // ... mt + STACK_MID( L, 1); + // copy the metatable in the target state + if( inter_copy_one_( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_)) // ... u mt? { - FuncSubType fst; - lua_CFunction cloneFunc = luaG_tocfunction( L, -1, &fst); - size_t userdata_size = 0; - void* const source = lua_touserdata( L, i); - void* clone = NULL; - lua_pushvalue( L, -1); // ... mt __lanesclone __lanesclone - // call the cloning function with 0 arguments, should return the number of bytes to allocate for the clone - lua_call( L, 0, 1); // ... mt __lanesclone size - STACK_MID( L, 3); - userdata_size = (size_t) lua_tointeger( L, -1); // ... mt __lanesclone size - lua_pop( L, 1); // ... mt __lanesclone - clone = lua_newuserdata( L2, userdata_size); // ... u - // call cloning function in source state to perform the actual memory cloning - lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone - lua_pushlightuserdata( L, source); // ... mt __lanesclone source - lua_call( L, 2, 0); // ... mt - STACK_MID( L, 1); - // copy the metatable in the target state - if( inter_copy_one_( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_)) // ... u mt? + lua_pop( L, 1); // ... + STACK_MID( L, 0); + // when writing to a keeper state, we have here a sentinel function with the metatable's fqn as upvalue + if( eLM_ToKeeper == mode_) // ... u sentinel { - lua_pop( L, 1); // ... - STACK_MID( L, 0); - // when writing to a keeper state, we have here a sentinel function with the metatable's fqn as upvalue - if( eLM_ToKeeper == mode_) // ... u sentinel - { - ASSERT_L( lua_tocfunction( L2, -1) == table_lookup_sentinel); - // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn - lua_getupvalue( L2, -1, 1); // ... u sentinel fqn - lua_remove( L2, -2); // ... u fqn - lua_insert( L2, -2); // ... fqn u - lua_pushcclosure( L2, userdata_clone_sentinel, 2); // ... userdata_clone_sentinel - } - else // from keeper or direct, we have the userdata and the metatable - { - ASSERT_L( lua_istable( L2, -1)); - lua_setmetatable( L2, -2); // ... u - } + ASSERT_L( lua_tocfunction( L2, -1) == table_lookup_sentinel); + // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn + lua_getupvalue( L2, -1, 1); // ... u sentinel fqn + lua_remove( L2, -2); // ... u fqn + lua_insert( L2, -2); // ... fqn u + lua_pushcclosure( L2, userdata_clone_sentinel, 2); // ... userdata_clone_sentinel } - else + else // from keeper or direct, we have the userdata and the metatable { - (void) luaL_error( L, "Error copying a metatable"); + ASSERT_L( lua_istable( L2, -1)); + lua_setmetatable( L2, -2); // ... u } } - break; + else + { + (void) luaL_error( L, "Error copying a metatable"); + } } + break; + } - // Not a deep or clonable full userdata - if( U->demoteFullUserdata) // attempt demotion to light userdata - { - void* lud = lua_touserdata( L, i); - lua_pushlightuserdata( L2, lud); - } - else // raise an error - { - (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); - } + // Not a deep or clonable full userdata + if( U->demoteFullUserdata) // attempt demotion to light userdata + { + void* lud = lua_touserdata( L, i); + lua_pushlightuserdata( L2, lud); + } + else // raise an error + { + (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); + } break; case LUA_TNIL: @@ -2035,7 +2038,7 @@ int luaG_new_require( lua_State* L) /* * Serialize calls to 'require', if it exists */ -void serialize_require( Universe* U, lua_State* L) +void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L) { STACK_GROW( L, 1); STACK_CHECK( L); diff --git a/src/tools.h b/src/tools.h index 09ae050..2f78b73 100644 --- a/src/tools.h +++ b/src/tools.h @@ -33,7 +33,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( Universe* U, lua_State *L); +void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State *L); void initialize_on_state_create( Universe* U, lua_State* L); void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); diff --git a/src/uniquekey.h b/src/uniquekey.h index b9a35cb..b3ef7dc 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -13,7 +13,7 @@ typedef struct s_UniqueKey UniqueKey; #if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) // building against LuaJIT headers, light userdata is restricted to 47 significant bits. #define MAKE_UNIQUE_KEY( p_) ((void*)((ptrdiff_t)(p_) & 0x7fffffffffffull)) #else // LUA_JITLIBNAME -#define MAKE_UNIQUE_KEY( p_) ((void*) p_) +#define MAKE_UNIQUE_KEY( p_) ((void*)(ptrdiff_t)(p_)) #endif // LUA_JITLIBNAME #define DECLARE_UNIQUE_KEY( name_) UniqueKey name_ -- cgit v1.2.3-55-g6feb