From df1113151aff47bfd1b401bf8d06a3fe8f6b9115 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 20 Mar 2024 16:53:14 +0100 Subject: C++ migration: more NULL → nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cancel.cpp | 2 +- src/compat.h | 2 +- src/deep.cpp | 28 ++++++++++++++-------------- src/keeper.cpp | 4 ++-- src/lanes.cpp | 23 ++++++++++++++--------- src/state.cpp | 36 +++++++++++++++++------------------ src/threading.cpp | 28 ++++++++++++++-------------- src/threading.h | 2 +- src/tools.cpp | 56 +++++++++++++++++++++++++++---------------------------- src/universe.cpp | 2 +- src/universe.h | 2 +- 11 files changed, 95 insertions(+), 90 deletions(-) (limited to 'src') 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. static inline enum e_cancel_request cancel_test( lua_State* L) { Lane* const s = get_lane_from_registry( L); - // 's' is NULL for the original main state (and no-one can cancel that) + // 's' is nullptr for the original main state (and no-one can cancel that) return s ? s->cancel_request : CANCEL_NONE; } 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" { #define lua_setuservalue lua_setfenv #define lua_getuservalue lua_getfenv #define lua_rawlen lua_objlen -#define luaG_registerlibfuncs( L, _funcs) luaL_register( L, NULL, _funcs) +#define luaG_registerlibfuncs(L, _funcs) luaL_register(L, nullptr, _funcs) #define LUA_OK 0 #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value 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) /* * Return the registered ID function for 'index' (deep userdata proxy), -* or NULL if 'index' is not a deep userdata proxy. +* or nullptr if 'index' is not a deep userdata proxy. */ static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mode_) { @@ -128,13 +128,13 @@ static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mo if( !lua_getmetatable( L, index)) // deep ... metatable? { - return NULL; // no metatable: can't be a deep userdata object! + return nullptr; // no metatable: can't be a deep userdata object! } // replace metatable with the idfunc pointer, if it is actually a deep userdata get_deep_lookup( L); // deep ... idfunc|nil - ret = (luaG_IdFunction) lua_touserdata( L, -1); // NULL if not a userdata + ret = (luaG_IdFunction) lua_touserdata( L, -1); // nullptr if not a userdata lua_pop( L, 1); STACK_END( L, 0); return ret; @@ -189,14 +189,14 @@ static int deep_userdata_gc( lua_State* L) luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); } } - *proxy = NULL; // make sure we don't use it any more, just in case + *proxy = nullptr; // make sure we don't use it any more, just in case return 0; } /* * Push a proxy userdata on the stack. - * returns NULL if ok, else some error string related to bad idfunc behavior or module require problem + * returns nullptr if ok, else some error string related to bad idfunc behavior or module require problem * (error cannot happen with mode_ == eLM_ToKeeper) * * 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 if ( !lua_isnil( L, -1)) { lua_remove( L, -2); // proxy - return NULL; + return nullptr; } else { @@ -293,7 +293,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in return "Bad idfunc(eOP_module): should not push anything"; } } - if( NULL != modname) // we actually got a module name + if (nullptr != modname) // we actually got a module name { // L.registry._LOADED exists without having registered the 'package' library. 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 lua_remove( L, -2); // proxy ASSERT_L( lua_isuserdata( L, -1)); STACK_END( L, 0); - return NULL; + return nullptr; } /* @@ -386,7 +386,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) { int const oldtop = lua_gettop( L); DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); - if( prelude == NULL) + if (prelude == nullptr) { return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); } @@ -408,7 +408,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) return luaL_error( L, "Bad idfunc(eDO_new): should not push anything on the stack"); } errmsg = push_deep_proxy( universe_get( L), L, prelude, nuv_, eLM_LaneBody); // proxy - if( errmsg != NULL) + if (errmsg != nullptr) { return luaL_error( L, errmsg); } @@ -432,7 +432,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) // ensure it is actually a deep userdata if( get_idfunc( L, index, eLM_LaneBody) != idfunc) { - return NULL; // no metatable, or wrong kind + return nullptr; // no metatable, or wrong kind } proxy = (DeepPrelude**) lua_touserdata( L, index); @@ -446,7 +446,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) * Copy deep userdata between two separate Lua states (from L to L2) * * Returns: - * the id function of the copied value, or NULL for non-deep userdata + * the id function of the copied value, or nullptr for non-deep userdata * (not copied) */ 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 luaG_IdFunction idfunc = get_idfunc( L, i, mode_); int nuv = 0; - if( idfunc == NULL) + if (idfunc == nullptr) { return false; // not a deep userdata } @@ -490,7 +490,7 @@ bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint STACK_END( L2, 1); STACK_END( L, 0); - if( errmsg != NULL) + if (errmsg != nullptr) { // raise the error in the proper state (not the keeper) 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) lua_rawget( L, 1); // fifos key fifo|nil // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! fifo = (keeper_fifo*) lua_touserdata( L, -1); - if( fifo != nullptr) // might be NULL if we set a nonexistent key to nil + if( fifo != nullptr) // might be nullptr if we set a nonexistent key to nil { // fifos key fifo if( fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it { @@ -621,7 +621,7 @@ void close_keepers( Universe* U) /* * Initialize keeper states * - * If there is a problem, returns NULL and pushes the error message on the stack + * If there is a problem, returns nullptr and pushes the error message on the stack * else returns the keepers bookkeeping structure. * * 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) break; } // fall through if we are killed, as we got nil, "killed" on the stack + [[fallthrough]]; case DONE: // got regular return values { - int i, nvalues = lua_gettop( L) - 3; - for( i = nvalues; i > 0; -- i) + int const nvalues{ lua_gettop(L) - 3 }; + for( int i = nvalues; i > 0; -- i) { // pop the last element of the stack, to store it in the uservalue at its proper index lua_rawseti( L, USR, i); @@ -2049,16 +2050,20 @@ static void EnableCrashingOnCrashes( void) const DWORD EXCEPTION_SWALLOWING = 0x1; HMODULE kernel32 = LoadLibraryA("kernel32.dll"); - tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); - tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); - if( pGetPolicy && pSetPolicy) + if (kernel32) { - DWORD dwFlags; - if( pGetPolicy( &dwFlags)) + tGetPolicy pGetPolicy = (tGetPolicy) GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); + tSetPolicy pSetPolicy = (tSetPolicy) GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); + if (pGetPolicy && pSetPolicy) { - // Turn off the filter - pSetPolicy( dwFlags & ~EXCEPTION_SWALLOWING); + DWORD dwFlags; + if (pGetPolicy(&dwFlags)) + { + // Turn off the filter + pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING); + } } + FreeLibrary(kernel32); } //typedef void (* SignalHandlerPointer)( int); /*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[] = #endif { LUA_COLIBNAME, luaopen_coroutine}, // Lua 5.2: coroutine is no longer a part of base! #else // LUA_VERSION_NUM - { LUA_COLIBNAME, NULL}, // Lua 5.1: part of base package + { LUA_COLIBNAME, nullptr }, // Lua 5.1: part of base package #endif // LUA_VERSION_NUM { LUA_DBLIBNAME, luaopen_debug}, #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, add some LuaJIT-specific libs @@ -156,11 +156,11 @@ static const luaL_Reg libs[] = { LUA_FFILIBNAME, luaopen_ffi}, #endif // LUAJIT_FLAVOR() -{ LUA_DBLIBNAME, luaopen_debug}, -{ "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) + { LUA_DBLIBNAME, luaopen_debug}, + { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) // -{ "base", NULL}, // ignore "base" (already acquired it) -{ NULL, NULL } + { "base", nullptr }, // ignore "base" (already acquired it) + { nullptr, nullptr } }; 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 { lua_CFunction libfunc = libs[i].func; name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ - if( libfunc != NULL) + if (libfunc != nullptr) { bool const isLanesCore{ libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" 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) { // store C function pointer in an internal variable U->on_state_create_func = lua_tocfunction( L, -1); // settings on_state_create - if( U->on_state_create_func != NULL) + if (U->on_state_create_func != nullptr) { // make sure the function doesn't have upvalues char const* upname = lua_getupvalue( L, -1, 1); // settings on_state_create upval? - if( upname != NULL) // should be "" for C functions with upvalues if any + if (upname != nullptr) // should be "" for C functions with upvalues if any { (void) luaL_error( L, "on_state_create shouldn't have upvalues"); } @@ -254,7 +254,7 @@ lua_State* create_state( Universe* U, lua_State* from_) // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... L = luaL_newstate(); #else // LUAJIT_FLAVOR() == 64 - if( U->provide_allocator != NULL) // we have a function we can call to obtain an allocator + if (U->provide_allocator != nullptr) // we have a function we can call to obtain an allocator { lua_pushcclosure( from_, U->provide_allocator, 0); lua_call( from_, 0, 1); @@ -271,7 +271,7 @@ lua_State* create_state( Universe* U, lua_State* from_) } #endif // LUAJIT_FLAVOR() == 64 - if( L == NULL) + if (L == nullptr) { (void) luaL_error( from_, "luaG_newstate() failed while creating state; out of memory"); } @@ -280,7 +280,7 @@ lua_State* create_state( Universe* U, lua_State* from_) void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) { - if( U->on_state_create_func != NULL) + if (U->on_state_create_func != nullptr) { STACK_CHECK( L, 0); 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 /* * Like 'luaL_openlibs()' but allows the set of libraries be selected * -* NULL no libraries, not even base +* nullptr no libraries, not even base * "" base library only * "io,string" named libraries * "*" all libraries * -* Base ("unpack", "print" etc.) is always added, unless 'libs' is NULL. +* Base ("unpack", "print" etc.) is always added, unless 'libs' is nullptr. * * *NOT* called for keeper states! * @@ -342,9 +342,9 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) STACK_MID( L, 0); // neither libs (not even 'base') nor special init func: we are done - if( libs_ == NULL && U->on_state_create_func == NULL) + if (libs_ == nullptr && U->on_state_create_func == nullptr) { - DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate(NULL)\n" INDENT_END)); + DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate(nullptr)\n" INDENT_END)); return L; } @@ -360,7 +360,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) // Anything causes 'base' to be taken in // - if( libs_ != NULL) + if (libs_ != nullptr) { // special "*" case (mainly to help with LuaJIT compatibility) // 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_) luaL_openlibs( L); // don't forget lanes.core for regular lane states open1lib( DEBUGSPEW_PARAM_COMMA( U) L, "lanes.core", 10); - libs_ = NULL; // done with libs + libs_ = nullptr; // done with libs } else { @@ -417,7 +417,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_) STACK_CHECK( L, 0); // after all this, register everything we find in our name<->function database lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack - populate_func_lookup_table( L, -1, NULL); + populate_func_lookup_table(L, -1, nullptr); #if 0 && USE_DEBUG_SPEW() // 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) fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); #else // PLATFORM_XBOX char buf[256]; - FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); #endif // PLATFORM_XBOX #ifdef _MSC_VER @@ -188,7 +188,7 @@ time_d now_secs(void) { // suseconds_t tv_usec; /* and microseconds */ // }; - int rc= gettimeofday( &tv, NULL /*time zone not used any more (in Linux)*/ ); + int rc = gettimeofday(&tv, nullptr /*time zone not used any more (in Linux)*/); assert( rc==0 ); return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; @@ -310,15 +310,15 @@ MSDN: "you can create at most 2028 threads" // Note: Visual C++ requires '__stdcall' where it is void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), void* data, int prio /* -3..+3 */) { - HANDLE h = (HANDLE) _beginthreadex( NULL, // security + HANDLE h = (HANDLE) _beginthreadex(nullptr, // security _THREAD_STACK_SIZE, func, data, 0, // flags (0/CREATE_SUSPENDED) - NULL // thread id (not used) + nullptr // thread id (not used) ); - if( h == NULL) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) + if (h == nullptr) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) { FAIL( "CreateThread", GetLastError()); } @@ -365,7 +365,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) if (rc == WAIT_TIMEOUT) return false; if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); - *ref= NULL; // thread no longer usable + *ref = nullptr; // thread no longer usable return true; } // @@ -376,7 +376,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) // in theory no-one should call this as it is very dangerous (memory and mutex leaks, no notification of DLLs, etc.) if (!TerminateThread( *ref, 0 )) FAIL("TerminateThread", GetLastError()); #endif // PLATFORM_XBOX - *ref= NULL; + *ref = nullptr; } 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) #define PT_CALL( call ) { int rc= call; if (rc!=0) _PT_FAIL( rc, #call, __FILE__, __LINE__ ); } // void SIGNAL_INIT( SIGNAL_T *ref ) { - PT_CALL( pthread_cond_init(ref,NULL /*attr*/) ); + PT_CALL(pthread_cond_init(ref, nullptr /*attr*/)); } void SIGNAL_FREE( SIGNAL_T *ref ) { PT_CALL( pthread_cond_destroy(ref) ); @@ -903,7 +903,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) int bit = 0; #ifdef __NetBSD__ cpuset_t *cpuset = cpuset_create(); - if( cpuset == NULL) + if (cpuset == nullptr) _PT_FAIL( errno, "cpuset_create", __FILE__, __LINE__-2 ); #define CPU_SET(b, s) cpuset_set(b, *(s)) #else @@ -940,7 +940,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) { struct timespec ts_store; - const struct timespec *timeout= NULL; + const struct timespec* timeout = nullptr; bool done; // 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 /* Thread is joinable */ if (!timeout) { - PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); + PT_CALL(pthread_join(*ref, nullptr /*ignore exit value*/)); done = true; } else { - int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); + int rc = PTHREAD_TIMEDJOIN(*ref, nullptr, timeout); if ((rc!=0) && (rc!=ETIMEDOUT)) { _PT_FAIL( rc, "PTHREAD_TIMEDJOIN", __FILE__, __LINE__-2 ); } @@ -1010,9 +1010,9 @@ bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); #else // that's the default, but just in case... - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) - pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); #endif } 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 }; #endif #define MUTEX_T pthread_mutex_t - #define MUTEX_INIT(ref) pthread_mutex_init(ref,NULL) + #define MUTEX_INIT(ref) pthread_mutex_init(ref, nullptr) #define MUTEX_RECURSIVE_INIT(ref) \ { pthread_mutexattr_t a; pthread_mutexattr_init( &a ); \ 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 */ void push_registry_subtable( lua_State* L, UniqueKey key_) { - push_registry_subtable_mode( L, key_, NULL); + push_registry_subtable_mode(L, key_, nullptr); } // ################################################################################################ @@ -162,7 +162,7 @@ static void* libc_lua_Alloc(void* ud, void* ptr, size_t osize, size_t nsize) if (nsize == 0) { free(ptr); - return NULL; + return nullptr; } else { @@ -199,11 +199,11 @@ void initialize_allocator_function( Universe* U, lua_State* L) { // store C function pointer in an internal variable U->provide_allocator = lua_tocfunction( L, -1); // settings allocator - if( U->provide_allocator != NULL) + if (U->provide_allocator != nullptr) { // make sure the function doesn't have upvalues char const* upname = lua_getupvalue( L, -1, 1); // settings allocator upval? - if( upname != NULL) // should be "" for C functions with upvalues if any + if (upname != nullptr) // should be "" for C functions with upvalues if any { (void) luaL_error( L, "config.allocator() shouldn't have upvalues"); } @@ -240,7 +240,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) if (strcmp(allocator, "libc") == 0) { U->internal_allocator.allocF = libc_lua_Alloc; - U->internal_allocator.allocUD = NULL; + U->internal_allocator.allocUD = nullptr; } else { @@ -254,7 +254,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) void cleanup_allocator_function( Universe* U, lua_State* L) { // remove the protected allocator, if any - if( U->protected_allocator.definition.allocF != NULL) + if (U->protected_allocator.definition.allocF != nullptr) { // install the non-protected allocator 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) * +-----------------+----------+------------+----------+ * | lua_topointer | | | | * +-----------------+----------+------------+----------+ - * | lua_tocfunction | NULL | | NULL | + * | lua_tocfunction | nullptr | | nullptr | * +-----------------+----------+------------+----------+ * | lua_dump | 666 | 1 | 1 | * +-----------------+----------+------------+----------+ @@ -310,7 +310,7 @@ FuncSubType luaG_getfuncsubtype( lua_State *L, int _i) // the provided writer fails with code 666 // therefore, anytime we get 666, this means that lua_dump() attempted a dump // all other cases mean this is either a C or LuaJIT-fast function - dumpres = lua504_dump( L, dummy_writer, NULL, 0); + dumpres = lua504_dump(L, dummy_writer, nullptr, 0); lua_pop( L, mustpush); if( dumpres == 666) { @@ -380,7 +380,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* // first, raise an error if the function is already known lua_pushvalue( L, -1); // ... {bfc} k o o lua_rawget( L, dest); // ... {bfc} k o name? - prevName = lua_tolstring( L, -1, &prevNameLength); // NULL if we got nil (first encounter of this object) + prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) // push name in fqn stack (note that concatenation will crash if name is a not string or a number) lua_pushvalue( L, -3); // ... {bfc} k o name? k 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* // Also, nothing prevents any external module from exposing a given object under several names, so... // Therefore, when we encounter an object for which a name was previously registered, we need to select the names // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded - if( prevName != NULL && (prevNameLength < newNameLength || lua_lessthan( L, -2, -1))) + if (prevName != nullptr && (prevNameLength < newNameLength || lua_lessthan(L, -2, -1))) { DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END, lua_typename( L, lua_type( L, -3)), newName, prevName)); // 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_) int const in_base = lua_absindex( L, _i); int start_depth = 0; DEBUGSPEW_CODE( Universe* U = universe_get( L)); - DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL")); + DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "nullptr")); DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); STACK_GROW( L, 3); STACK_CHECK( L, 0); @@ -578,7 +578,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) ASSERT_L( lua_istable( L, -1)); if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function { - name_ = name_ ? name_ : "NULL"; + name_ = name_ ? name_ : "nullptr"; lua_pushvalue( L, in_base); // {} f lua_pushstring( L, name_); // {} f _name lua_rawset( L, -3); // {} @@ -711,8 +711,8 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c else { // if this is not a sentinel, this is some user-created table we wanted to lookup - ASSERT_L( NULL == f && lua_istable( L, i)); - // push anything that will convert to NULL string + ASSERT_L(nullptr == f && lua_istable(L, i)); + // push anything that will convert to nullptr string lua_pushnil( L); // ... v ... nil } } @@ -730,7 +730,7 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database lua_pop( L, (mode_ == eLM_FromKeeper) ? 1 : 2); // ... v ... STACK_MID( L, 0); - if( NULL == fqn && !lua_istable( L, i)) // raise an error if we try to send an unknown function (but not for tables) + if (nullptr == fqn && !lua_istable(L, i)) // raise an error if we try to send an unknown function (but not for tables) { char const *from, *typewhat, *what, *gotchaA, *gotchaB; // 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 } (void) luaL_error( L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); *len_ = 0; - return NULL; + return nullptr; } STACK_END( L, 0); return fqn; @@ -771,7 +771,7 @@ static bool lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode // get the name of the table we want to send size_t len; char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); - if( NULL == fqn) // name not found, it is some user-created table + if (nullptr == fqn) // name not found, it is some user-created table { return false; } @@ -908,7 +908,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) lua_pushnil( L); // o "r" {c} {fqn} ... {?} nil while( lua_next( L, -2)) // o "r" {c} {fqn} ... {?} k v { - //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : NULL; // only for debugging + //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : nullptr; // only for debugging //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging STACK_MID( L, 2); // append key name to fqn stack @@ -922,7 +922,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) if( depth_ < shortest_) { shortest_ = depth_; - luaG_pushFQN( L, fqn, depth_, NULL); // o "r" {c} {fqn} ... {?} k v "fqn" + luaG_pushFQN( L, fqn, depth_, nullptr); // o "r" {c} {fqn} ... {?} k v "fqn" lua_replace( L, result); // o "r" {c} {fqn} ... {?} k v } // 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 char const* upname; lua_CFunction f = lua_tocfunction( L, i); // copy upvalues - for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) + for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != nullptr; ++ n) { luaG_inter_move( U, L, L2, 1, mode_); // [up[,up ...]] } @@ -1190,7 +1190,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* { int n, needToPush; luaL_Buffer B; - B.L = NULL; + B.L = nullptr; ASSERT_L( L2_cache_i != 0); // ... {cache} ... p STACK_GROW( L, 2); @@ -1226,7 +1226,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* // transfer the bytecode, then the upvalues, to create a similar closure { - char const* name = NULL; + char const* name = nullptr; #if LOG_FUNC_INFO // "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* // fills 'name' 'namewhat' and 'linedefined', pops function lua_getinfo( L, ">nS", &ar); // ... b name = ar.namewhat; - fprintf( stderr, INDENT_BEGIN "FNAME: %s @ %d\n", i, s_indent, ar.short_src, ar.linedefined); // just gives NULL + fprintf( stderr, INDENT_BEGIN "FNAME: %s @ %d\n", i, s_indent, ar.short_src, ar.linedefined); // just gives nullptr } #endif // LOG_FUNC_INFO { @@ -1285,7 +1285,7 @@ static void copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* // -> if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table lua_pushglobaltable( L); // ... _G #endif // LUA_VERSION_NUM - for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) + for (n = 0; (upname = lua_getupvalue(L, i, 1 + n)) != nullptr; ++n) { // ... _G up[n] DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END, n, upname)); #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* 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_) { FuncSubType funcSubType; - /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions + /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // nullptr for LuaJIT-fast && bytecode functions if( funcSubType == FST_Bytecode) { 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 size_t const bufLen = strlen( upName_) + keyRawLen + 2; valPath = (char*) alloca( bufLen); sprintf( valPath, "%s.%*s", upName_, (int) keyRawLen, key); - key = NULL; + key = nullptr; } #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 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* { int const mt = lua_absindex( L, -2); // ... mt __lanesclone size_t const userdata_size = (size_t) lua_rawlen( L, source_i_); - void* clone = NULL; + void* clone = nullptr; // extract all the uservalues, but don't transfer them yet int uvi = 0; 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 // but don't copy it anyway, as the function names change depending on the slot index! // users should provide an on_state_create function to setup custom loaders instead // don't copy package.preload in keeper states (they don't know how to translate functions) - char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : NULL/*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, NULL}; + char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : nullptr /*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, nullptr }; for( i = 0; entries[i]; ++ i) { 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) STACK_GROW( L, 2); STACK_CHECK( L, 0); REGISTRY_GET( L, UNIVERSE_REGKEY); - universe = (Universe*) lua_touserdata( L, -1); // NULL if nil + universe = (Universe*) lua_touserdata( L, -1); // nullptr if nil lua_pop( L, 1); STACK_END( L, 0); 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 // Initialized by 'init_once_LOCKED()': the deep userdata Linda object // used for timers (each lane will get a proxy to this) - volatile DeepPrelude* timer_deep; // = NULL + volatile DeepPrelude* timer_deep; // = nullptr #if HAVE_LANE_TRACKING() MUTEX_T tracking_cs; -- cgit v1.2.3-55-g6feb