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-11 08:50:49 +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-11 08:50:49 +0100 |
| commit | b0bb224ce6c4bd769a3f1a868e832d9d38f6e63e (patch) | |
| tree | 1810e92a24c95fa707b6b9bd56fd2526cdc86381 | |
| parent | a3ec8e0b6b5cc88063893fd7226599727a41dd29 (diff) | |
| download | lanes-b0bb224ce6c4bd769a3f1a868e832d9d38f6e63e.tar.gz lanes-b0bb224ce6c4bd769a3f1a868e832d9d38f6e63e.tar.bz2 lanes-b0bb224ce6c4bd769a3f1a868e832d9d38f6e63e.zip | |
fix a bunch of compilation warnings (issue #157)
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | src/deep.c | 12 | ||||
| -rw-r--r-- | src/keeper.c | 2 | ||||
| -rw-r--r-- | src/lanes.c | 11 | ||||
| -rw-r--r-- | src/macros_and_utils.h | 12 | ||||
| -rw-r--r-- | src/tools.c | 129 | ||||
| -rw-r--r-- | src/tools.h | 2 | ||||
| -rw-r--r-- | src/uniquekey.h | 2 |
8 files changed, 91 insertions, 82 deletions
| @@ -1,5 +1,8 @@ | |||
| 1 | CHANGES: | 1 | CHANGES: |
| 2 | 2 | ||
| 3 | CHANGE 135: BGe 11-Nov-18 | ||
| 4 | * fix a bunch of compilation warnings | ||
| 5 | |||
| 3 | CHANGE 134: BGe 3-Dec-13 | 6 | CHANGE 134: BGe 3-Dec-13 |
| 4 | * new API lanes.set_thread_affinity() | 7 | * new API lanes.set_thread_affinity() |
| 5 | * set_debug_threadname implemented with win32 pthread | 8 | * set_debug_threadname implemented with win32 pthread |
| @@ -123,13 +123,13 @@ void luaG_pushdeepversion( lua_State* L) { (void) lua_pushliteral( L, "ab8743e5- | |||
| 123 | * idfunc -> metatable | 123 | * idfunc -> metatable |
| 124 | */ | 124 | */ |
| 125 | // crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/ | 125 | // crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/ |
| 126 | static DECLARE_CONST_UNIQUE_KEY( DEEP_LOOKUP_KEY, (void*)0x9fb9b4f3f633d83d); | 126 | static DECLARE_CONST_UNIQUE_KEY( DEEP_LOOKUP_KEY, 0x9fb9b4f3f633d83d); |
| 127 | 127 | ||
| 128 | /* | 128 | /* |
| 129 | * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying | 129 | * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying |
| 130 | * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/ | 130 | * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/ |
| 131 | */ | 131 | */ |
| 132 | static DECLARE_CONST_UNIQUE_KEY( DEEP_PROXY_CACHE_KEY, (void*)0x05773d6fc26be106); | 132 | static DECLARE_CONST_UNIQUE_KEY( DEEP_PROXY_CACHE_KEY, 0x05773d6fc26be106); |
| 133 | 133 | ||
| 134 | /* | 134 | /* |
| 135 | * Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists. | 135 | * 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 | |||
| 302 | *proxy = prelude; | 302 | *proxy = prelude; |
| 303 | 303 | ||
| 304 | // Get/create metatable for 'idfunc' (in this state) | 304 | // Get/create metatable for 'idfunc' (in this state) |
| 305 | lua_pushlightuserdata( L, prelude->idfunc); // DPC proxy idfunc | 305 | lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy idfunc |
| 306 | get_deep_lookup( L); // DPC proxy metatable? | 306 | get_deep_lookup( L); // DPC proxy metatable? |
| 307 | 307 | ||
| 308 | if( lua_isnil( L, -1)) // // No metatable yet. | 308 | 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 | |||
| 351 | 351 | ||
| 352 | // Memorize for later rounds | 352 | // Memorize for later rounds |
| 353 | lua_pushvalue( L, -1); // DPC proxy metatable metatable | 353 | lua_pushvalue( L, -1); // DPC proxy metatable metatable |
| 354 | lua_pushlightuserdata( L, prelude->idfunc); // DPC proxy metatable metatable idfunc | 354 | lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc |
| 355 | set_deep_lookup( L); // DPC proxy metatable | 355 | set_deep_lookup( L); // DPC proxy metatable |
| 356 | 356 | ||
| 357 | // 2 - cause the target state to require the module that exported the idfunc | 357 | // 2 - cause the target state to require the module that exported the idfunc |
| 358 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc | 358 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc |
| 359 | { | 359 | { |
| 360 | int oldtop = lua_gettop( L); | 360 | int oldtop_module = lua_gettop( L); |
| 361 | modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable | 361 | modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable |
| 362 | // make sure the function pushed nothing on the stack! | 362 | // make sure the function pushed nothing on the stack! |
| 363 | if( lua_gettop( L) - oldtop != 0) | 363 | if( lua_gettop( L) - oldtop_module != 0) |
| 364 | { | 364 | { |
| 365 | lua_pop( L, 3); // | 365 | lua_pop( L, 3); // |
| 366 | return "Bad idfunc(eOP_module): should not push anything"; | 366 | 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) | |||
| 676 | luaL_requiref( K, "package", luaopen_package, 1); // package | 676 | luaL_requiref( K, "package", luaopen_package, 1); // package |
| 677 | lua_pop( K, 1); // | 677 | lua_pop( K, 1); // |
| 678 | STACK_MID( K, 0); | 678 | STACK_MID( K, 0); |
| 679 | serialize_require( U, K); | 679 | serialize_require( DEBUGSPEW_PARAM_COMMA( U) K); |
| 680 | STACK_MID( K, 0); | 680 | STACK_MID( K, 0); |
| 681 | 681 | ||
| 682 | // copy package.path and package.cpath from the source state | 682 | // 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) | |||
| 963 | { | 963 | { |
| 964 | struct s_Linda* linda = lua_toLinda( L, 1); | 964 | struct s_Linda* linda = lua_toLinda( L, 1); |
| 965 | char const* who = luaL_optstring( L, 2, "both"); | 965 | char const* who = luaL_optstring( L, 2, "both"); |
| 966 | Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); | ||
| 967 | 966 | ||
| 968 | // make sure we got 3 arguments: the linda, a key and a limit | 967 | // make sure we got 3 arguments: the linda, a key and a limit |
| 969 | luaL_argcheck( L, lua_gettop( L) <= 2, 2, "wrong number of arguments"); | 968 | 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_) | |||
| 1255 | lua_setfield( L, -2, "get"); | 1254 | lua_setfield( L, -2, "get"); |
| 1256 | 1255 | ||
| 1257 | lua_pushcfunction( L, LG_linda_cancel); | 1256 | lua_pushcfunction( L, LG_linda_cancel); |
| 1258 | lua_pushcclosure( L, LG_linda_protected_call, 1); | ||
| 1259 | lua_setfield( L, -2, "cancel"); | 1257 | lua_setfield( L, -2, "cancel"); |
| 1260 | 1258 | ||
| 1261 | lua_pushcfunction( L, LG_linda_deep); | 1259 | 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 | |||
| 1515 | { | 1513 | { |
| 1516 | return luaL_error( L, "force-killed lane failed to terminate within %f second%s", waitkill_timeout_, waitkill_timeout_ > 1 ? "s" : ""); | 1514 | return luaL_error( L, "force-killed lane failed to terminate within %f second%s", waitkill_timeout_, waitkill_timeout_ > 1 ? "s" : ""); |
| 1517 | } | 1515 | } |
| 1516 | #else | ||
| 1517 | (void) waitkill_timeout_; // unused | ||
| 1518 | (void) L; // unused | ||
| 1518 | #endif // THREADAPI == THREADAPI_PTHREAD | 1519 | #endif // THREADAPI == THREADAPI_PTHREAD |
| 1519 | s->mstatus = KILLED; // mark 'gc' to wait for it | 1520 | s->mstatus = KILLED; // mark 'gc' to wait for it |
| 1520 | // note that s->status value must remain to whatever it was at the time of the kill | 1521 | // 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) | |||
| 1809 | } | 1810 | } |
| 1810 | // requires 'chudInitialize()' | 1811 | // requires 'chudInitialize()' |
| 1811 | utilBindThreadToCPU(0); // # of CPU to run on (we cannot limit to 2..N CPUs?) | 1812 | utilBindThreadToCPU(0); // # of CPU to run on (we cannot limit to 2..N CPUs?) |
| 1813 | return 0; | ||
| 1812 | #else | 1814 | #else |
| 1813 | return luaL_error( L, "Not available: compile with _UTILBINDTHREADTOCPU"); | 1815 | return luaL_error( L, "Not available: compile with _UTILBINDTHREADTOCPU"); |
| 1814 | #endif | 1816 | #endif |
| 1815 | #else | 1817 | #else |
| 1816 | return luaL_error( L, "not implemented"); | 1818 | return luaL_error( L, "not implemented"); |
| 1817 | #endif | 1819 | #endif |
| 1818 | |||
| 1819 | return 0; | ||
| 1820 | } | 1820 | } |
| 1821 | 1821 | ||
| 1822 | 1822 | ||
| @@ -2204,7 +2204,6 @@ LUAG_FUNC( require) | |||
| 2204 | LUAG_FUNC( register) | 2204 | LUAG_FUNC( register) |
| 2205 | { | 2205 | { |
| 2206 | char const* name = luaL_checkstring( L, 1); | 2206 | char const* name = luaL_checkstring( L, 1); |
| 2207 | int const nargs = lua_gettop( L); | ||
| 2208 | int const mod_type = lua_type( L, 2); | 2207 | int const mod_type = lua_type( L, 2); |
| 2209 | // ignore extra parameters, just in case | 2208 | // ignore extra parameters, just in case |
| 2210 | lua_settop( L, 2); | 2209 | lua_settop( L, 2); |
| @@ -3179,7 +3178,7 @@ LUAG_FUNC( configure) | |||
| 3179 | STACK_MID( L, 0); | 3178 | STACK_MID( L, 0); |
| 3180 | 3179 | ||
| 3181 | // Serialize calls to 'require' from now on, also in the primary state | 3180 | // Serialize calls to 'require' from now on, also in the primary state |
| 3182 | serialize_require( U, L); | 3181 | serialize_require( DEBUGSPEW_PARAM_COMMA( U) L); |
| 3183 | 3182 | ||
| 3184 | // Retrieve main module interface table | 3183 | // Retrieve main module interface table |
| 3185 | lua_pushvalue( L, lua_upvalueindex( 2)); // settings M | 3184 | 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; | |||
| 36 | #define INDENT_BEGIN "%.*s " | 36 | #define INDENT_BEGIN "%.*s " |
| 37 | #define INDENT_END , (U ? U->debugspew_indent_depth : 0), debugspew_indent | 37 | #define INDENT_END , (U ? U->debugspew_indent_depth : 0), debugspew_indent |
| 38 | #define DEBUGSPEW_CODE(_code) _code | 38 | #define DEBUGSPEW_CODE(_code) _code |
| 39 | #define DEBUGSPEW_PARAM_COMMA( param_) param_, | ||
| 40 | #define DEBUGSPEW_COMMA_PARAM( param_) , param_ | ||
| 39 | #else // USE_DEBUG_SPEW | 41 | #else // USE_DEBUG_SPEW |
| 40 | #define DEBUGSPEW_CODE(_code) | 42 | #define DEBUGSPEW_CODE(_code) |
| 43 | #define DEBUGSPEW_PARAM_COMMA( param_) | ||
| 44 | #define DEBUGSPEW_COMMA_PARAM( param_) | ||
| 41 | #endif // USE_DEBUG_SPEW | 45 | #endif // USE_DEBUG_SPEW |
| 42 | 46 | ||
| 43 | #ifdef NDEBUG | 47 | #ifdef NDEBUG |
| @@ -56,10 +60,10 @@ extern char const* debugspew_indent; | |||
| 56 | #define STACK_MID(L,change) \ | 60 | #define STACK_MID(L,change) \ |
| 57 | do \ | 61 | do \ |
| 58 | { \ | 62 | { \ |
| 59 | int a = lua_gettop( L) - _oldtop_##L; \ | 63 | int stack_check_a = lua_gettop( L) - _oldtop_##L; \ |
| 60 | int b = (change); \ | 64 | int stack_check_b = (change); \ |
| 61 | if( a != b) \ | 65 | if( stack_check_a != stack_check_b) \ |
| 62 | luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", a, b, __FILE__, __LINE__ ); \ | 66 | luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", stack_check_a, stack_check_b, __FILE__, __LINE__ ); \ |
| 63 | } while( 0) | 67 | } while( 0) |
| 64 | #define STACK_END(L,change) STACK_MID(L,change); } | 68 | #define STACK_END(L,change) STACK_MID(L,change); } |
| 65 | 69 | ||
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[] = | |||
| 199 | { NULL, NULL } | 199 | { NULL, NULL } |
| 200 | }; | 200 | }; |
| 201 | 201 | ||
| 202 | static void open1lib( Universe* U, lua_State* L, char const* name_, size_t len_, lua_State* from_) | 202 | static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) |
| 203 | { | 203 | { |
| 204 | int i; | 204 | int i; |
| 205 | for( i = 0; libs[i].name; ++ i) | 205 | for( i = 0; libs[i].name; ++ i) |
| @@ -679,7 +679,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
| 679 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening ALL standard libraries\n" INDENT_END)); | 679 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening ALL standard libraries\n" INDENT_END)); |
| 680 | luaL_openlibs( L); | 680 | luaL_openlibs( L); |
| 681 | // don't forget lanes.core for regular lane states | 681 | // don't forget lanes.core for regular lane states |
| 682 | open1lib( U, L, "lanes.core", 10, from_); | 682 | open1lib( DEBUGSPEW_PARAM_COMMA( U) L, "lanes.core", 10); |
| 683 | libs_ = NULL; // done with libs | 683 | libs_ = NULL; // done with libs |
| 684 | } | 684 | } |
| 685 | else | 685 | else |
| @@ -713,12 +713,12 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
| 713 | while( isalnum( p[len]) || p[len] == '.') | 713 | while( isalnum( p[len]) || p[len] == '.') |
| 714 | ++ len; | 714 | ++ len; |
| 715 | // open library | 715 | // open library |
| 716 | open1lib( U, L, p, len, from_); | 716 | open1lib( DEBUGSPEW_PARAM_COMMA( U) L, p, len); |
| 717 | } | 717 | } |
| 718 | } | 718 | } |
| 719 | lua_gc( L, LUA_GCRESTART, 0); | 719 | lua_gc( L, LUA_GCRESTART, 0); |
| 720 | 720 | ||
| 721 | serialize_require( U, L); | 721 | serialize_require( DEBUGSPEW_PARAM_COMMA( U) L); |
| 722 | 722 | ||
| 723 | // call this after the base libraries are loaded and GC is restarted | 723 | // call this after the base libraries are loaded and GC is restarted |
| 724 | // will raise an error in from_ in case of problem | 724 | // 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_ | |||
| 1353 | // "Otherwise, it pushes an error message" | 1353 | // "Otherwise, it pushes an error message" |
| 1354 | // | 1354 | // |
| 1355 | STACK_GROW( L, 1); | 1355 | STACK_GROW( L, 1); |
| 1356 | luaL_error( L, "%s", lua_tostring( L2, -1)); | 1356 | luaL_error( L, "%s: %s", upName_, lua_tostring( L2, -1)); |
| 1357 | } | 1357 | } |
| 1358 | // remove the dumped string | 1358 | // remove the dumped string |
| 1359 | lua_pop( L, 1); // ... | 1359 | lua_pop( L, 1); // ... |
| @@ -1567,6 +1567,12 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache | |||
| 1567 | valPath = (char*) alloca( strlen( upName_) + 32 + 3); | 1567 | valPath = (char*) alloca( strlen( upName_) + 32 + 3); |
| 1568 | sprintf( valPath, "%s[" LUA_NUMBER_FMT "]", upName_, key); | 1568 | sprintf( valPath, "%s[" LUA_NUMBER_FMT "]", upName_, key); |
| 1569 | } | 1569 | } |
| 1570 | else if( lua_type( L, key_i) == LUA_TLIGHTUSERDATA) | ||
| 1571 | { | ||
| 1572 | void* key = lua_touserdata( L, key_i); | ||
| 1573 | valPath = (char*) alloca( strlen( upName_) + 16 + 5); | ||
| 1574 | sprintf( valPath, "%s[U:%p]", upName_, key); | ||
| 1575 | } | ||
| 1570 | } | 1576 | } |
| 1571 | /* | 1577 | /* |
| 1572 | * Contents of metatables are copied with cache checking; | 1578 | * 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 | |||
| 1597 | 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_) | 1603 | 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_) |
| 1598 | { | 1604 | { |
| 1599 | bool_t ret = TRUE; | 1605 | bool_t ret = TRUE; |
| 1600 | bool_t ignore = FALSE; | ||
| 1601 | int val_type = lua_type( L, i); | 1606 | int val_type = lua_type( L, i); |
| 1602 | STACK_GROW( L2, 1); | 1607 | STACK_GROW( L2, 1); |
| 1603 | STACK_CHECK( L); // L // L2 | 1608 | 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 | |||
| 1671 | } | 1676 | } |
| 1672 | STACK_MID( L, 0); | 1677 | STACK_MID( L, 0); |
| 1673 | 1678 | ||
| 1674 | if( lua_getmetatable( L, i)) // ... mt? | 1679 | if( lua_getmetatable( L, i)) // ... mt? |
| 1680 | { | ||
| 1681 | lua_getfield( L, -1, "__lanesclone"); // ... mt __lanesclone? | ||
| 1682 | if( lua_isnil( L, -1)) | ||
| 1675 | { | 1683 | { |
| 1676 | lua_getfield( L, -1, "__lanesclone"); // ... mt __lanesclone? | 1684 | lua_pop( L, 2); // ... |
| 1677 | if( lua_isnil( L, -1)) | 1685 | } |
| 1678 | { | 1686 | else |
| 1679 | lua_pop( L, 2); // ... | 1687 | { |
| 1680 | } | 1688 | size_t userdata_size = 0; |
| 1681 | else | 1689 | void* const source = lua_touserdata( L, i); |
| 1690 | void* clone = NULL; | ||
| 1691 | lua_pushvalue( L, -1); // ... mt __lanesclone __lanesclone | ||
| 1692 | // call the cloning function with 0 arguments, should return the number of bytes to allocate for the clone | ||
| 1693 | lua_call( L, 0, 1); // ... mt __lanesclone size | ||
| 1694 | STACK_MID( L, 3); | ||
| 1695 | userdata_size = (size_t) lua_tointeger( L, -1); // ... mt __lanesclone size | ||
| 1696 | lua_pop( L, 1); // ... mt __lanesclone | ||
| 1697 | clone = lua_newuserdata( L2, userdata_size); // ... u | ||
| 1698 | // call cloning function in source state to perform the actual memory cloning | ||
| 1699 | lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone | ||
| 1700 | lua_pushlightuserdata( L, source); // ... mt __lanesclone source | ||
| 1701 | lua_call( L, 2, 0); // ... mt | ||
| 1702 | STACK_MID( L, 1); | ||
| 1703 | // copy the metatable in the target state | ||
| 1704 | if( inter_copy_one_( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_)) // ... u mt? | ||
| 1682 | { | 1705 | { |
| 1683 | FuncSubType fst; | 1706 | lua_pop( L, 1); // ... |
| 1684 | lua_CFunction cloneFunc = luaG_tocfunction( L, -1, &fst); | 1707 | STACK_MID( L, 0); |
| 1685 | size_t userdata_size = 0; | 1708 | // when writing to a keeper state, we have here a sentinel function with the metatable's fqn as upvalue |
| 1686 | void* const source = lua_touserdata( L, i); | 1709 | if( eLM_ToKeeper == mode_) // ... u sentinel |
| 1687 | void* clone = NULL; | ||
| 1688 | lua_pushvalue( L, -1); // ... mt __lanesclone __lanesclone | ||
| 1689 | // call the cloning function with 0 arguments, should return the number of bytes to allocate for the clone | ||
| 1690 | lua_call( L, 0, 1); // ... mt __lanesclone size | ||
| 1691 | STACK_MID( L, 3); | ||
| 1692 | userdata_size = (size_t) lua_tointeger( L, -1); // ... mt __lanesclone size | ||
| 1693 | lua_pop( L, 1); // ... mt __lanesclone | ||
| 1694 | clone = lua_newuserdata( L2, userdata_size); // ... u | ||
| 1695 | // call cloning function in source state to perform the actual memory cloning | ||
| 1696 | lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone | ||
| 1697 | lua_pushlightuserdata( L, source); // ... mt __lanesclone source | ||
| 1698 | lua_call( L, 2, 0); // ... mt | ||
| 1699 | STACK_MID( L, 1); | ||
| 1700 | // copy the metatable in the target state | ||
| 1701 | if( inter_copy_one_( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_)) // ... u mt? | ||
| 1702 | { | 1710 | { |
| 1703 | lua_pop( L, 1); // ... | 1711 | ASSERT_L( lua_tocfunction( L2, -1) == table_lookup_sentinel); |
| 1704 | STACK_MID( L, 0); | 1712 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn |
| 1705 | // when writing to a keeper state, we have here a sentinel function with the metatable's fqn as upvalue | 1713 | lua_getupvalue( L2, -1, 1); // ... u sentinel fqn |
| 1706 | if( eLM_ToKeeper == mode_) // ... u sentinel | 1714 | lua_remove( L2, -2); // ... u fqn |
| 1707 | { | 1715 | lua_insert( L2, -2); // ... fqn u |
| 1708 | ASSERT_L( lua_tocfunction( L2, -1) == table_lookup_sentinel); | 1716 | lua_pushcclosure( L2, userdata_clone_sentinel, 2); // ... userdata_clone_sentinel |
| 1709 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn | ||
| 1710 | lua_getupvalue( L2, -1, 1); // ... u sentinel fqn | ||
| 1711 | lua_remove( L2, -2); // ... u fqn | ||
| 1712 | lua_insert( L2, -2); // ... fqn u | ||
| 1713 | lua_pushcclosure( L2, userdata_clone_sentinel, 2); // ... userdata_clone_sentinel | ||
| 1714 | } | ||
| 1715 | else // from keeper or direct, we have the userdata and the metatable | ||
| 1716 | { | ||
| 1717 | ASSERT_L( lua_istable( L2, -1)); | ||
| 1718 | lua_setmetatable( L2, -2); // ... u | ||
| 1719 | } | ||
| 1720 | } | 1717 | } |
| 1721 | else | 1718 | else // from keeper or direct, we have the userdata and the metatable |
| 1722 | { | 1719 | { |
| 1723 | (void) luaL_error( L, "Error copying a metatable"); | 1720 | ASSERT_L( lua_istable( L2, -1)); |
| 1721 | lua_setmetatable( L2, -2); // ... u | ||
| 1724 | } | 1722 | } |
| 1725 | } | 1723 | } |
| 1726 | break; | 1724 | else |
| 1725 | { | ||
| 1726 | (void) luaL_error( L, "Error copying a metatable"); | ||
| 1727 | } | ||
| 1727 | } | 1728 | } |
| 1729 | break; | ||
| 1730 | } | ||
| 1728 | 1731 | ||
| 1729 | // Not a deep or clonable full userdata | 1732 | // Not a deep or clonable full userdata |
| 1730 | if( U->demoteFullUserdata) // attempt demotion to light userdata | 1733 | if( U->demoteFullUserdata) // attempt demotion to light userdata |
| 1731 | { | 1734 | { |
| 1732 | void* lud = lua_touserdata( L, i); | 1735 | void* lud = lua_touserdata( L, i); |
| 1733 | lua_pushlightuserdata( L2, lud); | 1736 | lua_pushlightuserdata( L2, lud); |
| 1734 | } | 1737 | } |
| 1735 | else // raise an error | 1738 | else // raise an error |
| 1736 | { | 1739 | { |
| 1737 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); | 1740 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); |
| 1738 | } | 1741 | } |
| 1739 | break; | 1742 | break; |
| 1740 | 1743 | ||
| 1741 | case LUA_TNIL: | 1744 | case LUA_TNIL: |
| @@ -2035,7 +2038,7 @@ int luaG_new_require( lua_State* L) | |||
| 2035 | /* | 2038 | /* |
| 2036 | * Serialize calls to 'require', if it exists | 2039 | * Serialize calls to 'require', if it exists |
| 2037 | */ | 2040 | */ |
| 2038 | void serialize_require( Universe* U, lua_State* L) | 2041 | void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L) |
| 2039 | { | 2042 | { |
| 2040 | STACK_GROW( L, 1); | 2043 | STACK_GROW( L, 1); |
| 2041 | STACK_CHECK( L); | 2044 | 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); | |||
| 33 | int luaG_new_require( lua_State* L); | 33 | int luaG_new_require( lua_State* L); |
| 34 | 34 | ||
| 35 | void populate_func_lookup_table( lua_State* L, int _i, char const* _name); | 35 | void populate_func_lookup_table( lua_State* L, int _i, char const* _name); |
| 36 | void serialize_require( Universe* U, lua_State *L); | 36 | void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State *L); |
| 37 | void initialize_on_state_create( Universe* U, lua_State* L); | 37 | void initialize_on_state_create( Universe* U, lua_State* L); |
| 38 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); | 38 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); |
| 39 | 39 | ||
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; | |||
| 13 | #if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) // building against LuaJIT headers, light userdata is restricted to 47 significant bits. | 13 | #if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) // building against LuaJIT headers, light userdata is restricted to 47 significant bits. |
| 14 | #define MAKE_UNIQUE_KEY( p_) ((void*)((ptrdiff_t)(p_) & 0x7fffffffffffull)) | 14 | #define MAKE_UNIQUE_KEY( p_) ((void*)((ptrdiff_t)(p_) & 0x7fffffffffffull)) |
| 15 | #else // LUA_JITLIBNAME | 15 | #else // LUA_JITLIBNAME |
| 16 | #define MAKE_UNIQUE_KEY( p_) ((void*) p_) | 16 | #define MAKE_UNIQUE_KEY( p_) ((void*)(ptrdiff_t)(p_)) |
| 17 | #endif // LUA_JITLIBNAME | 17 | #endif // LUA_JITLIBNAME |
| 18 | 18 | ||
| 19 | #define DECLARE_UNIQUE_KEY( name_) UniqueKey name_ | 19 | #define DECLARE_UNIQUE_KEY( name_) UniqueKey name_ |
