aboutsummaryrefslogtreecommitdiff
path: root/src/tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cpp')
-rw-r--r--src/tools.cpp56
1 files changed, 28 insertions, 28 deletions
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 */
98void push_registry_subtable( lua_State* L, UniqueKey key_) 98void 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)
254void cleanup_allocator_function( Universe* U, lua_State* L) 254void 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*
1341static 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_) 1341static 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]));