diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-20 16:53:14 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-20 16:53:14 +0100 |
commit | df1113151aff47bfd1b401bf8d06a3fe8f6b9115 (patch) | |
tree | e14449dad963d0b441edebf2cf74713d5b9dd665 | |
parent | 6556cc558f0602cc99b1a8d1c7212b2e91490cdc (diff) | |
download | lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.tar.gz lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.tar.bz2 lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.zip |
C++ migration: more NULL → nullptr
-rw-r--r-- | src/cancel.cpp | 2 | ||||
-rw-r--r-- | src/compat.h | 2 | ||||
-rw-r--r-- | src/deep.cpp | 28 | ||||
-rw-r--r-- | src/keeper.cpp | 4 | ||||
-rw-r--r-- | src/lanes.cpp | 23 | ||||
-rw-r--r-- | src/state.cpp | 36 | ||||
-rw-r--r-- | src/threading.cpp | 28 | ||||
-rw-r--r-- | src/threading.h | 2 | ||||
-rw-r--r-- | src/tools.cpp | 56 | ||||
-rw-r--r-- | src/universe.cpp | 2 | ||||
-rw-r--r-- | src/universe.h | 2 |
11 files changed, 95 insertions, 90 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 0f22550..81f25d5 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -56,7 +56,7 @@ THE SOFTWARE. | |||
56 | static inline enum e_cancel_request cancel_test( lua_State* L) | 56 | static inline enum e_cancel_request cancel_test( lua_State* L) |
57 | { | 57 | { |
58 | Lane* const s = get_lane_from_registry( L); | 58 | Lane* const s = get_lane_from_registry( L); |
59 | // 's' is NULL for the original main state (and no-one can cancel that) | 59 | // 's' is nullptr for the original main state (and no-one can cancel that) |
60 | return s ? s->cancel_request : CANCEL_NONE; | 60 | return s ? s->cancel_request : CANCEL_NONE; |
61 | } | 61 | } |
62 | 62 | ||
diff --git a/src/compat.h b/src/compat.h index ed56cc6..46c31cf 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -36,7 +36,7 @@ extern "C" { | |||
36 | #define lua_setuservalue lua_setfenv | 36 | #define lua_setuservalue lua_setfenv |
37 | #define lua_getuservalue lua_getfenv | 37 | #define lua_getuservalue lua_getfenv |
38 | #define lua_rawlen lua_objlen | 38 | #define lua_rawlen lua_objlen |
39 | #define luaG_registerlibfuncs( L, _funcs) luaL_register( L, NULL, _funcs) | 39 | #define luaG_registerlibfuncs(L, _funcs) luaL_register(L, nullptr, _funcs) |
40 | #define LUA_OK 0 | 40 | #define LUA_OK 0 |
41 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value | 41 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value |
42 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources | 42 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources |
diff --git a/src/deep.cpp b/src/deep.cpp index c0aa25b..ee08cdd 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -106,7 +106,7 @@ static void get_deep_lookup( lua_State* L) | |||
106 | 106 | ||
107 | /* | 107 | /* |
108 | * Return the registered ID function for 'index' (deep userdata proxy), | 108 | * Return the registered ID function for 'index' (deep userdata proxy), |
109 | * or NULL if 'index' is not a deep userdata proxy. | 109 | * or nullptr if 'index' is not a deep userdata proxy. |
110 | */ | 110 | */ |
111 | static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mode_) | 111 | static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mode_) |
112 | { | 112 | { |
@@ -128,13 +128,13 @@ static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mo | |||
128 | 128 | ||
129 | if( !lua_getmetatable( L, index)) // deep ... metatable? | 129 | if( !lua_getmetatable( L, index)) // deep ... metatable? |
130 | { | 130 | { |
131 | return NULL; // no metatable: can't be a deep userdata object! | 131 | return nullptr; // no metatable: can't be a deep userdata object! |
132 | } | 132 | } |
133 | 133 | ||
134 | // replace metatable with the idfunc pointer, if it is actually a deep userdata | 134 | // replace metatable with the idfunc pointer, if it is actually a deep userdata |
135 | get_deep_lookup( L); // deep ... idfunc|nil | 135 | get_deep_lookup( L); // deep ... idfunc|nil |
136 | 136 | ||
137 | ret = (luaG_IdFunction) lua_touserdata( L, -1); // NULL if not a userdata | 137 | ret = (luaG_IdFunction) lua_touserdata( L, -1); // nullptr if not a userdata |
138 | lua_pop( L, 1); | 138 | lua_pop( L, 1); |
139 | STACK_END( L, 0); | 139 | STACK_END( L, 0); |
140 | return ret; | 140 | return ret; |
@@ -189,14 +189,14 @@ static int deep_userdata_gc( lua_State* L) | |||
189 | luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); | 189 | luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | *proxy = NULL; // make sure we don't use it any more, just in case | 192 | *proxy = nullptr; // make sure we don't use it any more, just in case |
193 | return 0; | 193 | return 0; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | /* | 197 | /* |
198 | * Push a proxy userdata on the stack. | 198 | * Push a proxy userdata on the stack. |
199 | * returns NULL if ok, else some error string related to bad idfunc behavior or module require problem | 199 | * returns nullptr if ok, else some error string related to bad idfunc behavior or module require problem |
200 | * (error cannot happen with mode_ == eLM_ToKeeper) | 200 | * (error cannot happen with mode_ == eLM_ToKeeper) |
201 | * | 201 | * |
202 | * Initializes necessary structures if it's the first time 'idfunc' is being | 202 | * Initializes necessary structures if it's the first time 'idfunc' is being |
@@ -214,7 +214,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
214 | if ( !lua_isnil( L, -1)) | 214 | if ( !lua_isnil( L, -1)) |
215 | { | 215 | { |
216 | lua_remove( L, -2); // proxy | 216 | lua_remove( L, -2); // proxy |
217 | return NULL; | 217 | return nullptr; |
218 | } | 218 | } |
219 | else | 219 | else |
220 | { | 220 | { |
@@ -293,7 +293,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
293 | return "Bad idfunc(eOP_module): should not push anything"; | 293 | return "Bad idfunc(eOP_module): should not push anything"; |
294 | } | 294 | } |
295 | } | 295 | } |
296 | if( NULL != modname) // we actually got a module name | 296 | if (nullptr != modname) // we actually got a module name |
297 | { | 297 | { |
298 | // L.registry._LOADED exists without having registered the 'package' library. | 298 | // L.registry._LOADED exists without having registered the 'package' library. |
299 | lua_getglobal( L, "require"); // DPC proxy metatable require() | 299 | lua_getglobal( L, "require"); // DPC proxy metatable require() |
@@ -352,7 +352,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
352 | lua_remove( L, -2); // proxy | 352 | lua_remove( L, -2); // proxy |
353 | ASSERT_L( lua_isuserdata( L, -1)); | 353 | ASSERT_L( lua_isuserdata( L, -1)); |
354 | STACK_END( L, 0); | 354 | STACK_END( L, 0); |
355 | return NULL; | 355 | return nullptr; |
356 | } | 356 | } |
357 | 357 | ||
358 | /* | 358 | /* |
@@ -386,7 +386,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) | |||
386 | { | 386 | { |
387 | int const oldtop = lua_gettop( L); | 387 | int const oldtop = lua_gettop( L); |
388 | DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); | 388 | DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); |
389 | if( prelude == NULL) | 389 | if (prelude == nullptr) |
390 | { | 390 | { |
391 | return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); | 391 | return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); |
392 | } | 392 | } |
@@ -408,7 +408,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) | |||
408 | return luaL_error( L, "Bad idfunc(eDO_new): should not push anything on the stack"); | 408 | return luaL_error( L, "Bad idfunc(eDO_new): should not push anything on the stack"); |
409 | } | 409 | } |
410 | errmsg = push_deep_proxy( universe_get( L), L, prelude, nuv_, eLM_LaneBody); // proxy | 410 | errmsg = push_deep_proxy( universe_get( L), L, prelude, nuv_, eLM_LaneBody); // proxy |
411 | if( errmsg != NULL) | 411 | if (errmsg != nullptr) |
412 | { | 412 | { |
413 | return luaL_error( L, errmsg); | 413 | return luaL_error( L, errmsg); |
414 | } | 414 | } |
@@ -432,7 +432,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | |||
432 | // ensure it is actually a deep userdata | 432 | // ensure it is actually a deep userdata |
433 | if( get_idfunc( L, index, eLM_LaneBody) != idfunc) | 433 | if( get_idfunc( L, index, eLM_LaneBody) != idfunc) |
434 | { | 434 | { |
435 | return NULL; // no metatable, or wrong kind | 435 | return nullptr; // no metatable, or wrong kind |
436 | } | 436 | } |
437 | 437 | ||
438 | proxy = (DeepPrelude**) lua_touserdata( L, index); | 438 | proxy = (DeepPrelude**) lua_touserdata( L, index); |
@@ -446,7 +446,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | |||
446 | * Copy deep userdata between two separate Lua states (from L to L2) | 446 | * Copy deep userdata between two separate Lua states (from L to L2) |
447 | * | 447 | * |
448 | * Returns: | 448 | * Returns: |
449 | * the id function of the copied value, or NULL for non-deep userdata | 449 | * the id function of the copied value, or nullptr for non-deep userdata |
450 | * (not copied) | 450 | * (not copied) |
451 | */ | 451 | */ |
452 | bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) | 452 | bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) |
@@ -455,7 +455,7 @@ bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint | |||
455 | luaG_IdFunction idfunc = get_idfunc( L, i, mode_); | 455 | luaG_IdFunction idfunc = get_idfunc( L, i, mode_); |
456 | int nuv = 0; | 456 | int nuv = 0; |
457 | 457 | ||
458 | if( idfunc == NULL) | 458 | if (idfunc == nullptr) |
459 | { | 459 | { |
460 | return false; // not a deep userdata | 460 | return false; // not a deep userdata |
461 | } | 461 | } |
@@ -490,7 +490,7 @@ bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint | |||
490 | STACK_END( L2, 1); | 490 | STACK_END( L2, 1); |
491 | STACK_END( L, 0); | 491 | STACK_END( L, 0); |
492 | 492 | ||
493 | if( errmsg != NULL) | 493 | if (errmsg != nullptr) |
494 | { | 494 | { |
495 | // raise the error in the proper state (not the keeper) | 495 | // raise the error in the proper state (not the keeper) |
496 | lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; | 496 | lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 697fe71..17f5df2 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -412,7 +412,7 @@ int keepercall_set( lua_State* L) | |||
412 | lua_rawget( L, 1); // fifos key fifo|nil | 412 | lua_rawget( L, 1); // fifos key fifo|nil |
413 | // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! | 413 | // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! |
414 | fifo = (keeper_fifo*) lua_touserdata( L, -1); | 414 | fifo = (keeper_fifo*) lua_touserdata( L, -1); |
415 | if( fifo != nullptr) // might be NULL if we set a nonexistent key to nil | 415 | if( fifo != nullptr) // might be nullptr if we set a nonexistent key to nil |
416 | { // fifos key fifo | 416 | { // fifos key fifo |
417 | if( fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it | 417 | if( fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it |
418 | { | 418 | { |
@@ -621,7 +621,7 @@ void close_keepers( Universe* U) | |||
621 | /* | 621 | /* |
622 | * Initialize keeper states | 622 | * Initialize keeper states |
623 | * | 623 | * |
624 | * If there is a problem, returns NULL and pushes the error message on the stack | 624 | * If there is a problem, returns nullptr and pushes the error message on the stack |
625 | * else returns the keepers bookkeeping structure. | 625 | * else returns the keepers bookkeeping structure. |
626 | * | 626 | * |
627 | * Note: Any problems would be design flaws; the created Lua state is left | 627 | * Note: Any problems would be design flaws; the created Lua state is left |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 126f65c..246e772 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -1559,11 +1559,12 @@ LUAG_FUNC( thread_index) | |||
1559 | break; | 1559 | break; |
1560 | } | 1560 | } |
1561 | // fall through if we are killed, as we got nil, "killed" on the stack | 1561 | // fall through if we are killed, as we got nil, "killed" on the stack |
1562 | [[fallthrough]]; | ||
1562 | 1563 | ||
1563 | case DONE: // got regular return values | 1564 | case DONE: // got regular return values |
1564 | { | 1565 | { |
1565 | int i, nvalues = lua_gettop( L) - 3; | 1566 | int const nvalues{ lua_gettop(L) - 3 }; |
1566 | for( i = nvalues; i > 0; -- i) | 1567 | for( int i = nvalues; i > 0; -- i) |
1567 | { | 1568 | { |
1568 | // pop the last element of the stack, to store it in the uservalue at its proper index | 1569 | // pop the last element of the stack, to store it in the uservalue at its proper index |
1569 | lua_rawseti( L, USR, i); | 1570 | lua_rawseti( L, USR, i); |
@@ -2049,16 +2050,20 @@ static void EnableCrashingOnCrashes( void) | |||
2049 | const DWORD EXCEPTION_SWALLOWING = 0x1; | 2050 | const DWORD EXCEPTION_SWALLOWING = 0x1; |
2050 | 2051 | ||
2051 | HMODULE kernel32 = LoadLibraryA("kernel32.dll"); | 2052 | HMODULE kernel32 = LoadLibraryA("kernel32.dll"); |
2052 | tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); | 2053 | if (kernel32) |
2053 | tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); | ||
2054 | if( pGetPolicy && pSetPolicy) | ||
2055 | { | 2054 | { |
2056 | DWORD dwFlags; | 2055 | tGetPolicy pGetPolicy = (tGetPolicy) GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); |
2057 | if( pGetPolicy( &dwFlags)) | 2056 | tSetPolicy pSetPolicy = (tSetPolicy) GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); |
2057 | if (pGetPolicy && pSetPolicy) | ||
2058 | { | 2058 | { |
2059 | // Turn off the filter | 2059 | DWORD dwFlags; |
2060 | pSetPolicy( dwFlags & ~EXCEPTION_SWALLOWING); | 2060 | if (pGetPolicy(&dwFlags)) |
2061 | { | ||
2062 | // Turn off the filter | ||
2063 | pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING); | ||
2064 | } | ||
2061 | } | 2065 | } |
2066 | FreeLibrary(kernel32); | ||
2062 | } | 2067 | } |
2063 | //typedef void (* SignalHandlerPointer)( int); | 2068 | //typedef void (* SignalHandlerPointer)( int); |
2064 | /*SignalHandlerPointer previousHandler =*/ signal( SIGABRT, signal_handler); | 2069 | /*SignalHandlerPointer previousHandler =*/ signal( SIGABRT, signal_handler); |
diff --git a/src/state.cpp b/src/state.cpp index 2213297..688ac2a 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -146,7 +146,7 @@ static const luaL_Reg libs[] = | |||
146 | #endif | 146 | #endif |
147 | { LUA_COLIBNAME, luaopen_coroutine}, // Lua 5.2: coroutine is no longer a part of base! | 147 | { LUA_COLIBNAME, luaopen_coroutine}, // Lua 5.2: coroutine is no longer a part of base! |
148 | #else // LUA_VERSION_NUM | 148 | #else // LUA_VERSION_NUM |
149 | { LUA_COLIBNAME, NULL}, // Lua 5.1: part of base package | 149 | { LUA_COLIBNAME, nullptr }, // Lua 5.1: part of base package |
150 | #endif // LUA_VERSION_NUM | 150 | #endif // LUA_VERSION_NUM |
151 | { LUA_DBLIBNAME, luaopen_debug}, | 151 | { LUA_DBLIBNAME, luaopen_debug}, |
152 | #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, add some LuaJIT-specific libs | 152 | #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, add some LuaJIT-specific libs |
@@ -156,11 +156,11 @@ static const luaL_Reg libs[] = | |||
156 | { LUA_FFILIBNAME, luaopen_ffi}, | 156 | { LUA_FFILIBNAME, luaopen_ffi}, |
157 | #endif // LUAJIT_FLAVOR() | 157 | #endif // LUAJIT_FLAVOR() |
158 | 158 | ||
159 | { LUA_DBLIBNAME, luaopen_debug}, | 159 | { LUA_DBLIBNAME, luaopen_debug}, |
160 | { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) | 160 | { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) |
161 | // | 161 | // |
162 | { "base", NULL}, // ignore "base" (already acquired it) | 162 | { "base", nullptr }, // ignore "base" (already acquired it) |
163 | { NULL, NULL } | 163 | { nullptr, nullptr } |
164 | }; | 164 | }; |
165 | 165 | ||
166 | static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) | 166 | static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) |
@@ -172,7 +172,7 @@ static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char con | |||
172 | { | 172 | { |
173 | lua_CFunction libfunc = libs[i].func; | 173 | lua_CFunction libfunc = libs[i].func; |
174 | name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ | 174 | name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ |
175 | if( libfunc != NULL) | 175 | if (libfunc != nullptr) |
176 | { | 176 | { |
177 | bool const isLanesCore{ libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" | 177 | bool const isLanesCore{ libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" |
178 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); | 178 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); |
@@ -224,11 +224,11 @@ void initialize_on_state_create( Universe* U, lua_State* L) | |||
224 | { | 224 | { |
225 | // store C function pointer in an internal variable | 225 | // store C function pointer in an internal variable |
226 | U->on_state_create_func = lua_tocfunction( L, -1); // settings on_state_create | 226 | U->on_state_create_func = lua_tocfunction( L, -1); // settings on_state_create |
227 | if( U->on_state_create_func != NULL) | 227 | if (U->on_state_create_func != nullptr) |
228 | { | 228 | { |
229 | // make sure the function doesn't have upvalues | 229 | // make sure the function doesn't have upvalues |
230 | char const* upname = lua_getupvalue( L, -1, 1); // settings on_state_create upval? | 230 | char const* upname = lua_getupvalue( L, -1, 1); // settings on_state_create upval? |
231 | if( upname != NULL) // should be "" for C functions with upvalues if any | 231 | if (upname != nullptr) // should be "" for C functions with upvalues if any |
232 | { | 232 | { |
233 | (void) luaL_error( L, "on_state_create shouldn't have upvalues"); | 233 | (void) luaL_error( L, "on_state_create shouldn't have upvalues"); |
234 | } | 234 | } |
@@ -254,7 +254,7 @@ lua_State* create_state( Universe* U, lua_State* from_) | |||
254 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... | 254 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... |
255 | L = luaL_newstate(); | 255 | L = luaL_newstate(); |
256 | #else // LUAJIT_FLAVOR() == 64 | 256 | #else // LUAJIT_FLAVOR() == 64 |
257 | if( U->provide_allocator != NULL) // we have a function we can call to obtain an allocator | 257 | if (U->provide_allocator != nullptr) // we have a function we can call to obtain an allocator |
258 | { | 258 | { |
259 | lua_pushcclosure( from_, U->provide_allocator, 0); | 259 | lua_pushcclosure( from_, U->provide_allocator, 0); |
260 | lua_call( from_, 0, 1); | 260 | lua_call( from_, 0, 1); |
@@ -271,7 +271,7 @@ lua_State* create_state( Universe* U, lua_State* from_) | |||
271 | } | 271 | } |
272 | #endif // LUAJIT_FLAVOR() == 64 | 272 | #endif // LUAJIT_FLAVOR() == 64 |
273 | 273 | ||
274 | if( L == NULL) | 274 | if (L == nullptr) |
275 | { | 275 | { |
276 | (void) luaL_error( from_, "luaG_newstate() failed while creating state; out of memory"); | 276 | (void) luaL_error( from_, "luaG_newstate() failed while creating state; out of memory"); |
277 | } | 277 | } |
@@ -280,7 +280,7 @@ lua_State* create_state( Universe* U, lua_State* from_) | |||
280 | 280 | ||
281 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) | 281 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) |
282 | { | 282 | { |
283 | if( U->on_state_create_func != NULL) | 283 | if (U->on_state_create_func != nullptr) |
284 | { | 284 | { |
285 | STACK_CHECK( L, 0); | 285 | STACK_CHECK( L, 0); |
286 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END)); | 286 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END)); |
@@ -315,12 +315,12 @@ void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMo | |||
315 | /* | 315 | /* |
316 | * Like 'luaL_openlibs()' but allows the set of libraries be selected | 316 | * Like 'luaL_openlibs()' but allows the set of libraries be selected |
317 | * | 317 | * |
318 | * NULL no libraries, not even base | 318 | * nullptr no libraries, not even base |
319 | * "" base library only | 319 | * "" base library only |
320 | * "io,string" named libraries | 320 | * "io,string" named libraries |
321 | * "*" all libraries | 321 | * "*" all libraries |
322 | * | 322 | * |
323 | * Base ("unpack", "print" etc.) is always added, unless 'libs' is NULL. | 323 | * Base ("unpack", "print" etc.) is always added, unless 'libs' is nullptr. |
324 | * | 324 | * |
325 | * *NOT* called for keeper states! | 325 | * *NOT* called for keeper states! |
326 | * | 326 | * |
@@ -342,9 +342,9 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
342 | STACK_MID( L, 0); | 342 | STACK_MID( L, 0); |
343 | 343 | ||
344 | // neither libs (not even 'base') nor special init func: we are done | 344 | // neither libs (not even 'base') nor special init func: we are done |
345 | if( libs_ == NULL && U->on_state_create_func == NULL) | 345 | if (libs_ == nullptr && U->on_state_create_func == nullptr) |
346 | { | 346 | { |
347 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate(NULL)\n" INDENT_END)); | 347 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate(nullptr)\n" INDENT_END)); |
348 | return L; | 348 | return L; |
349 | } | 349 | } |
350 | 350 | ||
@@ -360,7 +360,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
360 | 360 | ||
361 | // Anything causes 'base' to be taken in | 361 | // Anything causes 'base' to be taken in |
362 | // | 362 | // |
363 | if( libs_ != NULL) | 363 | if (libs_ != nullptr) |
364 | { | 364 | { |
365 | // special "*" case (mainly to help with LuaJIT compatibility) | 365 | // special "*" case (mainly to help with LuaJIT compatibility) |
366 | // as we are called from luaopen_lanes_core() already, and that would deadlock | 366 | // as we are called from luaopen_lanes_core() already, and that would deadlock |
@@ -370,7 +370,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
370 | luaL_openlibs( L); | 370 | luaL_openlibs( L); |
371 | // don't forget lanes.core for regular lane states | 371 | // don't forget lanes.core for regular lane states |
372 | open1lib( DEBUGSPEW_PARAM_COMMA( U) L, "lanes.core", 10); | 372 | open1lib( DEBUGSPEW_PARAM_COMMA( U) L, "lanes.core", 10); |
373 | libs_ = NULL; // done with libs | 373 | libs_ = nullptr; // done with libs |
374 | } | 374 | } |
375 | else | 375 | else |
376 | { | 376 | { |
@@ -417,7 +417,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) | |||
417 | STACK_CHECK( L, 0); | 417 | STACK_CHECK( L, 0); |
418 | // after all this, register everything we find in our name<->function database | 418 | // after all this, register everything we find in our name<->function database |
419 | lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack | 419 | lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack |
420 | populate_func_lookup_table( L, -1, NULL); | 420 | populate_func_lookup_table(L, -1, nullptr); |
421 | 421 | ||
422 | #if 0 && USE_DEBUG_SPEW() | 422 | #if 0 && USE_DEBUG_SPEW() |
423 | // dump the lookup database contents | 423 | // dump the lookup database contents |
diff --git a/src/threading.cpp b/src/threading.cpp index 4f3cbc8..636fe91 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -107,7 +107,7 @@ static void FAIL( char const* funcname, int rc) | |||
107 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); | 107 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); |
108 | #else // PLATFORM_XBOX | 108 | #else // PLATFORM_XBOX |
109 | char buf[256]; | 109 | char buf[256]; |
110 | FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); | 110 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); |
111 | fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); | 111 | fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); |
112 | #endif // PLATFORM_XBOX | 112 | #endif // PLATFORM_XBOX |
113 | #ifdef _MSC_VER | 113 | #ifdef _MSC_VER |
@@ -188,7 +188,7 @@ time_d now_secs(void) { | |||
188 | // suseconds_t tv_usec; /* and microseconds */ | 188 | // suseconds_t tv_usec; /* and microseconds */ |
189 | // }; | 189 | // }; |
190 | 190 | ||
191 | int rc= gettimeofday( &tv, NULL /*time zone not used any more (in Linux)*/ ); | 191 | int rc = gettimeofday(&tv, nullptr /*time zone not used any more (in Linux)*/); |
192 | assert( rc==0 ); | 192 | assert( rc==0 ); |
193 | 193 | ||
194 | return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; | 194 | return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; |
@@ -310,15 +310,15 @@ MSDN: "you can create at most 2028 threads" | |||
310 | // Note: Visual C++ requires '__stdcall' where it is | 310 | // Note: Visual C++ requires '__stdcall' where it is |
311 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), void* data, int prio /* -3..+3 */) | 311 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), void* data, int prio /* -3..+3 */) |
312 | { | 312 | { |
313 | HANDLE h = (HANDLE) _beginthreadex( NULL, // security | 313 | HANDLE h = (HANDLE) _beginthreadex(nullptr, // security |
314 | _THREAD_STACK_SIZE, | 314 | _THREAD_STACK_SIZE, |
315 | func, | 315 | func, |
316 | data, | 316 | data, |
317 | 0, // flags (0/CREATE_SUSPENDED) | 317 | 0, // flags (0/CREATE_SUSPENDED) |
318 | NULL // thread id (not used) | 318 | nullptr // thread id (not used) |
319 | ); | 319 | ); |
320 | 320 | ||
321 | if( h == NULL) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) | 321 | if (h == nullptr) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) |
322 | { | 322 | { |
323 | FAIL( "CreateThread", GetLastError()); | 323 | FAIL( "CreateThread", GetLastError()); |
324 | } | 324 | } |
@@ -365,7 +365,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
365 | 365 | ||
366 | if (rc == WAIT_TIMEOUT) return false; | 366 | if (rc == WAIT_TIMEOUT) return false; |
367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); | 367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); |
368 | *ref= NULL; // thread no longer usable | 368 | *ref = nullptr; // thread no longer usable |
369 | return true; | 369 | return true; |
370 | } | 370 | } |
371 | // | 371 | // |
@@ -376,7 +376,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
376 | // in theory no-one should call this as it is very dangerous (memory and mutex leaks, no notification of DLLs, etc.) | 376 | // in theory no-one should call this as it is very dangerous (memory and mutex leaks, no notification of DLLs, etc.) |
377 | if (!TerminateThread( *ref, 0 )) FAIL("TerminateThread", GetLastError()); | 377 | if (!TerminateThread( *ref, 0 )) FAIL("TerminateThread", GetLastError()); |
378 | #endif // PLATFORM_XBOX | 378 | #endif // PLATFORM_XBOX |
379 | *ref= NULL; | 379 | *ref = nullptr; |
380 | } | 380 | } |
381 | 381 | ||
382 | void THREAD_MAKE_ASYNCH_CANCELLABLE() {} // nothing to do for windows threads, we can cancel them anytime we want | 382 | void THREAD_MAKE_ASYNCH_CANCELLABLE() {} // nothing to do for windows threads, we can cancel them anytime we want |
@@ -609,7 +609,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
609 | #define PT_CALL( call ) { int rc= call; if (rc!=0) _PT_FAIL( rc, #call, __FILE__, __LINE__ ); } | 609 | #define PT_CALL( call ) { int rc= call; if (rc!=0) _PT_FAIL( rc, #call, __FILE__, __LINE__ ); } |
610 | // | 610 | // |
611 | void SIGNAL_INIT( SIGNAL_T *ref ) { | 611 | void SIGNAL_INIT( SIGNAL_T *ref ) { |
612 | PT_CALL( pthread_cond_init(ref,NULL /*attr*/) ); | 612 | PT_CALL(pthread_cond_init(ref, nullptr /*attr*/)); |
613 | } | 613 | } |
614 | void SIGNAL_FREE( SIGNAL_T *ref ) { | 614 | void SIGNAL_FREE( SIGNAL_T *ref ) { |
615 | PT_CALL( pthread_cond_destroy(ref) ); | 615 | PT_CALL( pthread_cond_destroy(ref) ); |
@@ -903,7 +903,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
903 | int bit = 0; | 903 | int bit = 0; |
904 | #ifdef __NetBSD__ | 904 | #ifdef __NetBSD__ |
905 | cpuset_t *cpuset = cpuset_create(); | 905 | cpuset_t *cpuset = cpuset_create(); |
906 | if( cpuset == NULL) | 906 | if (cpuset == nullptr) |
907 | _PT_FAIL( errno, "cpuset_create", __FILE__, __LINE__-2 ); | 907 | _PT_FAIL( errno, "cpuset_create", __FILE__, __LINE__-2 ); |
908 | #define CPU_SET(b, s) cpuset_set(b, *(s)) | 908 | #define CPU_SET(b, s) cpuset_set(b, *(s)) |
909 | #else | 909 | #else |
@@ -940,7 +940,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
940 | bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) | 940 | bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) |
941 | { | 941 | { |
942 | struct timespec ts_store; | 942 | struct timespec ts_store; |
943 | const struct timespec *timeout= NULL; | 943 | const struct timespec* timeout = nullptr; |
944 | bool done; | 944 | bool done; |
945 | 945 | ||
946 | // Do timeout counting before the locks | 946 | // Do timeout counting before the locks |
@@ -959,10 +959,10 @@ bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu | |||
959 | /* Thread is joinable | 959 | /* Thread is joinable |
960 | */ | 960 | */ |
961 | if (!timeout) { | 961 | if (!timeout) { |
962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); | 962 | PT_CALL(pthread_join(*ref, nullptr /*ignore exit value*/)); |
963 | done = true; | 963 | done = true; |
964 | } else { | 964 | } else { |
965 | int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); | 965 | int rc = PTHREAD_TIMEDJOIN(*ref, nullptr, timeout); |
966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { | 966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { |
967 | _PT_FAIL( rc, "PTHREAD_TIMEDJOIN", __FILE__, __LINE__-2 ); | 967 | _PT_FAIL( rc, "PTHREAD_TIMEDJOIN", __FILE__, __LINE__-2 ); |
968 | } | 968 | } |
@@ -1010,9 +1010,9 @@ bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu | |||
1010 | __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); | 1010 | __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); |
1011 | #else | 1011 | #else |
1012 | // that's the default, but just in case... | 1012 | // that's the default, but just in case... |
1013 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); | 1013 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); |
1014 | // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) | 1014 | // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) |
1015 | pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); | 1015 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); |
1016 | #endif | 1016 | #endif |
1017 | } | 1017 | } |
1018 | 1018 | ||
diff --git a/src/threading.h b/src/threading.h index 24e0998..608f916 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -114,7 +114,7 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; | |||
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | #define MUTEX_T pthread_mutex_t | 116 | #define MUTEX_T pthread_mutex_t |
117 | #define MUTEX_INIT(ref) pthread_mutex_init(ref,NULL) | 117 | #define MUTEX_INIT(ref) pthread_mutex_init(ref, nullptr) |
118 | #define MUTEX_RECURSIVE_INIT(ref) \ | 118 | #define MUTEX_RECURSIVE_INIT(ref) \ |
119 | { pthread_mutexattr_t a; pthread_mutexattr_init( &a ); \ | 119 | { pthread_mutexattr_t a; pthread_mutexattr_init( &a ); \ |
120 | pthread_mutexattr_settype( &a, _MUTEX_RECURSIVE ); \ | 120 | pthread_mutexattr_settype( &a, _MUTEX_RECURSIVE ); \ |
diff --git a/src/tools.cpp b/src/tools.cpp index ac2cf75..8242c82 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -97,7 +97,7 @@ void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode | |||
97 | */ | 97 | */ |
98 | void push_registry_subtable( lua_State* L, UniqueKey key_) | 98 | void push_registry_subtable( lua_State* L, UniqueKey key_) |
99 | { | 99 | { |
100 | push_registry_subtable_mode( L, key_, NULL); | 100 | push_registry_subtable_mode(L, key_, nullptr); |
101 | } | 101 | } |
102 | 102 | ||
103 | // ################################################################################################ | 103 | // ################################################################################################ |
@@ -162,7 +162,7 @@ static void* libc_lua_Alloc(void* ud, void* ptr, size_t osize, size_t nsize) | |||
162 | if (nsize == 0) | 162 | if (nsize == 0) |
163 | { | 163 | { |
164 | free(ptr); | 164 | free(ptr); |
165 | return NULL; | 165 | return nullptr; |
166 | } | 166 | } |
167 | else | 167 | else |
168 | { | 168 | { |
@@ -199,11 +199,11 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
199 | { | 199 | { |
200 | // store C function pointer in an internal variable | 200 | // store C function pointer in an internal variable |
201 | U->provide_allocator = lua_tocfunction( L, -1); // settings allocator | 201 | U->provide_allocator = lua_tocfunction( L, -1); // settings allocator |
202 | if( U->provide_allocator != NULL) | 202 | if (U->provide_allocator != nullptr) |
203 | { | 203 | { |
204 | // make sure the function doesn't have upvalues | 204 | // make sure the function doesn't have upvalues |
205 | char const* upname = lua_getupvalue( L, -1, 1); // settings allocator upval? | 205 | char const* upname = lua_getupvalue( L, -1, 1); // settings allocator upval? |
206 | if( upname != NULL) // should be "" for C functions with upvalues if any | 206 | if (upname != nullptr) // should be "" for C functions with upvalues if any |
207 | { | 207 | { |
208 | (void) luaL_error( L, "config.allocator() shouldn't have upvalues"); | 208 | (void) luaL_error( L, "config.allocator() shouldn't have upvalues"); |
209 | } | 209 | } |
@@ -240,7 +240,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
240 | if (strcmp(allocator, "libc") == 0) | 240 | if (strcmp(allocator, "libc") == 0) |
241 | { | 241 | { |
242 | U->internal_allocator.allocF = libc_lua_Alloc; | 242 | U->internal_allocator.allocF = libc_lua_Alloc; |
243 | U->internal_allocator.allocUD = NULL; | 243 | U->internal_allocator.allocUD = nullptr; |
244 | } | 244 | } |
245 | else | 245 | else |
246 | { | 246 | { |
@@ -254,7 +254,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
254 | void cleanup_allocator_function( Universe* U, lua_State* L) | 254 | void cleanup_allocator_function( Universe* U, lua_State* L) |
255 | { | 255 | { |
256 | // remove the protected allocator, if any | 256 | // remove the protected allocator, if any |
257 | if( U->protected_allocator.definition.allocF != NULL) | 257 | if (U->protected_allocator.definition.allocF != nullptr) |
258 | { | 258 | { |
259 | // install the non-protected allocator | 259 | // install the non-protected allocator |
260 | lua_setallocf( L, U->protected_allocator.definition.allocF, U->protected_allocator.definition.allocUD); | 260 | lua_setallocf( L, U->protected_allocator.definition.allocF, U->protected_allocator.definition.allocUD); |
@@ -281,7 +281,7 @@ static int dummy_writer( lua_State* L, void const* p, size_t sz, void* ud) | |||
281 | * +-----------------+----------+------------+----------+ | 281 | * +-----------------+----------+------------+----------+ |
282 | * | lua_topointer | | | | | 282 | * | lua_topointer | | | | |
283 | * +-----------------+----------+------------+----------+ | 283 | * +-----------------+----------+------------+----------+ |
284 | * | lua_tocfunction | NULL | | NULL | | 284 | * | lua_tocfunction | nullptr | | nullptr | |
285 | * +-----------------+----------+------------+----------+ | 285 | * +-----------------+----------+------------+----------+ |
286 | * | lua_dump | 666 | 1 | 1 | | 286 | * | lua_dump | 666 | 1 | 1 | |
287 | * +-----------------+----------+------------+----------+ | 287 | * +-----------------+----------+------------+----------+ |
@@ -310,7 +310,7 @@ FuncSubType luaG_getfuncsubtype( lua_State *L, int _i) | |||
310 | // the provided writer fails with code 666 | 310 | // the provided writer fails with code 666 |
311 | // therefore, anytime we get 666, this means that lua_dump() attempted a dump | 311 | // therefore, anytime we get 666, this means that lua_dump() attempted a dump |
312 | // all other cases mean this is either a C or LuaJIT-fast function | 312 | // all other cases mean this is either a C or LuaJIT-fast function |
313 | dumpres = lua504_dump( L, dummy_writer, NULL, 0); | 313 | dumpres = lua504_dump(L, dummy_writer, nullptr, 0); |
314 | lua_pop( L, mustpush); | 314 | lua_pop( L, mustpush); |
315 | if( dumpres == 666) | 315 | if( dumpres == 666) |
316 | { | 316 | { |
@@ -380,7 +380,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* | |||
380 | // first, raise an error if the function is already known | 380 | // first, raise an error if the function is already known |
381 | lua_pushvalue( L, -1); // ... {bfc} k o o | 381 | lua_pushvalue( L, -1); // ... {bfc} k o o |
382 | lua_rawget( L, dest); // ... {bfc} k o name? | 382 | lua_rawget( L, dest); // ... {bfc} k o name? |
383 | prevName = lua_tolstring( L, -1, &prevNameLength); // NULL if we got nil (first encounter of this object) | 383 | prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) |
384 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 384 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
385 | lua_pushvalue( L, -3); // ... {bfc} k o name? k | 385 | lua_pushvalue( L, -3); // ... {bfc} k o name? k |
386 | ASSERT_L( lua_type( L, -1) == LUA_TNUMBER || lua_type( L, -1) == LUA_TSTRING); | 386 | ASSERT_L( lua_type( L, -1) == LUA_TNUMBER || lua_type( L, -1) == LUA_TSTRING); |
@@ -397,7 +397,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* | |||
397 | // Also, nothing prevents any external module from exposing a given object under several names, so... | 397 | // Also, nothing prevents any external module from exposing a given object under several names, so... |
398 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the names | 398 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the names |
399 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 399 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
400 | if( prevName != NULL && (prevNameLength < newNameLength || lua_lessthan( L, -2, -1))) | 400 | if (prevName != nullptr && (prevNameLength < newNameLength || lua_lessthan(L, -2, -1))) |
401 | { | 401 | { |
402 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END, lua_typename( L, lua_type( L, -3)), newName, prevName)); | 402 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END, lua_typename( L, lua_type( L, -3)), newName, prevName)); |
403 | // the previous name is 'smaller' than the one we just generated: keep it! | 403 | // the previous name is 'smaller' than the one we just generated: keep it! |
@@ -569,7 +569,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
569 | int const in_base = lua_absindex( L, _i); | 569 | int const in_base = lua_absindex( L, _i); |
570 | int start_depth = 0; | 570 | int start_depth = 0; |
571 | DEBUGSPEW_CODE( Universe* U = universe_get( L)); | 571 | DEBUGSPEW_CODE( Universe* U = universe_get( L)); |
572 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL")); | 572 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "nullptr")); |
573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
574 | STACK_GROW( L, 3); | 574 | STACK_GROW( L, 3); |
575 | STACK_CHECK( L, 0); | 575 | STACK_CHECK( L, 0); |
@@ -578,7 +578,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
578 | ASSERT_L( lua_istable( L, -1)); | 578 | ASSERT_L( lua_istable( L, -1)); |
579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function | 579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function |
580 | { | 580 | { |
581 | name_ = name_ ? name_ : "NULL"; | 581 | name_ = name_ ? name_ : "nullptr"; |
582 | lua_pushvalue( L, in_base); // {} f | 582 | lua_pushvalue( L, in_base); // {} f |
583 | lua_pushstring( L, name_); // {} f _name | 583 | lua_pushstring( L, name_); // {} f _name |
584 | lua_rawset( L, -3); // {} | 584 | lua_rawset( L, -3); // {} |
@@ -711,8 +711,8 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c | |||
711 | else | 711 | else |
712 | { | 712 | { |
713 | // if this is not a sentinel, this is some user-created table we wanted to lookup | 713 | // if this is not a sentinel, this is some user-created table we wanted to lookup |
714 | ASSERT_L( NULL == f && lua_istable( L, i)); | 714 | ASSERT_L(nullptr == f && lua_istable(L, i)); |
715 | // push anything that will convert to NULL string | 715 | // push anything that will convert to nullptr string |
716 | lua_pushnil( L); // ... v ... nil | 716 | lua_pushnil( L); // ... v ... nil |
717 | } | 717 | } |
718 | } | 718 | } |
@@ -730,7 +730,7 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c | |||
730 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 730 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
731 | lua_pop( L, (mode_ == eLM_FromKeeper) ? 1 : 2); // ... v ... | 731 | lua_pop( L, (mode_ == eLM_FromKeeper) ? 1 : 2); // ... v ... |
732 | STACK_MID( L, 0); | 732 | STACK_MID( L, 0); |
733 | if( NULL == fqn && !lua_istable( L, i)) // raise an error if we try to send an unknown function (but not for tables) | 733 | if (nullptr == fqn && !lua_istable(L, i)) // raise an error if we try to send an unknown function (but not for tables) |
734 | { | 734 | { |
735 | char const *from, *typewhat, *what, *gotchaA, *gotchaB; | 735 | char const *from, *typewhat, *what, *gotchaA, *gotchaB; |
736 | // try to discover the name of the function we want to send | 736 | // try to discover the name of the function we want to send |
@@ -756,7 +756,7 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c | |||
756 | } | 756 | } |
757 | (void) luaL_error( L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); | 757 | (void) luaL_error( L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); |
758 | *len_ = 0; | 758 | *len_ = 0; |
759 | return NULL; | 759 | return nullptr; |
760 | } | 760 | } |
761 | STACK_END( L, 0); | 761 | STACK_END( L, 0); |
762 | return fqn; | 762 | return fqn; |
@@ -771,7 +771,7 @@ static bool lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode | |||
771 | // get the name of the table we want to send | 771 | // get the name of the table we want to send |
772 | size_t len; | 772 | size_t len; |
773 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); | 773 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); |
774 | if( NULL == fqn) // name not found, it is some user-created table | 774 | if (nullptr == fqn) // name not found, it is some user-created table |
775 | { | 775 | { |
776 | return false; | 776 | return false; |
777 | } | 777 | } |
@@ -908,7 +908,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
908 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} nil | 908 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} nil |
909 | while( lua_next( L, -2)) // o "r" {c} {fqn} ... {?} k v | 909 | while( lua_next( L, -2)) // o "r" {c} {fqn} ... {?} k v |
910 | { | 910 | { |
911 | //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : NULL; // only for debugging | 911 | //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : nullptr; // only for debugging |
912 | //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging | 912 | //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging |
913 | STACK_MID( L, 2); | 913 | STACK_MID( L, 2); |
914 | // append key name to fqn stack | 914 | // append key name to fqn stack |
@@ -922,7 +922,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
922 | if( depth_ < shortest_) | 922 | if( depth_ < shortest_) |
923 | { | 923 | { |
924 | shortest_ = depth_; | 924 | shortest_ = depth_; |
925 | luaG_pushFQN( L, fqn, depth_, NULL); // o "r" {c} {fqn} ... {?} k v "fqn" | 925 | luaG_pushFQN( L, fqn, depth_, nullptr); // o "r" {c} {fqn} ... {?} k v "fqn" |
926 | lua_replace( L, result); // o "r" {c} {fqn} ... {?} k v | 926 | lua_replace( L, result); // o "r" {c} {fqn} ... {?} k v |
927 | } | 927 | } |
928 | // no need to search further at this level | 928 | // no need to search further at this level |
@@ -1130,7 +1130,7 @@ static void lookup_native_func( lua_State* L2, lua_State* L, uint_t i, LookupMod | |||
1130 | char const* upname; | 1130 | char const* upname; |
1131 | lua_CFunction f = lua_tocfunction( L, i); | 1131 | lua_CFunction f = lua_tocfunction( L, i); |
1132 | // copy upvalues | 1132 | // copy upvalues |
1133 | for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) | 1133 | for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != nullptr; ++ n) |
1134 | { | 1134 | { |
1135 | luaG_inter_move( U, L, L2, 1, mode_); // [up[,up ...]] | 1135 | luaG_inter_move( U, L, L2, 1, mode_); // [up[,up ...]] |
1136 | } | 1136 | } |
@@ -1190,7 +1190,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1190 | { | 1190 | { |
1191 | int n, needToPush; | 1191 | int n, needToPush; |
1192 | luaL_Buffer B; | 1192 | luaL_Buffer B; |
1193 | B.L = NULL; | 1193 | B.L = nullptr; |
1194 | 1194 | ||
1195 | ASSERT_L( L2_cache_i != 0); // ... {cache} ... p | 1195 | ASSERT_L( L2_cache_i != 0); // ... {cache} ... p |
1196 | STACK_GROW( L, 2); | 1196 | STACK_GROW( L, 2); |
@@ -1226,7 +1226,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1226 | 1226 | ||
1227 | // transfer the bytecode, then the upvalues, to create a similar closure | 1227 | // transfer the bytecode, then the upvalues, to create a similar closure |
1228 | { | 1228 | { |
1229 | char const* name = NULL; | 1229 | char const* name = nullptr; |
1230 | 1230 | ||
1231 | #if LOG_FUNC_INFO | 1231 | #if LOG_FUNC_INFO |
1232 | // "To get information about a function you push it onto the | 1232 | // "To get information about a function you push it onto the |
@@ -1238,7 +1238,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1238 | // fills 'name' 'namewhat' and 'linedefined', pops function | 1238 | // fills 'name' 'namewhat' and 'linedefined', pops function |
1239 | lua_getinfo( L, ">nS", &ar); // ... b | 1239 | lua_getinfo( L, ">nS", &ar); // ... b |
1240 | name = ar.namewhat; | 1240 | name = ar.namewhat; |
1241 | fprintf( stderr, INDENT_BEGIN "FNAME: %s @ %d\n", i, s_indent, ar.short_src, ar.linedefined); // just gives NULL | 1241 | fprintf( stderr, INDENT_BEGIN "FNAME: %s @ %d\n", i, s_indent, ar.short_src, ar.linedefined); // just gives nullptr |
1242 | } | 1242 | } |
1243 | #endif // LOG_FUNC_INFO | 1243 | #endif // LOG_FUNC_INFO |
1244 | { | 1244 | { |
@@ -1285,7 +1285,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1285 | // -> if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table | 1285 | // -> if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table |
1286 | lua_pushglobaltable( L); // ... _G | 1286 | lua_pushglobaltable( L); // ... _G |
1287 | #endif // LUA_VERSION_NUM | 1287 | #endif // LUA_VERSION_NUM |
1288 | for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) | 1288 | for (n = 0; (upname = lua_getupvalue(L, i, 1 + n)) != nullptr; ++n) |
1289 | { // ... _G up[n] | 1289 | { // ... _G up[n] |
1290 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END, n, upname)); | 1290 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END, n, upname)); |
1291 | #if LUA_VERSION_NUM >= 502 | 1291 | #if LUA_VERSION_NUM >= 502 |
@@ -1341,7 +1341,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1341 | static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) | 1341 | static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) |
1342 | { | 1342 | { |
1343 | FuncSubType funcSubType; | 1343 | FuncSubType funcSubType; |
1344 | /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions | 1344 | /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // nullptr for LuaJIT-fast && bytecode functions |
1345 | if( funcSubType == FST_Bytecode) | 1345 | if( funcSubType == FST_Bytecode) |
1346 | { | 1346 | { |
1347 | void* const aspointer = (void*)lua_topointer( L, i); | 1347 | void* const aspointer = (void*)lua_topointer( L, i); |
@@ -1459,7 +1459,7 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache | |||
1459 | size_t const bufLen = strlen( upName_) + keyRawLen + 2; | 1459 | size_t const bufLen = strlen( upName_) + keyRawLen + 2; |
1460 | valPath = (char*) alloca( bufLen); | 1460 | valPath = (char*) alloca( bufLen); |
1461 | sprintf( valPath, "%s.%*s", upName_, (int) keyRawLen, key); | 1461 | sprintf( valPath, "%s.%*s", upName_, (int) keyRawLen, key); |
1462 | key = NULL; | 1462 | key = nullptr; |
1463 | } | 1463 | } |
1464 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 1464 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
1465 | else if( lua_isinteger( L, key_i)) | 1465 | else if( lua_isinteger( L, key_i)) |
@@ -1552,7 +1552,7 @@ static bool copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1552 | { | 1552 | { |
1553 | int const mt = lua_absindex( L, -2); // ... mt __lanesclone | 1553 | int const mt = lua_absindex( L, -2); // ... mt __lanesclone |
1554 | size_t const userdata_size = (size_t) lua_rawlen( L, source_i_); | 1554 | size_t const userdata_size = (size_t) lua_rawlen( L, source_i_); |
1555 | void* clone = NULL; | 1555 | void* clone = nullptr; |
1556 | // extract all the uservalues, but don't transfer them yet | 1556 | // extract all the uservalues, but don't transfer them yet |
1557 | int uvi = 0; | 1557 | int uvi = 0; |
1558 | while( lua_getiuservalue( L, source_i_, ++ uvi) != LUA_TNONE) {} // ... mt __lanesclone [uv]+ nil | 1558 | while( lua_getiuservalue( L, source_i_, ++ uvi) != LUA_TNONE) {} // ... mt __lanesclone [uv]+ nil |
@@ -2050,7 +2050,7 @@ int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int packa | |||
2050 | // but don't copy it anyway, as the function names change depending on the slot index! | 2050 | // but don't copy it anyway, as the function names change depending on the slot index! |
2051 | // users should provide an on_state_create function to setup custom loaders instead | 2051 | // users should provide an on_state_create function to setup custom loaders instead |
2052 | // don't copy package.preload in keeper states (they don't know how to translate functions) | 2052 | // don't copy package.preload in keeper states (they don't know how to translate functions) |
2053 | char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : NULL/*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, NULL}; | 2053 | char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : nullptr /*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, nullptr }; |
2054 | for( i = 0; entries[i]; ++ i) | 2054 | for( i = 0; entries[i]; ++ i) |
2055 | { | 2055 | { |
2056 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "package.%s\n" INDENT_END, entries[i])); | 2056 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "package.%s\n" INDENT_END, entries[i])); |
diff --git a/src/universe.cpp b/src/universe.cpp index a31189c..d04a2f8 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -68,7 +68,7 @@ Universe* universe_get( lua_State* L) | |||
68 | STACK_GROW( L, 2); | 68 | STACK_GROW( L, 2); |
69 | STACK_CHECK( L, 0); | 69 | STACK_CHECK( L, 0); |
70 | REGISTRY_GET( L, UNIVERSE_REGKEY); | 70 | REGISTRY_GET( L, UNIVERSE_REGKEY); |
71 | universe = (Universe*) lua_touserdata( L, -1); // NULL if nil | 71 | universe = (Universe*) lua_touserdata( L, -1); // nullptr if nil |
72 | lua_pop( L, 1); | 72 | lua_pop( L, 1); |
73 | STACK_END( L, 0); | 73 | STACK_END( L, 0); |
74 | return universe; | 74 | return universe; |
diff --git a/src/universe.h b/src/universe.h index 0599302..3f61945 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -71,7 +71,7 @@ struct s_Universe | |||
71 | 71 | ||
72 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object | 72 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object |
73 | // used for timers (each lane will get a proxy to this) | 73 | // used for timers (each lane will get a proxy to this) |
74 | volatile DeepPrelude* timer_deep; // = NULL | 74 | volatile DeepPrelude* timer_deep; // = nullptr |
75 | 75 | ||
76 | #if HAVE_LANE_TRACKING() | 76 | #if HAVE_LANE_TRACKING() |
77 | MUTEX_T tracking_cs; | 77 | MUTEX_T tracking_cs; |