diff --git a/src/auxiliary/lauxlib.cpp b/src/auxiliary/lauxlib.cpp index f21ef98b..403a37ae 100644 --- a/src/auxiliary/lauxlib.cpp +++ b/src/auxiliary/lauxlib.cpp @@ -188,7 +188,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { } argword = "argument"; } - if (ar.name == NULL) + if (ar.name == nullptr) ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; return luaL_error(L, "bad %s #%d to '%s' (%s)", argword, arg, ar.name, extramsg); @@ -291,7 +291,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { LUALIB_API int luaL_execresult (lua_State *L, int stat) { if (stat == -1) /* error with an 'errno'? */ - return luaL_fileresult(L, 0, NULL); + return luaL_fileresult(L, 0, nullptr); else { const char *what = "exit"; /* type of termination */ l_inspectstat(stat, what); /* interpret result */ @@ -336,22 +336,22 @@ LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ + if (p != nullptr) { /* value is a userdata? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ luaL_getmetatable(L, tname); /* get correct metatable */ if (!lua_rawequal(L, -1, -2)) /* not the same? */ - p = NULL; /* value is a userdata with wrong metatable */ + p = nullptr; /* value is a userdata with wrong metatable */ lua_pop(L, 2); /* remove both metatables */ return p; } } - return NULL; /* value is not a userdata with a metatable */ + return nullptr; /* value is not a userdata with a metatable */ } LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { void *p = luaL_testudata(L, ud, tname); - luaL_argexpected(L, p != NULL, ud, tname); + luaL_argexpected(L, p != nullptr, ud, tname); return p; } @@ -490,7 +490,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) { void *ud; lua_Alloc allocf = lua_getallocf(L, &ud); void *temp = allocf(ud, box->box, box->bsize, newsize); - if (l_unlikely(temp == NULL && newsize > 0)) { /* allocation error? */ + if (l_unlikely(temp == nullptr && newsize > 0)) { /* allocation error? */ lua_pushliteral(L, "not enough memory"); lua_error(L); /* raise a memory error */ } @@ -510,13 +510,13 @@ static int boxgc (lua_State *L) { static const luaL_Reg boxmt[] = { /* box metamethods */ {"__gc", boxgc}, {"__close", boxgc}, - {NULL, NULL} + {nullptr, nullptr} }; static void newbox (lua_State *L) { UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0); - box->box = NULL; + box->box = nullptr; box->bsize = 0; if (luaL_newmetatable(L, "_UBOX*")) /* creating metatable? */ luaL_setfuncs(L, boxmt, 0); /* set its metamethods */ @@ -533,10 +533,10 @@ static void newbox (lua_State *L) { /* ** Whenever buffer is accessed, slot 'idx' must either be a box (which -** cannot be NULL) or it is a placeholder for the buffer. +** cannot be nullptr) or it is a placeholder for the buffer. */ #define checkbufferlevel(B,idx) \ - lua_assert(buffonstack(B) ? lua_touserdata(B->L, idx) != NULL \ + lua_assert(buffonstack(B) ? lua_touserdata(B->L, idx) != nullptr \ : lua_touserdata(B->L, idx) == (void*)B) @@ -596,7 +596,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { - if (l > 0) { /* avoid 'std::copy_n' when 's' can be NULL */ + if (l > 0) { /* avoid 'std::copy_n' when 's' can be nullptr */ char *b = prepbuffsize(B, l, -1); std::copy_n(s, l, b); luaL_addsize(B, l); @@ -624,7 +624,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { s = (char*)box->box; /* final buffer address */ s[len] = '\0'; /* add ending zero */ /* clear box, as Lua will take control of the buffer */ - box->bsize = 0; box->box = NULL; + box->bsize = 0; box->box = nullptr; lua_pushexternalstring(L, s, len, allocf, ud); lua_closeslot(L, -2); /* close the box */ lua_gc(L, LUA_GCSTEP, len); @@ -752,7 +752,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { /* 'fread' can return > 0 *and* set the EOF flag. If next call to 'getF' called 'fread', it might still wait for user input. The next check avoids this problem. */ - if (feof(lf->f)) return NULL; + if (feof(lf->f)) return nullptr; *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */ } return lf->buff; @@ -812,7 +812,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, int status, readstatus; int c; int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ - if (filename == NULL) { + if (filename == nullptr) { lua_pushliteral(L, "=stdin"); lf.f = stdin; } @@ -820,7 +820,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, lua_pushfstring(L, "@%s", filename); errno = 0; lf.f = fopen(filename, "r"); - if (lf.f == NULL) return errfile(L, "open", fnameindex); + if (lf.f == nullptr) return errfile(L, "open", fnameindex); } lf.n = 0; if (skipcomment(lf.f, &c)) /* read initial portion */ @@ -830,7 +830,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, if (filename) { /* "real" file? */ errno = 0; lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ - if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + if (lf.f == nullptr) return errfile(L, "reopen", fnameindex); skipcomment(lf.f, &c); /* re-read initial portion */ } } @@ -858,7 +858,7 @@ typedef struct LoadS { static const char *getS (lua_State *L, void *ud, size_t *size) { LoadS *ls = (LoadS *)ud; (void)L; /* not used */ - if (ls->size == 0) return NULL; + if (ls->size == 0) return nullptr; *size = ls->size; ls->size = 0; return ls->s; @@ -965,8 +965,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { */ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - if (l->func == NULL) /* placeholder? */ + for (; l->name != nullptr; l++) { /* fill the table with given functions */ + if (l->func == nullptr) /* placeholder? */ lua_pushboolean(L, 0); else { int i; @@ -1028,7 +1028,7 @@ LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, const char *p, const char *r) { const char *wild; size_t l = strlen(p); - while ((wild = strstr(s, p)) != NULL) { + while ((wild = strstr(s, p)) != nullptr) { luaL_addlstring(b, s, ct_diff2sz(wild - s)); /* push prefix */ luaL_addstring(b, r); /* push replacement in place of pattern */ s = wild + l; /* continue after 'p' */ @@ -1051,7 +1051,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { (void)ud; (void)osize; /* not used */ if (nsize == 0) { free(ptr); - return NULL; + return nullptr; } else return realloc(ptr, nsize); @@ -1157,7 +1157,7 @@ static unsigned int luai_makeseed (void) { unsigned int buff[BUFSEED]; unsigned int res; unsigned int i; - time_t t = time(NULL); + time_t t = time(nullptr); char *b = (char*)buff; addbuff(b, b); /* local variable's address */ addbuff(b, t); /* time */ @@ -1183,7 +1183,7 @@ LUALIB_API unsigned int luaL_makeseed (lua_State *L) { ** as a macro. */ LUALIB_API lua_State *(luaL_newstate) (void) { - lua_State *L = lua_newstate(l_alloc, NULL, luai_makeseed()); + lua_State *L = lua_newstate(l_alloc, nullptr, luai_makeseed()); if (l_likely(L)) { lua_atpanic(L, &panic); lua_setwarnf(L, warnfoff, L); /* default is warnings off */ diff --git a/src/auxiliary/linit.cpp b/src/auxiliary/linit.cpp index 2fc258c6..ef886a8b 100644 --- a/src/auxiliary/linit.cpp +++ b/src/auxiliary/linit.cpp @@ -36,7 +36,7 @@ static const luaL_Reg stdlibs[] = { {LUA_STRLIBNAME, luaopen_string}, {LUA_TABLIBNAME, luaopen_table}, {LUA_UTF8LIBNAME, luaopen_utf8}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -47,7 +47,7 @@ LUALIB_API void luaL_openselectedlibs (lua_State *L, int load, int preload) { int mask; const luaL_Reg *lib; luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); - for (lib = stdlibs, mask = 1; lib->name != NULL; lib++, mask <<= 1) { + for (lib = stdlibs, mask = 1; lib->name != nullptr; lib++, mask <<= 1) { if (load & mask) { /* selected? */ luaL_requiref(L, lib->name, lib->func, 1); /* require library */ lua_pop(L, 1); /* remove result from the stack */ diff --git a/src/compiler/funcstate.cpp b/src/compiler/funcstate.cpp index 38a2bcfe..811fd5a2 100644 --- a/src/compiler/funcstate.cpp +++ b/src/compiler/funcstate.cpp @@ -92,7 +92,7 @@ short FuncState::registerlocalvar(TString *varname) { luaM_growvector(getLexState()->getLuaState(), proto->getLocVarsRef(), getNumDebugVars(), proto->getLocVarsSizeRef(), LocVar, SHRT_MAX, "local variables"); while (oldsize < proto->getLocVarsSize()) - proto->getLocVars()[oldsize++].setVarName(NULL); + proto->getLocVars()[oldsize++].setVarName(nullptr); proto->getLocVars()[getNumDebugVars()].setVarName(varname); proto->getLocVars()[getNumDebugVars()].setStartPC(getPC()); luaC_objbarrier(getLexState()->getLuaState(), proto, varname); @@ -140,7 +140,7 @@ lu_byte FuncState::nvarstack() { LocVar *FuncState::localdebuginfo(int vidx) { Vardesc *vd = getlocalvardesc(vidx); if (!vd->isInReg()) - return NULL; /* no debug info. for constants */ + return nullptr; /* no debug info. for constants */ else { int idx = vd->vd.pidx; lua_assert(idx < getNumDebugVars()); @@ -197,7 +197,7 @@ Upvaldesc *FuncState::allocupvalue() { luaM_growvector(getLexState()->getLuaState(), proto->getUpvaluesRef(), getNumUpvalues(), proto->getUpvaluesSizeRef(), Upvaldesc, MAXUPVAL, "upvalues"); while (oldsize < proto->getUpvaluesSize()) - proto->getUpvalues()[oldsize++].setName(NULL); + proto->getUpvalues()[oldsize++].setName(nullptr); return &proto->getUpvalues()[getNumUpvaluesRef()++]; } @@ -238,7 +238,7 @@ int FuncState::searchvar(TString *n, expdesc *var) { for (i = cast_int(getNumActiveVars()) - 1; i >= 0; i--) { Vardesc *vd = getlocalvardesc(i); if (vd->isGlobal()) { /* global declaration? */ - if (vd->vd.name == NULL) { /* collective declaration? */ + if (vd->vd.name == nullptr) { /* collective declaration? */ if (var->getInfo() < 0) /* no previous collective declaration? */ var->setInfo(getFirstLocal() + i); /* this is the first one */ } @@ -301,7 +301,7 @@ void FuncState::singlevaraux(TString *n, expdesc *var, int base) { else { /* not found at current level; try upvalues */ int idx = searchupvalue(n); /* try existing upvalues */ if (idx < 0) { /* not found? */ - if (getPrev() != NULL) /* more levels? */ + if (getPrev() != nullptr) /* more levels? */ getPrev()->singlevaraux(n, var, 0); /* try upper levels */ if (var->getKind() == VLOCAL || var->getKind() == VUPVAL) /* local or upvalue? */ idx = newupvalue(n, var); /* will be a new upvalue */ @@ -329,7 +329,7 @@ void FuncState::solvegotos(BlockCnt *blockCnt) { Labeldesc *gt = &(*gl)[igt]; /* search for a matching label in the current block */ Labeldesc *lb = lexState->findlabel(gt->name, blockCnt->firstlabel); - if (lb != NULL) /* found a match? */ + if (lb != nullptr) /* found a match? */ lexState->closegoto(this, igt, lb, blockCnt->upval); /* close and remove goto */ else { /* adjust 'goto' for outer block */ /* block has variables to be closed and goto escapes the scope of @@ -351,7 +351,7 @@ void FuncState::enterblock(BlockCnt *blk, lu_byte isloop) { blk->firstgoto = getLexState()->getDyndata()->gt.getN(); blk->upval = 0; /* inherit 'insidetbc' from enclosing block */ - blk->insidetbc = (getBlock() != NULL && getBlock()->insidetbc); + blk->insidetbc = (getBlock() != nullptr && getBlock()->insidetbc); blk->previous = getBlock(); /* link block in function's block list */ setBlock(blk); lua_assert(getFreeReg() == luaY_nvarstack(this)); @@ -370,7 +370,7 @@ void FuncState::leaveblock() { if (blk->isloop == 2) /* has to fix pending breaks? */ lexstate->createlabel(this, lexstate->getBreakName(), 0, 0); solvegotos(blk); - if (blk->previous == NULL) { /* was it the last block? */ + if (blk->previous == nullptr) { /* was it the last block? */ if (blk->firstgoto < lexstate->getDyndata()->gt.getN()) /* still pending gotos? */ lexstate->undefgoto(this, &lexstate->getDyndata()->gt[blk->firstgoto]); /* error */ } diff --git a/src/compiler/lcode.cpp b/src/compiler/lcode.cpp index 01e7f058..cf945ea1 100644 --- a/src/compiler/lcode.cpp +++ b/src/compiler/lcode.cpp @@ -943,7 +943,7 @@ void FuncState::codebinNoK(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int l ** constant in the proper range, use variant opcodes with K operands. */ void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int line) { - if (tonumeral(e2, NULL) && exp2K(e2)) /* K operand? */ + if (tonumeral(e2, nullptr) && exp2K(e2)) /* K operand? */ codebinK(opr, e1, e2, flip, line); else /* 'e2' is neither an immediate nor a K operand */ codebinNoK(opr, e1, e2, flip, line); @@ -956,7 +956,7 @@ void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int li */ void FuncState::codecommutative(BinOpr op, expdesc *e1, expdesc *e2, int line) { int flip = 0; - if (tonumeral(e1, NULL)) { /* is first operand a numeric constant? */ + if (tonumeral(e1, nullptr)) { /* is first operand a numeric constant? */ swapexps(e1, e2); /* change order */ flip = 1; } @@ -1527,14 +1527,14 @@ void FuncState::infix(int opr, expdesc *v) { case BinOpr::OPR_MOD: case BinOpr::OPR_POW: case BinOpr::OPR_BAND: case BinOpr::OPR_BOR: case BinOpr::OPR_BXOR: case BinOpr::OPR_SHL: case BinOpr::OPR_SHR: { - if (!tonumeral(v, NULL)) + if (!tonumeral(v, nullptr)) exp2anyreg(v); /* else keep numeral, which may be folded or used as an immediate operand */ break; } case BinOpr::OPR_EQ: case BinOpr::OPR_NE: { - if (!tonumeral(v, NULL)) + if (!tonumeral(v, nullptr)) exp2RK(v); /* else keep numeral, which may be an immediate operand */ break; diff --git a/src/compiler/llex.cpp b/src/compiler/llex.cpp index 478f9e6c..1fd7227f 100644 --- a/src/compiler/llex.cpp +++ b/src/compiler/llex.cpp @@ -463,7 +463,7 @@ int LexState::lex(SemInfo *seminfo) { size_t sep = skipSep(); luaZ_resetbuffer(getBuffer()); /* 'skip_sep' may dirty the buffer */ if (sep >= 2) { - readLongString(NULL, sep); /* skip long comment */ + readLongString(nullptr, sep); /* skip long comment */ luaZ_resetbuffer(getBuffer()); /* previous call may dirty the buff. */ break; } diff --git a/src/compiler/parselabels.cpp b/src/compiler/parselabels.cpp index 087532bc..35af9a16 100644 --- a/src/compiler/parselabels.cpp +++ b/src/compiler/parselabels.cpp @@ -54,7 +54,7 @@ typedef struct BlockCnt { */ l_noret LexState::jumpscopeerror(FuncState *funcState, Labeldesc *gt) { TString *tsname = funcState->getlocalvardesc(gt->nactvar)->vd.name; - const char *varname = (tsname != NULL) ? getstr(tsname) : "*"; + const char *varname = (tsname != nullptr) ? getstr(tsname) : "*"; semerror(" at line %d jumps into the scope of '%s'", getstr(gt->name), gt->line, varname); /* raise the error */ } @@ -103,7 +103,7 @@ Labeldesc *LexState::findlabel(TString *name, int ilb) { if (eqstr(lb->name, name)) /* correct label? */ return lb; } - return NULL; /* label not found */ + return nullptr; /* label not found */ } diff --git a/src/compiler/parser.cpp b/src/compiler/parser.cpp index c2335977..31b178b8 100644 --- a/src/compiler/parser.cpp +++ b/src/compiler/parser.cpp @@ -271,7 +271,7 @@ int Parser::new_localvar(TString *name) { */ void Parser::check_readonly(expdesc *e) { // FuncState passed as parameter - TString *varname = NULL; /* to be set if variable is const */ + TString *varname = nullptr; /* to be set if variable is const */ switch (e->getKind()) { case VCONST: { varname = ls->getDyndata()->actvar()[e->getInfo()].vd.name; @@ -413,7 +413,7 @@ Proto *Parser::addprototype() { int oldsize = proto->getProtosSize(); luaM_growvector(state, proto->getProtosRef(), funcstate->getNP(), proto->getProtosSizeRef(), Proto *, MAXARG_Bx, "functions"); while (oldsize < proto->getProtosSize()) - proto->getProtos()[oldsize++] = NULL; + proto->getProtos()[oldsize++] = nullptr; } proto->getProtos()[funcstate->getNPRef()++] = clp = luaF_newproto(state); luaC_objbarrier(state, proto, clp); @@ -455,7 +455,7 @@ void Parser::open_func(FuncState *funcstate, BlockCnt *bl) { funcstate->setNeedClose(0); funcstate->setFirstLocal(ls->getDyndata()->actvar().getN()); funcstate->setFirstLabel(ls->getDyndata()->label.getN()); - funcstate->setBlock(NULL); + funcstate->setBlock(nullptr); f->setSource(ls->getSource()); luaC_objbarrier(state, f, f->getSource()); f->setMaxStackSize(2); /* registers 0/1 are always valid */ @@ -472,7 +472,7 @@ void Parser::close_func() { Proto *f = funcstate->getProto(); funcstate->ret(luaY_nvarstack(funcstate), 0); /* final return */ funcstate->leaveblock(); - lua_assert(funcstate->getBlock() == NULL); + lua_assert(funcstate->getBlock() == nullptr); funcstate->finish(); luaM_shrinkvector(state, f->getCodeRef(), f->getCodeSizeRef(), funcstate->getPC(), Instruction); luaM_shrinkvector(state, f->getLineInfoRef(), f->getLineInfoSizeRef(), funcstate->getPC(), ls_byte); @@ -1021,7 +1021,7 @@ void Parser::gotostat( int line) { */ void Parser::breakstat( int line) { BlockCnt *bl; /* to look for an enclosing loop */ - for (bl = fs->getBlock(); bl != NULL; bl = bl->previous) { + for (bl = fs->getBlock(); bl != nullptr; bl = bl->previous) { if (bl->isloop) /* found one? */ goto ok; } @@ -1039,7 +1039,7 @@ void Parser::breakstat( int line) { */ void Parser::checkrepeated( TString *name) { Labeldesc *lb = ls->findlabel(name, fs->getFirstLabel()); - if (l_unlikely(lb != NULL)) /* already defined? */ + if (l_unlikely(lb != nullptr)) /* already defined? */ ls->semerror( "label '%s' already defined on line %d", getstr(name), lb->line); /* error */ } @@ -1361,8 +1361,8 @@ void Parser::globalstat() { if (!testnext( '*')) globalnames(defkind); else { - /* use NULL as name to represent '*' entries */ - new_varkind( NULL, defkind); + /* use nullptr as name to represent '*' entries */ + new_varkind( nullptr, defkind); funcstate->getNumActiveVarsRef()++; /* activate declaration */ } } @@ -1425,7 +1425,7 @@ void Parser::exprstat() { struct LHS_assign v; suffixedexp(&v.v); if (ls->getToken() == '=' || ls->getToken() == ',') { /* stat -> assignment ? */ - v.prev = NULL; + v.prev = nullptr; restassign(&v, 1); } else { /* stat -> func */ diff --git a/src/core/lapi.cpp b/src/core/lapi.cpp index f0b5f2d8..383bbaec 100644 --- a/src/core/lapi.cpp +++ b/src/core/lapi.cpp @@ -372,16 +372,16 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { o = L->getStackSubsystem().indexToValue(L,idx); if (!ttisstring(o)) { if (!cvt2str(o)) { /* not convertible? */ - if (len != NULL) *len = 0; + if (len != nullptr) *len = 0; lua_unlock(L); - return NULL; + return nullptr; } luaO_tostring(L, o); luaC_checkGC(L); o = L->getStackSubsystem().indexToValue(L,idx); /* previous call may reallocate the stack */ } lua_unlock(L); - if (len != NULL) + if (len != nullptr) return getlstr(tsvalue(o), *len); else return getstr(tsvalue(o)); @@ -411,7 +411,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { if (ttislcf(o)) return fvalue(o); else if (ttisCclosure(o)) return clCvalue(o)->getFunction(); - else return NULL; /* not a C function */ + else return nullptr; /* not a C function */ } @@ -419,7 +419,7 @@ static inline void *touserdata (const TValue *o) { switch (ttype(o)) { case LUA_TUSERDATA: return uvalue(o)->getMemory(); case LUA_TLIGHTUSERDATA: return pvalue(o); - default: return NULL; + default: return nullptr; } } @@ -432,7 +432,7 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { LUA_API lua_State *lua_tothread (lua_State *L, int idx) { const TValue *o = L->getStackSubsystem().indexToValue(L,idx); - return (!ttisthread(o)) ? NULL : thvalue(o); + return (!ttisthread(o)) ? nullptr : thvalue(o); } @@ -453,7 +453,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { if (iscollectable(o)) return gcvalue(o); else - return NULL; + return nullptr; } } } @@ -491,7 +491,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { /* ** Pushes on the stack a string with given length. Avoid using 's' when -** 'len' == 0 (as 's' can be NULL in that case), due to later use of +** 'len' == 0 (as 's' can be nullptr in that case), due to later use of ** 'memcmp' and 'memcpy'. */ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { @@ -523,7 +523,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L, LUA_API const char *lua_pushstring (lua_State *L, const char *s) { lua_lock(L); - if (s == NULL) + if (s == nullptr) setnilvalue(s2v(L->getTop().p)); else { TString *ts; @@ -773,7 +773,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { mt = G(L)->getMetatable(ttype(obj)); break; } - if (mt != NULL) { + if (mt != nullptr) { sethvalue2s(L, L->getTop().p, mt); api_incr_top(L); res = 1; @@ -922,7 +922,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { api_checkpop(L, 1); obj = L->getStackSubsystem().indexToValue(L,objindex); if (ttisnil(s2v(L->getTop().p - 1))) - mt = NULL; + mt = nullptr; else { api_check(L, ttistable(s2v(L->getTop().p - 1)), "table expected"); mt = hvalue(s2v(L->getTop().p - 1)); @@ -992,13 +992,13 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k) { StkId func; lua_lock(L); - api_check(L, k == NULL || !L->getCI()->isLua(), + api_check(L, k == nullptr || !L->getCI()->isLua(), "cannot use continuations inside hooks"); api_checkpop(L, nargs + 1); api_check(L, L->getStatus() == LUA_OK, "cannot do calls on non-normal thread"); checkresults(L, nargs, nresults); func = L->getTop().p - (nargs+1); - if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ + if (k != nullptr && yieldable(L)) { /* need to prepare continuation? */ L->getCI()->setK(k); /* save continuation */ L->getCI()->setCtx(ctx); /* save context */ L->call( func, nresults); /* do the call */ @@ -1033,7 +1033,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, TStatus status; ptrdiff_t func; lua_lock(L); - api_check(L, k == NULL || !L->getCI()->isLua(), + api_check(L, k == nullptr || !L->getCI()->isLua(), "cannot use continuations inside hooks"); api_checkpop(L, nargs + 1); api_check(L, L->getStatus() == LUA_OK, "cannot do calls on non-normal thread"); @@ -1046,7 +1046,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, func = L->saveStack(o); } c.func = L->getTop().p - (nargs+1); /* function to be called */ - if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ + if (k == nullptr || !yieldable(L)) { /* no continuation or no yieldable? */ c.nresults = nresults; /* do a 'conventional' protected call */ status = L->pCall( f_call, &c, L->saveStack(c.func), func); } @@ -1323,7 +1323,7 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val, case LUA_VCCL: { /* C closure */ CClosure *f = clCvalue(fi); if (!(cast_uint(n) - 1u < cast_uint(f->getNumUpvalues()))) - return NULL; /* 'n' not in [1, f->getNumUpvalues()] */ + return nullptr; /* 'n' not in [1, f->getNumUpvalues()] */ *val = f->getUpvalue(n-1); if (owner) *owner = obj2gco(f); return ""; @@ -1333,22 +1333,22 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val, TString *name; Proto *p = f->getProto(); if (!(cast_uint(n) - 1u < cast_uint(p->getUpvaluesSize()))) - return NULL; /* 'n' not in [1, p->getUpvaluesSize()] */ + return nullptr; /* 'n' not in [1, p->getUpvaluesSize()] */ *val = f->getUpval(n-1)->getVP(); if (owner) *owner = obj2gco(f->getUpval(n - 1)); name = p->getUpvalues()[n-1].getName(); - return (name == NULL) ? "(no name)" : getstr(name); + return (name == nullptr) ? "(no name)" : getstr(name); } - default: return NULL; /* not a closure */ + default: return nullptr; /* not a closure */ } } LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { const char *name; - TValue *val = NULL; /* to avoid warnings */ + TValue *val = nullptr; /* to avoid warnings */ lua_lock(L); - name = aux_upvalue(L->getStackSubsystem().indexToValue(L,funcindex), n, &val, NULL); + name = aux_upvalue(L->getStackSubsystem().indexToValue(L,funcindex), n, &val, nullptr); if (name) { L->getStackSubsystem().setSlot(L->getTop().p, val); api_incr_top(L); @@ -1360,8 +1360,8 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { const char *name; - TValue *val = NULL; /* to avoid warnings */ - GCObject *owner = NULL; /* to avoid warnings */ + TValue *val = nullptr; /* to avoid warnings */ + GCObject *owner = nullptr; /* to avoid warnings */ TValue *fi; lua_lock(L); fi = L->getStackSubsystem().indexToValue(L,funcindex); @@ -1378,7 +1378,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { - static const UpVal *const nullup = NULL; + static const UpVal *const nullup = nullptr; LClosure *f; TValue *fi = L->getStackSubsystem().indexToValue(L,fidx); api_check(L, ttisLclosure(fi), "Lua function expected"); @@ -1395,7 +1395,7 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { TValue *fi = L->getStackSubsystem().indexToValue(L,fidx); switch (ttypetag(fi)) { case LUA_VLCL: { /* lua closure */ - return *getupvalref(L, fidx, n, NULL); + return *getupvalref(L, fidx, n, nullptr); } case LUA_VCCL: { /* C closure */ CClosure *f = clCvalue(fi); @@ -1404,10 +1404,10 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { /* else */ } /* FALLTHROUGH */ case LUA_VLCF: - return NULL; /* light C functions have no upvalues */ + return nullptr; /* light C functions have no upvalues */ default: { api_check(L, 0, "function expected"); - return NULL; + return nullptr; } } } @@ -1417,8 +1417,8 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, int fidx2, int n2) { LClosure *f1; UpVal **up1 = getupvalref(L, fidx1, n1, &f1); - UpVal **up2 = getupvalref(L, fidx2, n2, NULL); - api_check(L, *up1 != NULL && *up2 != NULL, "invalid upvalue index"); + UpVal **up2 = getupvalref(L, fidx2, n2, nullptr); + api_check(L, *up1 != nullptr && *up2 != nullptr, "invalid upvalue index"); *up1 = *up2; luaC_objbarrier(L, f1, *up1); } diff --git a/src/core/ldebug.cpp b/src/core/ldebug.cpp index 6f5e6e98..ed2bf7d0 100644 --- a/src/core/ldebug.cpp +++ b/src/core/ldebug.cpp @@ -33,7 +33,7 @@ /* Both CClosure and LClosure have tt at same offset (from GCBase) */ -#define LuaClosure(f) ((f) != NULL && (f)->c.getType() == LUA_VLCL) +#define LuaClosure(f) ((f) != nullptr && (f)->c.getType() == LUA_VLCL) static const char strlocal[] = "local"; static const char strupval[] = "upvalue"; @@ -89,7 +89,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) { ** the desired instruction. */ int luaG_getfuncline (const Proto *f, int pc) { - if (f->getLineInfo() == NULL) /* no debug information? */ + if (f->getLineInfo() == nullptr) /* no debug information? */ return -1; else { int basepc; @@ -120,7 +120,7 @@ static int getcurrentline (CallInfo *ci) { ** has no good reasons to do that.) */ static void settraps (CallInfo *ci) { - for (; ci != NULL; ci = ci->getPrevious()) + for (; ci != nullptr; ci = ci->getPrevious()) if (ci->isLua()) ci->getTrap() = 1; } @@ -137,9 +137,9 @@ static void settraps (CallInfo *ci) { ** before being called (see 'luaD_hook'). */ LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { - if (func == NULL || mask == 0) { /* turn off hooks? */ + if (func == nullptr || mask == 0) { /* turn off hooks? */ mask = 0; - func = NULL; + func = nullptr; } L->setHook(func); L->setBaseHookCount(count); @@ -184,7 +184,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { static const char *upvalname (const Proto *p, int uv) { TString *s = check_exp(uv < p->getUpvaluesSize(), p->getUpvalues()[uv].getName()); - if (s == NULL) return "?"; + if (s == nullptr) return "?"; else return getstr(s); } @@ -197,28 +197,28 @@ static const char *findvararg (CallInfo *ci, int n, StkId *pos) { return "(vararg)"; /* generic name for any vararg */ } } - return NULL; /* no such vararg */ + return nullptr; /* no such vararg */ } // lua_State method const char *lua_State::findLocal(CallInfo *ci_arg, int n, StkId *pos) { StkId base = ci_arg->funcRef().p + 1; - const char *name = NULL; + const char *name = nullptr; if (ci_arg->isLua()) { if (n < 0) /* access to vararg values? */ return findvararg(ci_arg, n, pos); else name = ci_arg->getFunc()->getProto()->getLocalName(n, currentpc(ci_arg)); /* Phase 25b */ } - if (name == NULL) { /* no 'standard' name? */ + if (name == nullptr) { /* no 'standard' name? */ StkId limit = (ci_arg == getCI()) ? getTop().p : ci_arg->getNext()->funcRef().p; if (limit - base >= n && n > 0) { /* is 'n' inside 'ci' stack? */ /* generic name for any valid slot */ name = ci_arg->isLua() ? "(temporary)" : "(C temporary)"; } else - return NULL; /* no name */ + return nullptr; /* no name */ } if (pos) *pos = base + (n - 1); @@ -233,14 +233,14 @@ const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) { LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { const char *name; lua_lock(L); - if (ar == NULL) { /* information about non-active function? */ + if (ar == nullptr) { /* information about non-active function? */ if (!isLfunction(s2v(L->getTop().p - 1))) /* not a Lua function? */ - name = NULL; + name = nullptr; else /* consider live variables at function start (parameters) */ name = clLvalue(s2v(L->getTop().p - 1))->getProto()->getLocalName(n, 0); /* Phase 25b */ } else { /* active function; get information through 'ar' */ - StkId pos = NULL; /* to avoid warnings */ + StkId pos = nullptr; /* to avoid warnings */ name = luaG_findlocal(L, ar->i_ci, n, &pos); if (name) { *s2v(L->getTop().p) = *s2v(pos); /* use operator= */ @@ -253,7 +253,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { - StkId pos = NULL; /* to avoid warnings */ + StkId pos = nullptr; /* to avoid warnings */ const char *name; lua_lock(L); name = luaG_findlocal(L, ar->i_ci, n, &pos); @@ -311,7 +311,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { Table *t = luaH_new(L); /* new table to store active lines */ sethvalue2s(L, L->getTop().p, t); /* push it on stack */ api_incr_top(L); - if (p->getLineInfo() != NULL) { /* proto with debug information? */ + if (p->getLineInfo() != nullptr) { /* proto with debug information? */ int i; TValue v; setbtvalue(&v); /* boolean 'true' to be the value of all indices */ @@ -333,9 +333,9 @@ static void collectvalidlines (lua_State *L, Closure *f) { static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { /* calling function is a known function? */ - if (ci != NULL && !(ci->getCallStatus() & CIST_TAIL)) + if (ci != nullptr && !(ci->getCallStatus() & CIST_TAIL)) return funcnamefromcall(L, ci->getPrevious(), name); - else return NULL; /* no way to find a name */ + else return nullptr; /* no way to find a name */ } @@ -353,7 +353,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, break; } case 'u': { - ar->nups = (f == NULL) ? 0 : f->c.getNumUpvalues(); + ar->nups = (f == nullptr) ? 0 : f->c.getNumUpvalues(); if (!LuaClosure(f)) { ar->isvararg = 1; ar->nparams = 0; @@ -366,7 +366,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, break; } case 't': { - if (ci != NULL) { + if (ci != nullptr) { ar->istailcall = !!(ci->getCallStatus() & CIST_TAIL); ar->extraargs = cast_uchar((ci->getCallStatus() & MAX_CCMT) >> CIST_CCMT); @@ -379,14 +379,14 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, } case 'n': { ar->namewhat = getfuncname(L, ci, &ar->name); - if (ar->namewhat == NULL) { + if (ar->namewhat == nullptr) { ar->namewhat = ""; /* not found */ - ar->name = NULL; + ar->name = nullptr; } break; } case 'r': { - if (ci == NULL || !(ci->getCallStatus() & CIST_HOOKED)) + if (ci == nullptr || !(ci->getCallStatus() & CIST_HOOKED)) ar->ftransfer = ar->ntransfer = 0; else { ar->ftransfer = L->getTransferInfo().ftransfer; @@ -411,7 +411,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { TValue *func; lua_lock(L); if (*what == '>') { - ci = NULL; + ci = nullptr; func = s2v(L->getTop().p - 1); api_check(L, ttisfunction(func), "function expected"); what++; /* skip the '>' */ @@ -422,7 +422,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { func = s2v(ci->funcRef().p); lua_assert(ttisfunction(func)); } - cl = ttisclosure(func) ? clvalue(func) : NULL; + cl = ttisclosure(func) ? clvalue(func) : nullptr; status = auxgetinfo(L, what, ar, cl, ci); if (strchr(what, 'f')) { L->getStackSubsystem().setSlot(L->getTop().p, func); @@ -509,7 +509,7 @@ static const char *kname (const Proto *p, int index, const char **name) { } else { *name = "?"; - return NULL; + return nullptr; } } @@ -541,7 +541,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg, default: break; } } - return NULL; /* could not find reasonable name */ + return nullptr; /* could not find reasonable name */ } @@ -569,7 +569,7 @@ static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) { /* 'name' must be the name of a local variable (at the current level or an upvalue) */ if (what != strlocal && what != strupval) - name = NULL; /* cannot be the variable _ENV */ + name = nullptr; /* cannot be the variable _ENV */ } return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field"; } @@ -581,7 +581,7 @@ static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) { static const char *getobjname (const Proto *p, int lastpc, int reg, const char **name) { const char *kind = basicgetobjname(p, &lastpc, reg, name); - if (kind != NULL) + if (kind != nullptr) return kind; else if (lastpc != -1) { /* could find instruction? */ Instruction i = p->getCode()[lastpc]; @@ -611,10 +611,10 @@ static const char *getobjname (const Proto *p, int lastpc, int reg, kname(p, k, name); return "method"; } - default: break; /* go through to return NULL */ + default: break; /* go through to return nullptr */ } } - return NULL; /* could not find reasonable name */ + return nullptr; /* could not find reasonable name */ } @@ -658,7 +658,7 @@ static const char *funcnamefromcode (lua_State *L, const Proto *p, case OP_LE: case OP_LEI: case OP_GEI: tm = TMS::TM_LE; break; case OP_CLOSE: case OP_RETURN: tm = TMS::TM_CLOSE; break; default: - return NULL; /* cannot find a reasonable name */ + return nullptr; /* cannot find a reasonable name */ } *name = getshrstr(G(L)->getTMName(static_cast(tm))) + 2; return "metamethod"; @@ -681,7 +681,7 @@ static const char *funcnamefromcall (lua_State *L, CallInfo *ci, else if (ci->isLua()) return funcnamefromcode(L, ci->getFunc()->getProto(), currentpc(ci), name); else - return NULL; + return nullptr; } /* }====================================================== */ @@ -719,13 +719,13 @@ static const char *getupvalname (CallInfo *ci, const TValue *o, return strupval; } } - return NULL; + return nullptr; } static const char *formatvarinfo (lua_State *L, const char *kind, const char *name) { - if (kind == NULL) + if (kind == nullptr) return ""; /* no information */ else return luaO_pushfstring(L, " (%s '%s')", kind, name); @@ -737,8 +737,8 @@ static const char *formatvarinfo (lua_State *L, const char *kind, */ static const char *varinfo (lua_State *L, const TValue *o) { CallInfo *ci = L->getCI(); - const char *name = NULL; /* to avoid warnings */ - const char *kind = NULL; + const char *name = nullptr; /* to avoid warnings */ + const char *kind = nullptr; if (ci->isLua()) { kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ if (!kind) { /* not an upvalue? */ @@ -782,7 +782,7 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { */ // lua_State method l_noret lua_State::callError(const TValue *o) { - const char *name = NULL; /* to avoid warnings */ + const char *name = nullptr; /* to avoid warnings */ const char *kind = funcnamefromcall(this, ci, &name); const char *extra = kind ? formatvarinfo(this, kind, name) : varinfo(this, o); typeerror(this, o, "call", extra); @@ -862,7 +862,7 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { /* add src:line information to 'msg' */ // lua_State method const char *lua_State::addInfo(const char *msg, TString *src, int line) { - if (src == NULL) /* no debug information? */ + if (src == nullptr) /* no debug information? */ return luaO_pushfstring(this, "?:?: %s", msg); else { char buff[LUA_IDSIZE]; @@ -940,7 +940,7 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { ** so it goes directly to 'luaG_getfuncline'. */ static int changedline (const Proto *p, int oldpc, int newpc) { - if (p->getLineInfo() == NULL) /* no debug information? */ + if (p->getLineInfo() == nullptr) /* no debug information? */ return 0; if (newpc - oldpc < MAXIWTHABS / 2) { /* not too far apart? */ int delta = 0; /* line difference */ diff --git a/src/core/ldo.cpp b/src/core/ldo.cpp index e25604c0..34be1565 100644 --- a/src/core/ldo.cpp +++ b/src/core/ldo.cpp @@ -171,7 +171,7 @@ l_noret lua_State::doThrow(TStatus errcode) { l_noret lua_State::throwBaseLevel(TStatus errcode) { if (errorJmp) { /* unroll error entries up to the first level */ - while (errorJmp->previous != NULL) + while (errorJmp->previous != nullptr) errorJmp = errorJmp->previous; } doThrow(errcode); @@ -617,7 +617,7 @@ int lua_State::preTailCall(CallInfo *ci_arg, StkId func, ** the call. The function to be called is at '*func'. The arguments ** are on the stack, right after the function. Returns the CallInfo ** to be executed, if it was a Lua function. Otherwise (a C function) -** returns NULL, with all the results on the stack, starting at the +** returns nullptr, with all the results on the stack, starting at the ** original function position. */ // Convert to lua_State method @@ -628,10 +628,10 @@ CallInfo* lua_State::preCall(StkId func, int nresults) { switch (ttypetag(s2v(func))) { case LUA_VCCL: /* C closure */ preCallC(func, status_val, clCvalue(s2v(func))->getFunction()); - return NULL; + return nullptr; case LUA_VLCF: /* light C function */ preCallC(func, status_val, fvalue(s2v(func))); - return NULL; + return nullptr; case LUA_VLCL: { /* Lua function */ CallInfo *ci_new; Proto *p = clLvalue(s2v(func))->getProto(); @@ -673,7 +673,7 @@ void lua_State::cCall(StkId func, int nResults, l_uint32 inc) { checkstackp(this, 0, func); /* free any use of EXTRA_STACK */ luaE_checkcstack(this); } - if ((ci_result = preCall(func, nResults)) != NULL) { /* Lua function? */ + if ((ci_result = preCall(func, nResults)) != nullptr) { /* Lua function? */ ci_result->callStatusRef() |= CIST_FRESH; /* mark that it is a "fresh" execute */ luaV_execute(this, ci_result); /* call it */ } @@ -761,7 +761,7 @@ void lua_State::finishCCall(CallInfo *ci_arg) { TStatus status_val = LUA_YIELD; /* default if there were no errors */ lua_KFunction kf = ci_arg->getK(); /* continuation function */ /* must have a continuation and must be able to call it */ - lua_assert(kf != NULL && yieldable(this)); + lua_assert(kf != nullptr && yieldable(this)); if (ci_arg->callStatusRef() & CIST_YPCALL) /* was inside a 'lua_pcallk'? */ status_val = finishPCallK(ci_arg); /* finish it */ adjustresults(this, LUA_MULTRET); /* finish 'lua_callk' */ @@ -809,11 +809,11 @@ static void unroll (lua_State *L, void *ud) { // Convert to private lua_State method CallInfo* lua_State::findPCall() { CallInfo *ci_iter; - for (ci_iter = getCI(); ci_iter != NULL; ci_iter = ci_iter->getPrevious()) { /* search for a pcall */ + for (ci_iter = getCI(); ci_iter != nullptr; ci_iter = ci_iter->getPrevious()) { /* search for a pcall */ if (ci_iter->callStatusRef() & CIST_YPCALL) return ci_iter; } - return NULL; /* no pending pcall */ + return nullptr; /* no pending pcall */ } @@ -857,7 +857,7 @@ static void resume (lua_State *L, void *ud) { luaV_execute(L, ci); /* just continue running Lua code */ } else { /* 'common' yield */ - if (ci->getK() != NULL) { /* does it have a continuation function? */ + if (ci->getK() != nullptr) { /* does it have a continuation function? */ lua_unlock(L); n = (*ci->getK())(L, LUA_YIELD, ci->getCtx()); /* call continuation */ lua_lock(L); @@ -865,7 +865,7 @@ static void resume (lua_State *L, void *ud) { } L->postCall( ci, n); /* finish 'luaD_call' */ } - L->unrollContinuation( NULL); /* run continuation */ + L->unrollContinuation( nullptr); /* run continuation */ } } @@ -880,10 +880,10 @@ static void resume (lua_State *L, void *ud) { */ static TStatus precover (lua_State *L, TStatus status) { CallInfo *ci; - while (errorstatus(status) && (ci = L->findPCall()) != NULL) { + while (errorstatus(status) && (ci = L->findPCall()) != nullptr) { L->setCI(ci); /* go down to recovery functions */ ci->setRecoverStatus(status); /* status to finish 'pcall' */ - status = L->rawRunProtected( unroll, NULL); + status = L->rawRunProtected( unroll, nullptr); } return status; } @@ -947,10 +947,10 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, if (ci->isLua()) { /* inside a hook? */ lua_assert(!ci->isLuaCode()); api_check(L, nresults == 0, "hooks cannot yield values"); - api_check(L, k == NULL, "hooks cannot continue after yielding"); + api_check(L, k == nullptr, "hooks cannot continue after yielding"); } else { - if ((ci->setK(k), k) != NULL) /* is there a continuation? */ + if ((ci->setK(k), k) != nullptr) /* is there a continuation? */ ci->setCtx(ctx); /* save context */ L->doThrow( LUA_YIELD); } @@ -1044,7 +1044,7 @@ struct SParser { /* data to 'f_parser' */ static void checkmode (lua_State *L, const char *mode, const char *x) { - if (strchr(mode, x[0]) == NULL) { + if (strchr(mode, x[0]) == nullptr) { luaO_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", x, mode); L->doThrow( LUA_ERRSYNTAX); @@ -1059,7 +1059,7 @@ static void f_parser (lua_State *L, void *ud) { int c = zgetc(p->z); /* read first character */ if (c == LUA_SIGNATURE[0]) { int fixed = 0; - if (strchr(mode, 'B') != NULL) + if (strchr(mode, 'B') != nullptr) fixed = 1; else checkmode(L, mode, "binary"); diff --git a/src/core/lstack.cpp b/src/core/lstack.cpp index d4d95e69..74397339 100644 --- a/src/core/lstack.cpp +++ b/src/core/lstack.cpp @@ -113,7 +113,7 @@ void LuaStack::init(lua_State* L) { ** Free stack memory (called from lstate.cpp) */ void LuaStack::free(lua_State* L) { - if (stack.p == NULL) + if (stack.p == nullptr) return; /* stack not completely built yet */ /* free stack */ luaM_freearray(L, stack.p, cast_sizet(getSize() + EXTRA_STACK)); @@ -135,7 +135,7 @@ int LuaStack::inUse(const lua_State* L) const { int res; StkId lim = top.p; - for (ci_iter = L->getCI(); ci_iter != NULL; ci_iter = ci_iter->getPrevious()) { + for (ci_iter = L->getCI(); ci_iter != nullptr; ci_iter = ci_iter->getPrevious()) { if (lim < ci_iter->topRef().p) lim = ci_iter->topRef().p; } @@ -168,10 +168,10 @@ void LuaStack::relPointers(lua_State* L) { top.offset = save(top.p); tbclist.offset = save(tbclist.p); - for (up = L->getOpenUpval(); up != NULL; up = up->getOpenNext()) + for (up = L->getOpenUpval(); up != nullptr; up = up->getOpenNext()) up->setOffset(save(up->getLevel())); - for (ci = L->getCI(); ci != NULL; ci = ci->getPrevious()) { + for (ci = L->getCI(); ci != nullptr; ci = ci->getPrevious()) { ci->topRef().offset = save(ci->topRef().p); ci->funcRef().offset = save(ci->funcRef().p); } @@ -189,10 +189,10 @@ void LuaStack::correctPointers(lua_State* L, StkId oldstack) { top.p = restore(top.offset); tbclist.p = restore(tbclist.offset); - for (up = L->getOpenUpval(); up != NULL; up = up->getOpenNext()) + for (up = L->getOpenUpval(); up != nullptr; up = up->getOpenNext()) up->setVP(s2v(restore(up->getOffset()))); - for (ci = L->getCI(); ci != NULL; ci = ci->getPrevious()) { + for (ci = L->getCI(); ci != nullptr; ci = ci->getPrevious()) { ci->topRef().p = restore(ci->topRef().offset); ci->funcRef().p = restore(ci->funcRef().offset); if (ci->isLua()) @@ -225,10 +225,10 @@ void LuaStack::correctPointers(lua_State* L, StkId oldstack) { top.p = top.p - oldstack + newstack; tbclist.p = tbclist.p - oldstack + newstack; - for (up = L->getOpenUpval(); up != NULL; up = up->getOpenNext()) + for (up = L->getOpenUpval(); up != nullptr; up = up->getOpenNext()) up->setVP(s2v(up->getLevel() - oldstack + newstack)); - for (ci = L->getCI(); ci != NULL; ci = ci->getPrevious()) { + for (ci = L->getCI(); ci != nullptr; ci = ci->getPrevious()) { ci->topRef().p = ci->topRef().p - oldstack + newstack; ci->funcRef().p = ci->funcRef().p - oldstack + newstack; if (ci->isLua()) @@ -266,7 +266,7 @@ int LuaStack::realloc(lua_State* L, int newsize, int raiseerror) { G(L)->setGCStopEm(oldgcstop); /* restore emergency collection */ - if (l_unlikely(newstack == NULL)) { /* reallocation failed? */ + if (l_unlikely(newstack == nullptr)) { /* reallocation failed? */ correctPointers(L, oldstack); /* change offsets back to pointers */ if (raiseerror) luaM_error(L); diff --git a/src/core/lstate.cpp b/src/core/lstate.cpp index 05bc59b6..0bcd57d4 100644 --- a/src/core/lstate.cpp +++ b/src/core/lstate.cpp @@ -80,13 +80,13 @@ void luaE_setdebt (global_State *g, l_mem debt) { CallInfo *luaE_extendCI (lua_State *L) { CallInfo *ci; - lua_assert(L->getCI()->getNext() == NULL); + lua_assert(L->getCI()->getNext() == nullptr); // Use placement new to call constructor (initializes all 9 fields) ci = new (luaM_malloc_(L, sizeof(CallInfo), 0)) CallInfo(); - lua_assert(L->getCI()->getNext() == NULL); + lua_assert(L->getCI()->getNext() == nullptr); L->getCI()->setNext(ci); ci->setPrevious(L->getCI()); - ci->setNext(NULL); + ci->setNext(nullptr); // trap already initialized to 0 in constructor, but keep this for clarity ci->getTrap() = 0; L->getNCIRef()++; @@ -100,8 +100,8 @@ CallInfo *luaE_extendCI (lua_State *L) { static void freeCI (lua_State *L) { CallInfo *ci = L->getCI(); CallInfo *next = ci->getNext(); - ci->setNext(NULL); - while ((ci = next) != NULL) { + ci->setNext(nullptr); + while ((ci = next) != nullptr) { next = ci->getNext(); luaM_free(L, ci); L->getNCIRef()--; @@ -116,14 +116,14 @@ static void freeCI (lua_State *L) { void luaE_shrinkCI (lua_State *L) { CallInfo *ci = L->getCI()->getNext(); /* first free CallInfo */ CallInfo *next; - if (ci == NULL) + if (ci == nullptr) return; /* no extra elements */ - while ((next = ci->getNext()) != NULL) { /* two extra elements? */ + while ((next = ci->getNext()) != nullptr) { /* two extra elements? */ CallInfo *next2 = next->getNext(); /* next's next */ ci->setNext(next2); /* remove next from the list */ L->getNCIRef()--; luaM_free(L, next); /* free next */ - if (next2 == NULL) + if (next2 == nullptr) break; /* no more elements */ else { next2->setPrevious(ci); @@ -160,7 +160,7 @@ static void resetCI (lua_State *L) { ci->funcRef().p = L->getStack().p; setnilvalue(s2v(ci->funcRef().p)); /* 'function' entry for basic 'ci' */ ci->topRef().p = ci->funcRef().p + 1 + LUA_MINSTACK; /* +1 for 'function' entry */ - ci->setK(NULL); + ci->setK(nullptr); ci->setCallStatus(CIST_C); L->setStatus(LUA_OK); L->setErrFunc(0); /* stack unwind can "throw away" the error function */ @@ -233,15 +233,15 @@ static void f_luaopen (lua_State *L, void *ud) { static void preinit_thread (lua_State *L, global_State *g) { L->init(g); // Initialize lua_State fields (preserves GC fields) L->resetHookCount(); // Initialize hookcount = basehookcount - L->getBaseCI()->setPrevious(NULL); - L->getBaseCI()->setNext(NULL); + L->getBaseCI()->setPrevious(nullptr); + L->getBaseCI()->setNext(nullptr); } lu_mem luaE_threadsize (lua_State *L) { lu_mem sz = static_cast(sizeof(LX)) + cast_uint(L->getNCI()) * sizeof(CallInfo); - if (L->getStack().p != NULL) + if (L->getStack().p != nullptr) sz += cast_uint(L->getStackSize() + EXTRA_STACK) * sizeof(StackValue); return sz; } @@ -295,7 +295,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { void luaE_freethread (lua_State *L, lua_State *L1) { LX *l = fromstate(L1); luaF_closeupval(L1, L1->getStack().p); /* close all upvalues */ - lua_assert(L1->getOpenUpval() == NULL); + lua_assert(L1->getOpenUpval() == nullptr); luai_userstatefree(L, L1); freestack(L1); luaM_free(L, l); @@ -332,38 +332,38 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { int i; lua_State *L; global_State *g = static_cast( - (*f)(ud, NULL, LUA_TTHREAD, sizeof(global_State))); - if (g == NULL) return NULL; + (*f)(ud, nullptr, LUA_TTHREAD, sizeof(global_State))); + if (g == nullptr) return nullptr; L = &g->getMainThread()->l; L->setType(LUA_VTHREAD); g->setCurrentWhite(bitmask(WHITE0BIT)); L->setMarked(g->getWhite()); preinit_thread(L, g); g->setAllGC(obj2gco(L)); /* by now, only object is the main thread */ - L->setNext(NULL); + L->setNext(nullptr); incnny(L); /* main thread is always non yieldable */ g->setFrealloc(f); g->setUd(ud); - g->setWarnF(NULL); - g->setUdWarn(NULL); + g->setWarnF(nullptr); + g->setUdWarn(nullptr); g->setSeed(seed); g->setGCStp(GCSTPGC); /* no GC while building state */ g->getStringTable()->setSize(0); g->getStringTable()->setNumElements(0); - g->getStringTable()->setHash(NULL); + g->getStringTable()->setHash(nullptr); setnilvalue(g->getRegistry()); - g->setPanic(NULL); + g->setPanic(nullptr); g->setGCState(GCState::Pause); g->setGCKind(GCKind::Incremental); g->setGCStopEm(0); g->setGCEmergency(0); - g->setFinObj(NULL); g->setToBeFnz(NULL); g->setFixedGC(NULL); - g->setFirstOld1(NULL); g->setSurvival(NULL); g->setOld1(NULL); g->setReallyOld(NULL); - g->setFinObjSur(NULL); g->setFinObjOld1(NULL); g->setFinObjROld(NULL); - g->setSweepGC(NULL); - g->setGray(NULL); g->setGrayAgain(NULL); - g->setWeak(NULL); g->setEphemeron(NULL); g->setAllWeak(NULL); - g->setTwups(NULL); + g->setFinObj(nullptr); g->setToBeFnz(nullptr); g->setFixedGC(nullptr); + g->setFirstOld1(nullptr); g->setSurvival(nullptr); g->setOld1(nullptr); g->setReallyOld(nullptr); + g->setFinObjSur(nullptr); g->setFinObjOld1(nullptr); g->setFinObjROld(nullptr); + g->setSweepGC(nullptr); + g->setGray(nullptr); g->setGrayAgain(nullptr); + g->setWeak(nullptr); g->setEphemeron(nullptr); g->setAllWeak(nullptr); + g->setTwups(nullptr); g->setGCTotalBytes(sizeof(global_State)); g->setGCMarked(0); g->setGCDebt(0); @@ -377,10 +377,10 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { for (i = 0; i < LUA_NUMTYPES; i++) { g->setMetatable(i, nullptr); } - if (L->rawRunProtected( f_luaopen, NULL) != LUA_OK) { + if (L->rawRunProtected( f_luaopen, nullptr) != LUA_OK) { /* memory allocation error: free partial state */ close_state(L); - L = NULL; + L = nullptr; } return L; } @@ -395,7 +395,7 @@ LUA_API void lua_close (lua_State *L) { void luaE_warning (lua_State *L, const char *msg, int tocont) { lua_WarnFunction wf = G(L)->getWarnF(); - if (wf != NULL) + if (wf != nullptr) wf(G(L)->getUdWarn(), msg, tocont); } diff --git a/src/core/lstate.h b/src/core/lstate.h index b10b9ad5..273b590e 100644 --- a/src/core/lstate.h +++ b/src/core/lstate.h @@ -43,12 +43,12 @@ typedef void (*Pfunc) (lua_State *L, void *ud); ** 'allgc' -> 'survival': new objects; ** 'survival' -> 'old': objects that survived one collection; ** 'old1' -> 'reallyold': objects that became old in last collection; -** 'reallyold' -> NULL: objects old for more than one cycle. +** 'reallyold' -> nullptr: objects old for more than one cycle. ** ** 'finobj' -> 'finobjsur': new objects marked for finalization; ** 'finobjsur' -> 'finobjold1': survived """"; ** 'finobjold1' -> 'finobjrold': just old """"; -** 'finobjrold' -> NULL: really old """". +** 'finobjrold' -> nullptr: really old """". ** ** All lists can contain elements older than their main ages, due ** to 'luaC_checkfinalizer' and 'udata2finalize', which move diff --git a/src/core/ltm.cpp b/src/core/ltm.cpp index 067a9a0a..c64845af 100644 --- a/src/core/ltm.cpp +++ b/src/core/ltm.cpp @@ -62,7 +62,7 @@ const TValue *luaT_gettm (const Table *events, TMS event, TString *ename) { lua_assert(event <= TMS::TM_EQ); if (notm(tm)) { /* no tag method? */ events->setFlagBits(1 << static_cast(event)); /* cache this fact (flags is mutable) */ - return NULL; + return nullptr; } else return tm; } @@ -90,8 +90,8 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { */ const char *luaT_objtypename (lua_State *L, const TValue *o) { Table *mt; - if ((ttistable(o) && (mt = hvalue(o)->getMetatable()) != NULL) || - (ttisfulluserdata(o) && (mt = uvalue(o)->getMetatable()) != NULL)) { + if ((ttistable(o) && (mt = hvalue(o)->getMetatable()) != nullptr) || + (ttisfulluserdata(o) && (mt = uvalue(o)->getMetatable()) != nullptr)) { const TValue *name = luaH_Hgetshortstr(mt, luaS_new(L, "__name")); if (ttisstring(name)) /* is '__name' a string? */ return getstr(tsvalue(name)); /* use it as type name */ diff --git a/src/interpreter/lua.cpp b/src/interpreter/lua.cpp index a3f0d259..f6e4c4b4 100644 --- a/src/interpreter/lua.cpp +++ b/src/interpreter/lua.cpp @@ -33,7 +33,7 @@ #define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX -static lua_State *globalL = NULL; +static lua_State *globalL = nullptr; static const char *progname = LUA_PROGNAME; @@ -48,7 +48,7 @@ static void setsignal (int sig, void (*handler)(int)) { sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); /* do not mask any signal */ - sigaction(sig, &sa, NULL); + sigaction(sig, &sa, nullptr); } #else /* }{ */ @@ -63,7 +63,7 @@ static void setsignal (int sig, void (*handler)(int)) { */ static void lstop (lua_State *L, lua_Debug *ar) { (void)ar; /* unused arg. */ - lua_sethook(L, NULL, 0, 0); /* reset hook */ + lua_sethook(L, nullptr, 0, 0); /* reset hook */ luaL_error(L, "interrupted!"); } @@ -121,7 +121,7 @@ static void l_message (const char *pname, const char *msg) { static int report (lua_State *L, int status) { if (status != LUA_OK) { const char *msg = lua_tostring(L, -1); - if (msg == NULL) + if (msg == nullptr) msg = "(error message not a string)"; l_message(progname, msg); lua_pop(L, 1); /* remove message */ @@ -135,7 +135,7 @@ static int report (lua_State *L, int status) { */ static int msghandler (lua_State *L) { const char *msg = lua_tostring(L, 1); - if (msg == NULL) { /* is error object not a string? */ + if (msg == nullptr) { /* is error object not a string? */ if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */ return 1; /* that is the message */ @@ -217,9 +217,9 @@ static int dostring (lua_State *L, const char *s, const char *name) { */ static int dolibrary (lua_State *L, char *globname) { int status; - char *suffix = NULL; + char *suffix = nullptr; char *modname = strchr(globname, '='); - if (modname == NULL) { /* no explicit name? */ + if (modname == nullptr) { /* no explicit name? */ modname = globname; /* module name is equal to global name */ suffix = strchr(modname, *LUA_IGMARK); /* look for a suffix mark */ } @@ -231,7 +231,7 @@ static int dolibrary (lua_State *L, char *globname) { lua_pushstring(L, modname); status = docall(L, 1, 1); /* call 'require(modname)' */ if (status == LUA_OK) { - if (suffix != NULL) /* is there a suffix mark? */ + if (suffix != nullptr) /* is there a suffix mark? */ *suffix = '\0'; /* remove suffix from global name */ lua_setglobal(L, globname); /* globname = require(modname) */ } @@ -259,7 +259,7 @@ static int handle_script (lua_State *L, char **argv) { int status; const char *fname = argv[0]; if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) - fname = NULL; /* stdin */ + fname = nullptr; /* stdin */ status = luaL_loadfile(L, fname); if (status == LUA_OK) { int n = pushargs(L); /* push arguments to script */ @@ -287,7 +287,7 @@ static int handle_script (lua_State *L, char **argv) { static int collectargs (char **argv, int *first) { int args = 0; int i; - if (argv[0] != NULL) { /* is there a program name? */ + if (argv[0] != nullptr) { /* is there a program name? */ if (argv[0][0]) /* not empty? */ progname = argv[0]; /* save it */ } @@ -295,7 +295,7 @@ static int collectargs (char **argv, int *first) { *first = -1; return 0; } - for (i = 1; argv[i] != NULL; i++) { /* handle arguments */ + for (i = 1; argv[i] != nullptr; i++) { /* handle arguments */ *first = i; if (argv[i][0] != '-') /* not an option? */ return args; /* stop handling options */ @@ -304,7 +304,7 @@ static int collectargs (char **argv, int *first) { if (argv[i][2] != '\0') /* extra characters after '--'? */ return has_error; /* invalid option */ /* if there is a script name, it comes after '--' */ - *first = (argv[i + 1] != NULL) ? i + 1 : 0; + *first = (argv[i + 1] != nullptr) ? i + 1 : 0; return args; case '\0': /* '-' */ return args; /* script "name" is '-' */ @@ -329,7 +329,7 @@ static int collectargs (char **argv, int *first) { case 'l': /* both options need an argument */ if (argv[i][2] == '\0') { /* no concatenated argument? */ i++; /* try next 'argv' */ - if (argv[i] == NULL || argv[i][0] == '-') + if (argv[i] == nullptr || argv[i][0] == '-') return has_error; /* no next argument or it is another option */ } break; @@ -357,7 +357,7 @@ static int runargs (lua_State *L, char **argv, int n) { int status; char *extra = argv[i] + 2; /* both options need an argument */ if (*extra == '\0') extra = argv[++i]; - lua_assert(extra != NULL); + lua_assert(extra != nullptr); status = (option == 'e') ? dostring(L, extra, "=(command line)") : dolibrary(L, extra); @@ -376,11 +376,11 @@ static int runargs (lua_State *L, char **argv, int n) { static int handle_luainit (lua_State *L) { const char *name = "=" LUA_INITVARVERSION; const char *init = getenv(name + 1); - if (init == NULL) { + if (init == nullptr) { name = "=" LUA_INIT_VAR; init = getenv(name + 1); /* try alternative name */ } - if (init == NULL) return LUA_OK; + if (init == nullptr) return LUA_OK; else if (init[0] == '@') return dofile(L, init+1); else @@ -459,15 +459,15 @@ static int handle_luainit (lua_State *L) { /* pointer to 'readline' function (if any) */ typedef char *(*l_readlineT) (const char *prompt); -static l_readlineT l_readline = NULL; +static l_readlineT l_readline = nullptr; /* pointer to 'add_history' function (if any) */ typedef void (*l_addhistT) (const char *string); -static l_addhistT l_addhist = NULL; +static l_addhistT l_addhist = nullptr; static char *lua_readline (char *buff, const char *prompt) { - if (l_readline != NULL) /* is there a 'readline'? */ + if (l_readline != nullptr) /* is there a 'readline'? */ return (*l_readline)(prompt); /* use it */ else { /* emulate 'readline' over 'buff' */ fputs(prompt, stdout); @@ -478,14 +478,14 @@ static char *lua_readline (char *buff, const char *prompt) { static void lua_saveline (const char *line) { - if (l_addhist != NULL) /* is there an 'add_history'? */ + if (l_addhist != nullptr) /* is there an 'add_history'? */ (*l_addhist)(line); /* use it */ /* else nothing to be done */ } static void lua_freeline (char *line) { - if (l_readline != NULL) /* is there a 'readline'? */ + if (l_readline != nullptr) /* is there a 'readline'? */ free(line); /* free line created by it */ /* else 'lua_readline' used an automatic buffer; nothing to free */ } @@ -498,15 +498,15 @@ static void lua_freeline (char *line) { static void lua_initreadline (lua_State *L) { void *lib = dlopen(LUA_READLINELIB, RTLD_NOW | RTLD_LOCAL); - if (lib == NULL) + if (lib == nullptr) lua_warning(L, "library '" LUA_READLINELIB "' not found", 0); else { const char **name = static_cast(dlsym(lib, "rl_readline_name")); - if (name != NULL) + if (name != nullptr) *name = "lua"; l_readline = reinterpret_cast(cast_func(dlsym(lib, "readline"))); l_addhist = reinterpret_cast(cast_func(dlsym(lib, "add_history"))); - if (l_readline == NULL) + if (l_readline == nullptr) lua_warning(L, "unable to load 'readline'", 0); } } @@ -514,7 +514,7 @@ static void lua_initreadline (lua_State *L) { #else /* }{ */ /* no dlopen or LUA_READLINELIB undefined */ -/* Leave pointers with NULL */ +/* Leave pointers with nullptr */ #define lua_initreadline(L) ((void)L) #endif /* } */ @@ -533,7 +533,7 @@ static const char *get_prompt (lua_State *L, int firstline) { if (lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2") == LUA_TNIL) return (firstline ? LUA_PROMPT : LUA_PROMPT2); /* use the default */ else { /* apply 'tostring' over the value */ - const char *p = luaL_tolstring(L, -1, NULL); + const char *p = luaL_tolstring(L, -1, nullptr); lua_remove(L, -2); /* remove original value */ return p; } @@ -569,7 +569,7 @@ static int pushline (lua_State *L, int firstline) { const char *prmt = get_prompt(L, firstline); char *b = lua_readline(buffer, prmt); lua_pop(L, 1); /* remove prompt */ - if (b == NULL) + if (b == nullptr) return 0; /* no input */ l = strlen(b); if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ @@ -601,7 +601,7 @@ static void checklocal (const char *line) { static const char space[] = " \t"; line += strspn(line, space); /* skip spaces */ if (strncmp(line, "local", szloc) == 0 && /* "local"? */ - strchr(space, *(line + szloc)) != NULL) { /* followed by a space? */ + strchr(space, *(line + szloc)) != nullptr) { /* followed by a space? */ lua_writestringerror("%s\n", "warning: locals do not survive across lines in interactive mode"); } @@ -676,7 +676,7 @@ static void l_print (lua_State *L) { static void doREPL (lua_State *L) { int status; const char *oldprogname = progname; - progname = NULL; /* no 'progname' on errors in interactive mode */ + progname = nullptr; /* no 'progname' on errors in interactive mode */ lua_initreadline(L); while ((status = loadline(L)) != -1) { if (status == LUA_OK) @@ -739,7 +739,7 @@ static int pmain (lua_State *L) { doREPL(L); /* do read-eval-print loop */ } else - dofile(L, NULL); /* executes stdin as a file */ + dofile(L, nullptr); /* executes stdin as a file */ } lua_pushboolean(L, 1); /* signal no errors */ return 1; @@ -749,7 +749,7 @@ static int pmain (lua_State *L) { int main (int argc, char **argv) { int status, result; lua_State *L = luaL_newstate(); /* create state */ - if (L == NULL) { + if (L == nullptr) { l_message(argv[0], "cannot create state: not enough memory"); return EXIT_FAILURE; } diff --git a/src/libraries/lbaselib.cpp b/src/libraries/lbaselib.cpp index c1724ec6..33991614 100644 --- a/src/libraries/lbaselib.cpp +++ b/src/libraries/lbaselib.cpp @@ -65,12 +65,12 @@ static const char *b_str2int (const char *s, unsigned base, lua_Integer *pn) { if (*s == '-') { s++; neg = 1; } /* handle sign */ else if (*s == '+') s++; if (!isalnum(cast_uchar(*s))) /* no digit? */ - return NULL; + return nullptr; do { unsigned digit = cast_uint(isdigit(cast_uchar(*s)) ? *s - '0' : (toupper(cast_uchar(*s)) - 'A') + 10); - if (digit >= base) return NULL; /* invalid numeral */ + if (digit >= base) return nullptr; /* invalid numeral */ n = n * base + digit; s++; } while (isalnum(cast_uchar(*s))); @@ -89,7 +89,7 @@ static int luaB_tonumber (lua_State *L) { else { size_t l; const char *s = lua_tolstring(L, 1, &l); - if (s != NULL && lua_stringtonumber(L, s) == l + 1) + if (s != nullptr && lua_stringtonumber(L, s) == l + 1) return 1; /* successful conversion to number */ /* else not a number */ luaL_checkany(L, 1); /* (but there must be some parameter) */ @@ -201,7 +201,7 @@ static int pushmode (lua_State *L, int oldmode) { static int luaB_collectgarbage (lua_State *L) { static const char *const opts[] = {"stop", "restart", "collect", "count", "step", "isrunning", "generational", "incremental", - "param", NULL}; + "param", nullptr}; static const char optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCSTEP, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC, LUA_GCPARAM}; @@ -236,11 +236,11 @@ static int luaB_collectgarbage (lua_State *L) { case LUA_GCPARAM: { static const char *const params[] = { "minormul", "majorminor", "minormajor", - "pause", "stepmul", "stepsize", NULL}; + "pause", "stepmul", "stepsize", nullptr}; static const char pnum[] = { LUA_GCPMINORMUL, LUA_GCPMAJORMINOR, LUA_GCPMINORMAJOR, LUA_GCPPAUSE, LUA_GCPSTEPMUL, LUA_GCPSTEPSIZE}; - int p = pnum[luaL_checkoption(L, 2, NULL, params)]; + int p = pnum[luaL_checkoption(L, 2, nullptr, params)]; lua_Integer value = luaL_optinteger(L, 3, -1); lua_pushinteger(L, lua_gc(L, o, p, (int)value)); return 1; @@ -340,14 +340,14 @@ static int load_aux (lua_State *L, int status, int envidx) { static const char *getMode (lua_State *L, int idx) { const char *mode = luaL_optstring(L, idx, "bt"); - if (strchr(mode, 'B') != NULL) /* Lua code cannot use fixed buffers */ + if (strchr(mode, 'B') != nullptr) /* Lua code cannot use fixed buffers */ luaL_argerror(L, idx, "invalid mode"); return mode; } static int luaB_loadfile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); + const char *fname = luaL_optstring(L, 1, nullptr); const char *mode = getMode(L, 2); int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ int status = luaL_loadfilex(L, fname, mode); @@ -384,7 +384,7 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { if (lua_isnil(L, -1)) { lua_pop(L, 1); /* pop result */ *size = 0; - return NULL; + return nullptr; } else if (l_unlikely(!lua_isstring(L, -1))) luaL_error(L, "reader function must return a string"); @@ -399,7 +399,7 @@ static int luaB_load (lua_State *L) { const char *s = lua_tolstring(L, 1, &l); const char *mode = getMode(L, 3); int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */ - if (s != NULL) { /* loading a string? */ + if (s != nullptr) { /* loading a string? */ const char *chunkname = luaL_optstring(L, 2, s); status = luaL_loadbufferx(L, s, l, chunkname, mode); } @@ -407,7 +407,7 @@ static int luaB_load (lua_State *L) { const char *chunkname = luaL_optstring(L, 2, "=(load)"); luaL_checktype(L, 1, LUA_TFUNCTION); lua_settop(L, RESERVEDSLOT); /* create reserved slot */ - status = lua_load(L, generic_reader, NULL, chunkname, mode); + status = lua_load(L, generic_reader, nullptr, chunkname, mode); } return load_aux(L, status, env); } @@ -422,7 +422,7 @@ static int dofilecont (lua_State *L, int d1, lua_KContext d2) { static int luaB_dofile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); + const char *fname = luaL_optstring(L, 1, nullptr); lua_settop(L, 1); if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK)) return lua_error(L); @@ -507,7 +507,7 @@ static int luaB_xpcall (lua_State *L) { static int luaB_tostring (lua_State *L) { luaL_checkany(L, 1); - luaL_tolstring(L, 1, NULL); + luaL_tolstring(L, 1, nullptr); return 1; } @@ -537,9 +537,9 @@ static const luaL_Reg base_funcs[] = { {"type", luaB_type}, {"xpcall", luaB_xpcall}, /* placeholders */ - {LUA_GNAME, NULL}, - {"_VERSION", NULL}, - {NULL, NULL} + {LUA_GNAME, nullptr}, + {"_VERSION", nullptr}, + {nullptr, nullptr} }; diff --git a/src/libraries/lcorolib.cpp b/src/libraries/lcorolib.cpp index ff66a70d..b9e97cc3 100644 --- a/src/libraries/lcorolib.cpp +++ b/src/libraries/lcorolib.cpp @@ -211,7 +211,7 @@ static const luaL_Reg co_funcs[] = { {"yield", luaB_yield}, {"isyieldable", luaB_yieldable}, {"close", luaB_close}, - {NULL, NULL} + {nullptr, nullptr} }; diff --git a/src/libraries/ldblib.cpp b/src/libraries/ldblib.cpp index d36b7de7..f54a350e 100644 --- a/src/libraries/ldblib.cpp +++ b/src/libraries/ldblib.cpp @@ -209,7 +209,7 @@ static int db_getlocal (lua_State *L) { int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ if (lua_isfunction(L, arg + 1)) { /* function argument? */ lua_pushvalue(L, arg + 1); /* push function */ - lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ + lua_pushstring(L, lua_getlocal(L, nullptr, nvar)); /* push local name */ return 1; /* return only name (there is no value) */ } else { /* stack-level argument */ @@ -248,7 +248,7 @@ static int db_setlocal (lua_State *L) { checkstack(L, L1, 1); lua_xmove(L, L1, 1); name = lua_setlocal(L1, &ar, nvar); - if (name == NULL) + if (name == nullptr) lua_pop(L1, 1); /* pop value (if not popped by 'lua_setlocal') */ lua_pushstring(L, name); return 1; @@ -263,7 +263,7 @@ static int auxupvalue (lua_State *L, int get) { int n = (int)luaL_checkinteger(L, 2); /* upvalue index */ luaL_checktype(L, 1, LUA_TFUNCTION); /* closure */ name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); - if (name == NULL) return 0; + if (name == nullptr) return 0; lua_pushstring(L, name); lua_insert(L, -(get+1)); /* no-op if get is false */ return get + 1; @@ -291,7 +291,7 @@ static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ id = lua_upvalueid(L, argf, nup); if (pnup) { - luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index"); + luaL_argcheck(L, id != nullptr, argnup, "invalid upvalue index"); *pnup = nup; } return id; @@ -299,8 +299,8 @@ static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { static int db_upvalueid (lua_State *L) { - void *id = checkupval(L, 1, 2, NULL); - if (id != NULL) + void *id = checkupval(L, 1, 2, nullptr); + if (id != nullptr) lua_pushlightuserdata(L, id); else luaL_pushfail(L); @@ -371,7 +371,7 @@ static int db_sethook (lua_State *L) { lua_State *L1 = getthread(L, &arg); if (lua_isnoneornil(L, arg+1)) { /* no hook? */ lua_settop(L, arg+1); - func = NULL; mask = 0; count = 0; /* turn off hooks */ + func = nullptr; mask = 0; count = 0; /* turn off hooks */ } else { const char *smask = luaL_checkstring(L, arg+2); @@ -401,7 +401,7 @@ static int db_gethook (lua_State *L) { char buff[5]; int mask = lua_gethookmask(L1); lua_Hook hook = lua_gethook(L1); - if (hook == NULL) { /* no hook? */ + if (hook == nullptr) { /* no hook? */ luaL_pushfail(L); return 1; } @@ -424,12 +424,12 @@ static int db_debug (lua_State *L) { for (;;) { char buffer[250]; lua_writestringerror("%s", "lua_debug> "); - if (fgets(buffer, sizeof(buffer), stdin) == NULL || + if (fgets(buffer, sizeof(buffer), stdin) == nullptr || strcmp(buffer, "cont\n") == 0) return 0; if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || lua_pcall(L, 0, 0, 0)) - lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); + lua_writestringerror("%s\n", luaL_tolstring(L, -1, nullptr)); lua_settop(L, 0); /* remove eventual returns */ } } @@ -439,7 +439,7 @@ static int db_traceback (lua_State *L) { int arg; lua_State *L1 = getthread(L, &arg); const char *msg = lua_tostring(L, arg + 1); - if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */ + if (msg == nullptr && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */ lua_pushvalue(L, arg + 1); /* return it untouched */ else { int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0); @@ -466,7 +466,7 @@ static const luaL_Reg dblib[] = { {"setmetatable", db_setmetatable}, {"setupvalue", db_setupvalue}, {"traceback", db_traceback}, - {NULL, NULL} + {nullptr, nullptr} }; diff --git a/src/libraries/liolib.cpp b/src/libraries/liolib.cpp index 4e00e539..d5dcd311 100644 --- a/src/libraries/liolib.cpp +++ b/src/libraries/liolib.cpp @@ -37,7 +37,7 @@ /* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ static int l_checkmode (const char *mode) { - return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && + return (*mode != '\0' && strchr("rwa", *(mode++)) != nullptr && (*mode != '+' || ((void)(++mode), 1)) && /* skip if char is '+' */ (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */ } @@ -55,7 +55,7 @@ static int l_checkmode (const char *mode) { #if defined(LUA_USE_POSIX) /* { */ -#define l_popen(L,c,m) (fflush(NULL), popen(c,m)) +#define l_popen(L,c,m) (fflush(nullptr), popen(c,m)) #define l_pclose(L,file) (pclose(file)) #elif defined(LUA_USE_WINDOWS) /* }{ */ @@ -156,14 +156,14 @@ typedef luaL_Stream LStream; #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE)) -#define isclosed(p) ((p)->closef == NULL) +#define isclosed(p) ((p)->closef == nullptr) static int io_type (lua_State *L) { LStream *p; luaL_checkany(L, 1); p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE); - if (p == NULL) + if (p == nullptr) luaL_pushfail(L); /* not a file */ else if (isclosed(p)) lua_pushliteral(L, "closed file"); @@ -199,7 +199,7 @@ static FILE *tofile (lua_State *L) { */ static LStream *newprefile (lua_State *L) { LStream *p = (LStream *)lua_newuserdatauv(L, sizeof(LStream), 0); - p->closef = NULL; /* mark file handle as 'closed' */ + p->closef = nullptr; /* mark file handle as 'closed' */ luaL_setmetatable(L, LUA_FILEHANDLE); return p; } @@ -213,7 +213,7 @@ static LStream *newprefile (lua_State *L) { static int aux_close (lua_State *L) { LStream *p = tolstream(L); volatile lua_CFunction cf = p->closef; - p->closef = NULL; /* mark stream as closed */ + p->closef = nullptr; /* mark stream as closed */ return (*cf)(L); /* close it */ } @@ -233,7 +233,7 @@ static int io_close (lua_State *L) { static int f_gc (lua_State *L) { LStream *p = tolstream(L); - if (!isclosed(p) && p->f != NULL) + if (!isclosed(p) && p->f != nullptr) aux_close(L); /* ignore closed and incompletely open files */ return 0; } @@ -245,13 +245,13 @@ static int f_gc (lua_State *L) { static int io_fclose (lua_State *L) { LStream *p = tolstream(L); errno = 0; - return luaL_fileresult(L, (fclose(p->f) == 0), NULL); + return luaL_fileresult(L, (fclose(p->f) == 0), nullptr); } static LStream *newfile (lua_State *L) { LStream *p = newprefile(L); - p->f = NULL; + p->f = nullptr; p->closef = &io_fclose; return p; } @@ -260,7 +260,7 @@ static LStream *newfile (lua_State *L) { static void opencheck (lua_State *L, const char *fname, const char *mode) { LStream *p = newfile(L); p->f = fopen(fname, mode); - if (l_unlikely(p->f == NULL)) + if (l_unlikely(p->f == nullptr)) luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); } @@ -273,7 +273,7 @@ static int io_open (lua_State *L) { luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); errno = 0; p->f = fopen(filename, mode); - return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; + return (p->f == nullptr) ? luaL_fileresult(L, 0, filename) : 1; } @@ -295,7 +295,7 @@ static int io_popen (lua_State *L) { errno = 0; p->f = l_popen(L, filename, mode); p->closef = &io_pclose; - return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; + return (p->f == nullptr) ? luaL_fileresult(L, 0, filename) : 1; } @@ -303,7 +303,7 @@ static int io_tmpfile (lua_State *L) { LStream *p = newfile(L); errno = 0; p->f = tmpfile(); - return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; + return (p->f == nullptr) ? luaL_fileresult(L, 0, nullptr) : 1; } @@ -607,7 +607,7 @@ static int g_read (lua_State *L, FILE *f, int first) { } } if (ferror(f)) - return luaL_fileresult(L, 0, NULL); + return luaL_fileresult(L, 0, nullptr); if (!success) { lua_pop(L, 1); /* remove last result */ luaL_pushfail(L); /* push nil instead */ @@ -678,7 +678,7 @@ static int g_write (lua_State *L, FILE *f, int arg) { numbytes = fwrite(s, sizeof(char), len, f); totalbytes += numbytes; if (numbytes < len) { /* write error? */ - int n = luaL_fileresult(L, 0, NULL); + int n = luaL_fileresult(L, 0, nullptr); lua_pushinteger(L, cast_st2S(totalbytes)); return n + 1; /* return fail, error msg., error code, and counter */ } @@ -701,7 +701,7 @@ static int f_write (lua_State *L) { static int f_seek (lua_State *L) { static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; - static const char *const modenames[] = {"set", "cur", "end", NULL}; + static const char *const modenames[] = {"set", "cur", "end", nullptr}; FILE *f = tofile(L); int op = luaL_checkoption(L, 2, "cur", modenames); lua_Integer p3 = luaL_optinteger(L, 3, 0); @@ -711,7 +711,7 @@ static int f_seek (lua_State *L) { errno = 0; op = l_fseek(f, offset, mode[op]); if (l_unlikely(op)) - return luaL_fileresult(L, 0, NULL); /* error */ + return luaL_fileresult(L, 0, nullptr); /* error */ else { lua_pushinteger(L, (lua_Integer)l_ftell(f)); return 1; @@ -721,20 +721,20 @@ static int f_seek (lua_State *L) { static int f_setvbuf (lua_State *L) { static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; - static const char *const modenames[] = {"no", "full", "line", NULL}; + static const char *const modenames[] = {"no", "full", "line", nullptr}; FILE *f = tofile(L); - int op = luaL_checkoption(L, 2, NULL, modenames); + int op = luaL_checkoption(L, 2, nullptr, modenames); lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); int res; errno = 0; - res = setvbuf(f, NULL, mode[op], (size_t)sz); - return luaL_fileresult(L, res == 0, NULL); + res = setvbuf(f, nullptr, mode[op], (size_t)sz); + return luaL_fileresult(L, res == 0, nullptr); } static int aux_flush (lua_State *L, FILE *f) { errno = 0; - return luaL_fileresult(L, fflush(f) == 0, NULL); + return luaL_fileresult(L, fflush(f) == 0, nullptr); } @@ -763,7 +763,7 @@ static const luaL_Reg iolib[] = { {"tmpfile", io_tmpfile}, {"type", io_type}, {"write", io_write}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -778,7 +778,7 @@ static const luaL_Reg meth[] = { {"seek", f_seek}, {"close", f_close}, {"setvbuf", f_setvbuf}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -786,11 +786,11 @@ static const luaL_Reg meth[] = { ** metamethods for file handles */ static const luaL_Reg metameth[] = { - {"__index", NULL}, /* placeholder */ + {"__index", nullptr}, /* placeholder */ {"__gc", f_gc}, {"__close", f_gc}, {"__tostring", f_tostring}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -821,7 +821,7 @@ static void createstdfile (lua_State *L, FILE *f, const char *k, LStream *p = newprefile(L); p->f = f; p->closef = &io_noclose; - if (k != NULL) { + if (k != nullptr) { lua_pushvalue(L, -1); lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */ } @@ -835,7 +835,7 @@ LUAMOD_API int luaopen_io (lua_State *L) { /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); - createstdfile(L, stderr, NULL, "stderr"); + createstdfile(L, stderr, nullptr, "stderr"); return 1; } diff --git a/src/libraries/lmathlib.cpp b/src/libraries/lmathlib.cpp index f5a5db69..57cf0699 100644 --- a/src/libraries/lmathlib.cpp +++ b/src/libraries/lmathlib.cpp @@ -647,7 +647,7 @@ static int math_randomseed (lua_State *L) { static const luaL_Reg randfuncs[] = { {"random", math_random}, {"randomseed", math_randomseed}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -736,13 +736,13 @@ static const luaL_Reg mathlib[] = { {"log10", math_log10}, #endif /* placeholders */ - {"random", NULL}, - {"randomseed", NULL}, - {"pi", NULL}, - {"huge", NULL}, - {"maxinteger", NULL}, - {"mininteger", NULL}, - {NULL, NULL} + {"random", nullptr}, + {"randomseed", nullptr}, + {"pi", nullptr}, + {"huge", nullptr}, + {"maxinteger", nullptr}, + {"mininteger", nullptr}, + {nullptr, nullptr} }; diff --git a/src/libraries/loadlib.cpp b/src/libraries/loadlib.cpp index e472a293..10980e20 100644 --- a/src/libraries/loadlib.cpp +++ b/src/libraries/loadlib.cpp @@ -75,14 +75,14 @@ static void lsys_unloadlib (void *lib); /* ** load C library in file 'path'. If 'seeglb', load with all names in ** the library global. -** Returns the library; in case of error, returns NULL plus an +** Returns the library; in case of error, returns nullptr plus an ** error string in the stack. */ static void *lsys_load (lua_State *L, const char *path, int seeglb); /* ** Try to find a function named 'sym' in library 'lib'. -** Returns the function; in case of error, returns NULL plus an +** Returns the function; in case of error, returns nullptr plus an ** error string in the stack. */ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym); @@ -108,7 +108,7 @@ static void lsys_unloadlib (void *lib) { static void *lsys_load (lua_State *L, const char *path, int seeglb) { void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL)); - if (l_unlikely(lib == NULL)) + if (l_unlikely(lib == nullptr)) lua_pushstring(L, dlerror()); return lib; } @@ -116,7 +116,7 @@ static void *lsys_load (lua_State *L, const char *path, int seeglb) { static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { lua_CFunction f = cast_Lfunc(dlsym(lib, sym)); - if (l_unlikely(f == NULL)) + if (l_unlikely(f == nullptr)) lua_pushstring(L, dlerror()); return f; } @@ -154,8 +154,8 @@ static void setprogdir (lua_State *L) { char buff[MAX_PATH + 1]; char *lb; DWORD nsize = sizeof(buff)/sizeof(char); - DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */ - if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + DWORD n = GetModuleFileNameA(nullptr, buff, nsize); /* get exec. name */ + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == nullptr) luaL_error(L, "unable to get ModuleFileName"); else { *lb = '\0'; /* cut name on the last '\\' to get the path */ @@ -171,7 +171,7 @@ static void pusherror (lua_State *L) { int error = GetLastError(); char buffer[128]; if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL)) + nullptr, error, 0, buffer, sizeof(buffer)/sizeof(char), nullptr)) lua_pushstring(L, buffer); else lua_pushfstring(L, "system error %d\n", error); @@ -183,16 +183,16 @@ static void lsys_unloadlib (void *lib) { static void *lsys_load (lua_State *L, const char *path, int seeglb) { - HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS); + HMODULE lib = LoadLibraryExA(path, nullptr, LUA_LLE_FLAGS); (void)(seeglb); /* not used: symbols are 'global' by default */ - if (lib == NULL) pusherror(L); + if (lib == nullptr) pusherror(L); return lib; } static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { lua_CFunction f = cast_Lfunc(GetProcAddress((HMODULE)lib, sym)); - if (f == NULL) pusherror(L); + if (f == nullptr) pusherror(L); return f; } @@ -221,14 +221,14 @@ static void lsys_unloadlib (void *lib) { static void *lsys_load (lua_State *L, const char *path, int seeglb) { (void)(path); (void)(seeglb); /* not used */ lua_pushliteral(L, DLMSG); - return NULL; + return nullptr; } static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { (void)(lib); (void)(sym); /* not used */ lua_pushliteral(L, DLMSG); - return NULL; + return nullptr; } /* }====================================================== */ @@ -277,11 +277,11 @@ static void setpath (lua_State *L, const char *fieldname, const char *dftmark; const char *nver = lua_pushfstring(L, "%s%s", envname, LUA_VERSUFFIX); const char *path = getenv(nver); /* try versioned name */ - if (path == NULL) /* no versioned environment variable? */ + if (path == nullptr) /* no versioned environment variable? */ path = getenv(envname); /* try unversioned name */ - if (path == NULL || noenv(L)) /* no environment variable? */ - lua_pushexternalstring(L, dft, strlen(dft), NULL, NULL); /* use default */ - else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL) + if (path == nullptr || noenv(L)) /* no environment variable? */ + lua_pushexternalstring(L, dft, strlen(dft), nullptr, nullptr); /* use default */ + else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == nullptr) lua_pushstring(L, path); /* nothing to change */ else { /* path contains a ";;": insert default path in its place */ size_t len = strlen(path); @@ -337,7 +337,7 @@ static void *freelib (void *ud, void *ptr, size_t osize, size_t nsize) { /* string itself is irrelevant and static */ (void)ptr; (void)osize; (void)nsize; lsys_unloadlib(ud); /* unload library represented by the string */ - return NULL; + return nullptr; } @@ -383,9 +383,9 @@ static void addtoclib (lua_State *L, const char *path, void *plib) { */ static int lookforfunc (lua_State *L, const char *path, const char *sym) { void *reg = checkclib(L, path); /* check loaded C libraries */ - if (reg == NULL) { /* must load library? */ + if (reg == nullptr) { /* must load library? */ reg = lsys_load(L, path, *sym == '*'); /* global symbols if 'sym'=='*' */ - if (reg == NULL) return ERRLIB; /* unable to load library */ + if (reg == nullptr) return ERRLIB; /* unable to load library */ addtoclib(L, path, reg); } if (*sym == '*') { /* loading only library (no function)? */ @@ -394,7 +394,7 @@ static int lookforfunc (lua_State *L, const char *path, const char *sym) { } else { lua_CFunction f = lsys_sym(L, reg, sym); - if (f == NULL) + if (f == nullptr) return ERRFUNC; /* unable to find function */ lua_pushcfunction(L, f); /* else create new function */ return 0; /* no errors */ @@ -427,7 +427,7 @@ static int ll_loadlib (lua_State *L) { static int readable (const char *filename) { FILE *f = fopen(filename, "r"); /* try to open file */ - if (f == NULL) return 0; /* open failed */ + if (f == nullptr) return 0; /* open failed */ fclose(f); return 1; } @@ -436,19 +436,19 @@ static int readable (const char *filename) { /* ** Get the next name in '*path' = 'name1;name2;name3;...', changing ** the ending ';' to '\0' to create a zero-terminated string. Return -** NULL when list ends. +** nullptr when list ends. */ static const char *getnextfilename (char **path, char *end) { char *sep; char *name = *path; if (name == end) - return NULL; /* no more names */ + return nullptr; /* no more names */ else if (*name == '\0') { /* from previous iteration? */ *name = *LUA_PATH_SEP; /* restore separator */ name++; /* skip it */ } sep = strchr(name, *LUA_PATH_SEP); /* find next separator */ - if (sep == NULL) /* separator not found? */ + if (sep == nullptr) /* separator not found? */ sep = end; /* name goes until the end */ *sep = '\0'; /* finish file name */ *path = sep; /* will start next search from here */ @@ -481,7 +481,7 @@ static const char *searchpath (lua_State *L, const char *name, char *endpathname; /* its end */ const char *filename; /* separator is non-empty and appears in 'name'? */ - if (*sep != '\0' && strchr(name, *sep) != NULL) + if (*sep != '\0' && strchr(name, *sep) != nullptr) name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */ luaL_buffinit(L, &buff); /* add path to the buffer, replacing marks ('?') with the file name */ @@ -489,13 +489,13 @@ static const char *searchpath (lua_State *L, const char *name, luaL_addchar(&buff, '\0'); pathname = luaL_buffaddr(&buff); /* writable list of file names */ endpathname = pathname + luaL_bufflen(&buff) - 1; - while ((filename = getnextfilename(&pathname, endpathname)) != NULL) { + while ((filename = getnextfilename(&pathname, endpathname)) != nullptr) { if (readable(filename)) /* does file exist and is readable? */ return lua_pushstring(L, filename); /* save and return name */ } luaL_pushresult(&buff); /* push path to create error message */ pusherrornotfound(L, lua_tostring(L, -1)); /* create error message */ - return NULL; /* not found */ + return nullptr; /* not found */ } @@ -504,7 +504,7 @@ static int ll_searchpath (lua_State *L) { luaL_checkstring(L, 2), luaL_optstring(L, 3, "."), luaL_optstring(L, 4, LUA_DIRSEP)); - if (f != NULL) return 1; + if (f != nullptr) return 1; else { /* error message is on top of the stack */ luaL_pushfail(L); lua_insert(L, -2); @@ -519,7 +519,7 @@ static const char *findfile (lua_State *L, const char *name, const char *path; lua_getfield(L, lua_upvalueindex(1), pname); path = lua_tostring(L, -1); - if (l_unlikely(path == NULL)) + if (l_unlikely(path == nullptr)) luaL_error(L, "'package.%s' must be a string", pname); return searchpath(L, name, path, ".", dirsep); } @@ -540,7 +540,7 @@ static int searcher_Lua (lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); filename = findfile(L, name, "path", LUA_LSUBSEP); - if (filename == NULL) return 1; /* module not found in this path */ + if (filename == nullptr) return 1; /* module not found in this path */ return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename); } @@ -574,7 +574,7 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { static int searcher_C (lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP); - if (filename == NULL) return 1; /* module not found in this path */ + if (filename == nullptr) return 1; /* module not found in this path */ return checkload(L, (loadfunc(L, filename, name) == 0), filename); } @@ -584,10 +584,10 @@ static int searcher_Croot (lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); int stat; - if (p == NULL) return 0; /* is root */ + if (p == nullptr) return 0; /* is root */ lua_pushlstring(L, name, ct_diff2sz(p - name)); filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP); - if (filename == NULL) return 1; /* root not found */ + if (filename == nullptr) return 1; /* root not found */ if ((stat = loadfunc(L, filename, name)) != 0) { if (stat != ERRFUNC) return checkload(L, 0, filename); /* real error */ @@ -685,18 +685,18 @@ static const luaL_Reg pk_funcs[] = { {"loadlib", ll_loadlib}, {"searchpath", ll_searchpath}, /* placeholders */ - {"preload", NULL}, - {"cpath", NULL}, - {"path", NULL}, - {"searchers", NULL}, - {"loaded", NULL}, - {NULL, NULL} + {"preload", nullptr}, + {"cpath", nullptr}, + {"path", nullptr}, + {"searchers", nullptr}, + {"loaded", nullptr}, + {nullptr, nullptr} }; static const luaL_Reg ll_funcs[] = { {"require", ll_require}, - {NULL, NULL} + {nullptr, nullptr} }; @@ -706,13 +706,13 @@ static void createsearcherstable (lua_State *L) { searcher_Lua, searcher_C, searcher_Croot, - NULL + nullptr }; int i; /* create 'searchers' table */ lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0); /* fill it with predefined searchers */ - for (i=0; searchers[i] != NULL; i++) { + for (i=0; searchers[i] != nullptr; i++) { lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */ lua_pushcclosure(L, searchers[i], 1); lua_rawseti(L, -2, i+1); diff --git a/src/libraries/loslib.cpp b/src/libraries/loslib.cpp index e41693f3..9392b63b 100644 --- a/src/libraries/loslib.cpp +++ b/src/libraries/loslib.cpp @@ -122,7 +122,7 @@ /* ISO C definitions */ #define LUA_TMPNAMBUFSIZE L_tmpnam -#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#define lua_tmpnam(b,e) { e = (tmpnam(b) == nullptr); } #endif /* } */ @@ -133,7 +133,7 @@ #if !defined(l_system) #if defined(LUA_USE_IOS) /* Despite claiming to be ISO C, iOS does not implement 'system'. */ -#define l_system(cmd) ((cmd) == NULL ? 0 : -1) +#define l_system(cmd) ((cmd) == nullptr ? 0 : -1) #else #define l_system(cmd) system(cmd) /* default definition */ #endif @@ -141,11 +141,11 @@ static int os_execute (lua_State *L) { - const char *cmd = luaL_optstring(L, 1, NULL); + const char *cmd = luaL_optstring(L, 1, nullptr); int stat; errno = 0; stat = l_system(cmd); - if (cmd != NULL) + if (cmd != nullptr) return luaL_execresult(L, stat); else { lua_pushboolean(L, stat); /* true if there is a shell */ @@ -165,7 +165,7 @@ static int os_rename (lua_State *L) { const char *fromname = luaL_checkstring(L, 1); const char *toname = luaL_checkstring(L, 2); errno = 0; - return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); + return luaL_fileresult(L, rename(fromname, toname) == 0, nullptr); } @@ -181,7 +181,7 @@ static int os_tmpname (lua_State *L) { static int os_getenv (lua_State *L) { - lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if nullptr push nil */ return 1; } @@ -305,7 +305,7 @@ static time_t l_checktime (lua_State *L, int arg) { static int os_date (lua_State *L) { size_t slen; const char *s = luaL_optlstring(L, 1, "%c", &slen); - time_t t = luaL_opt(L, l_checktime, 2, time(NULL)); + time_t t = luaL_opt(L, l_checktime, 2, time(nullptr)); const char *se = s + slen; /* 's' end */ struct tm tmr, *stm; if (*s == '!') { /* UTC? */ @@ -314,7 +314,7 @@ static int os_date (lua_State *L) { } else stm = l_localtime(&t, &tmr); - if (stm == NULL) /* invalid date? */ + if (stm == nullptr) /* invalid date? */ return luaL_error(L, "date result cannot be represented in this installation"); if (strcmp(s, "*t") == 0) { @@ -348,7 +348,7 @@ static int os_date (lua_State *L) { static int os_time (lua_State *L) { time_t t; if (lua_isnoneornil(L, 1)) /* called without args? */ - t = time(NULL); /* get current time */ + t = time(nullptr); /* get current time */ else { struct tm ts; luaL_checktype(L, 1, LUA_TTABLE); @@ -385,8 +385,8 @@ static int os_setlocale (lua_State *L) { static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME}; static const char *const catnames[] = {"all", "collate", "ctype", "monetary", - "numeric", "time", NULL}; - const char *l = luaL_optstring(L, 1, NULL); + "numeric", "time", nullptr}; + const char *l = luaL_optstring(L, 1, nullptr); int op = luaL_checkoption(L, 2, "all", catnames); lua_pushstring(L, setlocale(cat[op], l)); return 1; @@ -418,7 +418,7 @@ static const luaL_Reg syslib[] = { {"setlocale", os_setlocale}, {"time", os_time}, {"tmpname", os_tmpname}, - {NULL, NULL} + {nullptr, nullptr} }; /* }====================================================== */ diff --git a/src/libraries/lstrlib.cpp b/src/libraries/lstrlib.cpp index 8f6341db..075c17cc 100644 --- a/src/libraries/lstrlib.cpp +++ b/src/libraries/lstrlib.cpp @@ -214,7 +214,7 @@ static int writer (lua_State *L, const void *b, size_t size, void *ud) { state->init = 1; luaL_buffinit(L, &state->B); } - if (b == NULL) { /* finishing dump? */ + if (b == nullptr) { /* finishing dump? */ luaL_pushresult(&state->B); /* push result */ lua_replace(L, 1); /* move it to reserved slot */ } @@ -250,8 +250,8 @@ static int str_dump (lua_State *L) { /* no coercion from strings to numbers */ static const luaL_Reg stringmetamethods[] = { - {"__index", NULL}, /* placeholder */ - {NULL, NULL} + {"__index", nullptr}, /* placeholder */ + {nullptr, nullptr} }; #else /* }{ */ @@ -264,7 +264,7 @@ static int tonum (lua_State *L, int arg) { else { /* check whether it is a numerical string */ size_t len; const char *s = lua_tolstring(L, arg, &len); - return (s != NULL && lua_stringtonumber(L, s) == len + 1); + return (s != nullptr && lua_stringtonumber(L, s) == len + 1); } } @@ -331,8 +331,8 @@ static const luaL_Reg stringmetamethods[] = { {"__div", arith_div}, {"__idiv", arith_idiv}, {"__unm", arith_unm}, - {"__index", NULL}, /* placeholder */ - {NULL, NULL} + {"__index", nullptr}, /* placeholder */ + {nullptr, nullptr} }; #endif /* } */ @@ -482,7 +482,7 @@ static const char *matchbalance (MatchState *ms, const char *s, const char *p) { if (l_unlikely(p >= ms->p_end - 1)) luaL_error(ms->L, "malformed pattern (missing arguments to '%%b')"); - if (*s != *p) return NULL; + if (*s != *p) return nullptr; else { int b = *p; int e = *(p+1); @@ -494,7 +494,7 @@ static const char *matchbalance (MatchState *ms, const char *s, else if (*s == b) cont++; } } - return NULL; /* string ends out of balance */ + return nullptr; /* string ends out of balance */ } @@ -509,7 +509,7 @@ static const char *max_expand (MatchState *ms, const char *s, if (res) return res; i--; /* else didn't match; reduce 1 repetition to try again */ } - return NULL; + return nullptr; } @@ -517,11 +517,11 @@ static const char *min_expand (MatchState *ms, const char *s, const char *p, const char *ep) { for (;;) { const char *res = match(ms, s, ep+1); - if (res != NULL) + if (res != nullptr) return res; else if (singlematch(ms, s, p, ep)) s++; /* try with one more repetition */ - else return NULL; + else return nullptr; } } @@ -534,7 +534,7 @@ static const char *start_capture (MatchState *ms, const char *s, ms->capture[level].init = s; ms->capture[level].len = what; ms->level = level+1; - if ((res=match(ms, s, p)) == NULL) /* match failed? */ + if ((res=match(ms, s, p)) == nullptr) /* match failed? */ ms->level--; /* undo capture */ return res; } @@ -545,7 +545,7 @@ static const char *end_capture (MatchState *ms, const char *s, int l = capture_to_close(ms); const char *res; ms->capture[l].len = s - ms->capture[l].init; /* close capture */ - if ((res = match(ms, s, p)) == NULL) /* match failed? */ + if ((res = match(ms, s, p)) == nullptr) /* match failed? */ ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ return res; } @@ -558,7 +558,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) { if ((size_t)(ms->src_end-s) >= len && memcmp(ms->capture[l].init, s, len) == 0) return s+len; - else return NULL; + else return nullptr; } @@ -582,16 +582,16 @@ static const char *match (MatchState *ms, const char *s, const char *p) { case '$': { if ((p + 1) != ms->p_end) /* is the '$' the last char in pattern? */ goto dflt; /* no; go to default */ - s = (s == ms->src_end) ? s : NULL; /* check end of string */ + s = (s == ms->src_end) ? s : nullptr; /* check end of string */ break; } case L_ESC: { /* escaped sequences not in the format class[*+?-]? */ switch (*(p + 1)) { case 'b': { /* balanced string? */ s = matchbalance(ms, s, p + 2); - if (s != NULL) { + if (s != nullptr) { p += 4; goto init; /* return match(ms, s, p + 4); */ - } /* else fail (s == NULL) */ + } /* else fail (s == nullptr) */ break; } case 'f': { /* frontier? */ @@ -605,14 +605,14 @@ static const char *match (MatchState *ms, const char *s, const char *p) { matchbracketclass(cast_uchar(*s), p, ep - 1)) { p = ep; goto init; /* return match(ms, s, ep); */ } - s = NULL; /* match failed */ + s = nullptr; /* match failed */ break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { /* capture results (%0-%9)? */ s = match_capture(ms, s, cast_uchar(*(p + 1))); - if (s != NULL) { + if (s != nullptr) { p += 2; goto init; /* return match(ms, s, p + 2) */ } break; @@ -629,13 +629,13 @@ static const char *match (MatchState *ms, const char *s, const char *p) { p = ep + 1; goto init; /* return match(ms, s, ep + 1); */ } else /* '+' or no suffix */ - s = NULL; /* fail */ + s = nullptr; /* fail */ } else { /* matched once */ switch (*ep) { /* handle optional suffix */ case '?': { /* optional */ const char *res; - if ((res = match(ms, s + 1, ep + 1)) != NULL) + if ((res = match(ms, s + 1, ep + 1)) != nullptr) s = res; else { p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */ @@ -668,12 +668,12 @@ static const char *match (MatchState *ms, const char *s, const char *p) { static const char *lmemfind (const char *s1, size_t l1, const char *s2, size_t l2) { if (l2 == 0) return s1; /* empty strings are everywhere */ - else if (l2 > l1) return NULL; /* avoids a negative 'l1' */ + else if (l2 > l1) return nullptr; /* avoids a negative 'l1' */ else { const char *init; /* to search for a '*s2' inside 's1' */ l2--; /* 1st char will be checked by 'memchr' */ l1 = l1-l2; /* 's2' cannot be found after that */ - while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != nullptr) { init++; /* 1st char is already checked */ if (memcmp(init, s2+1, l2) == 0) return init-1; @@ -682,7 +682,7 @@ static const char *lmemfind (const char *s1, size_t l1, s1 = init; } } - return NULL; /* not found */ + return nullptr; /* not found */ } } @@ -796,11 +796,11 @@ static int str_find_aux (lua_State *L, int find) { do { const char *res; reprepstate(&ms); - if ((res=match(&ms, s1, p)) != NULL) { + if ((res=match(&ms, s1, p)) != nullptr) { if (find) { lua_pushinteger(L, ct_diff2S(s1 - s) + 1); /* start */ lua_pushinteger(L, ct_diff2S(res - s)); /* end */ - return push_captures(&ms, NULL, 0) + 2; + return push_captures(&ms, nullptr, 0) + 2; } else return push_captures(&ms, s1, res); @@ -838,7 +838,7 @@ static int gmatch_aux (lua_State *L) { for (src = gm->src; src <= gm->ms.src_end; src++) { const char *e; reprepstate(&gm->ms); - if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) { + if ((e = match(&gm->ms, src, gm->p)) != nullptr && e != gm->lastmatch) { gm->src = gm->lastmatch = e; return push_captures(&gm->ms, src, e); } @@ -858,7 +858,7 @@ static int gmatch (lua_State *L) { if (init > ls) /* start after string's end? */ init = ls + 1; /* avoid overflows in 's + init' */ prepstate(&gm->ms, L, s, ls, p, lp); - gm->src = s + init; gm->p = p; gm->lastmatch = NULL; + gm->src = s + init; gm->p = p; gm->lastmatch = nullptr; lua_pushcclosure(L, gmatch_aux, 3); return 1; } @@ -870,7 +870,7 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, lua_State *L = ms->L; const char *news = lua_tolstring(L, 3, &l); const char *p; - while ((p = (char *)memchr(news, L_ESC, l)) != NULL) { + while ((p = (char *)memchr(news, L_ESC, l)) != nullptr) { luaL_addlstring(b, news, ct_diff2sz(p - news)); p++; /* skip ESC */ if (*p == L_ESC) /* '%%' */ @@ -939,7 +939,7 @@ static int str_gsub (lua_State *L) { size_t srcl, lp; const char *src = luaL_checklstring(L, 1, &srcl); /* subject */ const char *p = luaL_checklstring(L, 2, &lp); /* pattern */ - const char *lastmatch = NULL; /* end of last match */ + const char *lastmatch = nullptr; /* end of last match */ int tr = lua_type(L, 3); /* replacement type */ /* max replacements */ lua_Integer max_s = luaL_optinteger(L, 4, cast_st2S(srcl) + 1); @@ -959,7 +959,7 @@ static int str_gsub (lua_State *L) { while (n < max_s) { const char *e; reprepstate(&ms); /* (re)prepare state for new match */ - if ((e = match(&ms, src, p)) != NULL && e != lastmatch) { /* match? */ + if ((e = match(&ms, src, p)) != nullptr && e != lastmatch) { /* match? */ n++; changed = add_value(&ms, &b, src, e, tr) | changed; src = lastmatch = e; @@ -1157,7 +1157,7 @@ static int quotefloat (lua_State *L, char *buff, lua_Number n) { int nb = lua_number2strx(L, buff, MAX_ITEM, "%" LUA_NUMBER_FRMLEN "a", n); /* ensures that 'buff' string uses a dot as the radix character */ - if (memchr(buff, '.', cast_uint(nb)) == NULL) { /* no dot? */ + if (memchr(buff, '.', cast_uint(nb)) == nullptr) { /* no dot? */ char point = lua_getlocaledecpoint(); /* try locale point */ char *ppoint = (char *)memchr(buff, point, cast_uint(nb)); if (ppoint) *ppoint = '.'; /* change it to a dot */ @@ -1193,7 +1193,7 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { break; } case LUA_TNIL: case LUA_TBOOLEAN: { - luaL_tolstring(L, arg, NULL); + luaL_tolstring(L, arg, nullptr); luaL_addvalue(b); break; } @@ -1330,7 +1330,7 @@ static int str_format (lua_State *L) { case 'p': { const void *p = lua_topointer(L, arg); checkformat(L, form, L_FMTFLAGSC, 0); - if (p == NULL) { /* avoid calling 'printf' with argument NULL */ + if (p == nullptr) { /* avoid calling 'printf' with argument nullptr */ p = "(null)"; /* result */ form[strlen(form) - 1] = 's'; /* format it as a string */ } @@ -1351,7 +1351,7 @@ static int str_format (lua_State *L) { else { luaL_argcheck(L, l == strlen(s), arg, "string contains zeros"); checkformat(L, form, L_FMTFLAGSC, 1); - if (strchr(form, '.') == NULL && l >= 100) { + if (strchr(form, '.') == nullptr && l >= 100) { /* no precision and string is too long to be formatted */ luaL_addvalue(&b); /* keep entire string */ } @@ -1853,7 +1853,7 @@ static const luaL_Reg strlib[] = { {"pack", str_pack}, {"packsize", str_packsize}, {"unpack", str_unpack}, - {NULL, NULL} + {nullptr, nullptr} }; diff --git a/src/libraries/ltablib.cpp b/src/libraries/ltablib.cpp index cc5a5862..38767f47 100644 --- a/src/libraries/ltablib.cpp +++ b/src/libraries/ltablib.cpp @@ -415,7 +415,7 @@ static const luaL_Reg tab_funcs[] = { {"remove", tremove}, {"move", tmove}, {"sort", sort}, - {NULL, NULL} + {nullptr, nullptr} }; diff --git a/src/libraries/lutf8lib.cpp b/src/libraries/lutf8lib.cpp index 89513231..207d82d2 100644 --- a/src/libraries/lutf8lib.cpp +++ b/src/libraries/lutf8lib.cpp @@ -44,7 +44,7 @@ static lua_Integer u_posrelat (lua_Integer pos, size_t len) { /* -** Decode one UTF-8 sequence, returning NULL if byte sequence is +** Decode one UTF-8 sequence, returning nullptr if byte sequence is ** invalid. The array 'limits' stores the minimum value for each ** sequence length, to check for overlong representations. Its first ** entry forces an error for non-ASCII bytes with no continuation @@ -62,18 +62,18 @@ static const char *utf8_decode (const char *s, l_uint32 *val, int strict) { for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ unsigned int cc = (unsigned char)s[++count]; /* read next byte */ if (!iscont(cc)) /* not a continuation byte? */ - return NULL; /* invalid byte sequence */ + return nullptr; /* invalid byte sequence */ res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ } res |= ((l_uint32)(c & 0x7F) << (count * 5)); /* add first byte */ if (count > 5 || res > MAXUTF || res < limits[count]) - return NULL; /* invalid byte sequence */ + return nullptr; /* invalid byte sequence */ s += count; /* skip continuation bytes read */ } if (strict) { /* check for invalid code points; too large or surrogates */ if (res > MAXUNICODE || (0xD800u <= res && res <= 0xDFFFu)) - return NULL; + return nullptr; } if (val) *val = res; return s + 1; /* +1 to include first byte */ @@ -97,8 +97,8 @@ static int utflen (lua_State *L) { luaL_argcheck(L, --posj < (lua_Integer)len, 3, "final position out of bounds"); while (posi <= posj) { - const char *s1 = utf8_decode(s + posi, NULL, !lax); - if (s1 == NULL) { /* conversion error? */ + const char *s1 = utf8_decode(s + posi, nullptr, !lax); + if (s1 == nullptr) { /* conversion error? */ luaL_pushfail(L); /* return fail ... */ lua_pushinteger(L, posi + 1); /* ... and current position */ return 2; @@ -135,7 +135,7 @@ static int codepoint (lua_State *L) { for (s += posi - 1; s < se;) { l_uint32 code; s = utf8_decode(s, &code, !lax); - if (s == NULL) + if (s == nullptr) return luaL_error(L, MSGInvalid); lua_pushinteger(L, l_castU2S(code)); n++; @@ -238,7 +238,7 @@ static int iter_aux (lua_State *L, int strict) { else { l_uint32 code; const char *next = utf8_decode(s + n, &code, strict); - if (next == NULL || iscontp(next)) + if (next == nullptr || iscontp(next)) return luaL_error(L, MSGInvalid); lua_pushinteger(L, l_castU2S(n + 1)); lua_pushinteger(L, l_castU2S(code)); @@ -278,8 +278,8 @@ static const luaL_Reg funcs[] = { {"len", utflen}, {"codes", iter_codes}, /* placeholders */ - {"charpattern", NULL}, - {NULL, NULL} + {"charpattern", nullptr}, + {nullptr, nullptr} }; diff --git a/src/memory/gc/gc_collector.cpp b/src/memory/gc/gc_collector.cpp index 786201b5..f5bcc831 100644 --- a/src/memory/gc/gc_collector.cpp +++ b/src/memory/gc/gc_collector.cpp @@ -42,8 +42,8 @@ void GCCollector::atomic(lua_State* L) { global_State* g = G(L); GCObject *origweak, *origall; GCObject *grayagain = g->getGrayAgain(); /* save original list */ - g->setGrayAgain(NULL); - lua_assert(g->getEphemeron() == NULL && g->getWeak() == NULL); + g->setGrayAgain(nullptr); + lua_assert(g->getEphemeron() == nullptr && g->getWeak() == nullptr); lua_assert(!iswhite(mainthread(g))); g->setGCState(GCState::Atomic); markobject(g, L); /* mark running thread */ @@ -59,8 +59,8 @@ void GCCollector::atomic(lua_State* L) { GCWeak::convergeephemerons(g); /* at this point, all strongly accessible objects are marked. */ /* Clear values from weak tables, before checking finalizers */ - GCWeak::clearbyvalues(g, g->getWeak(), NULL); - GCWeak::clearbyvalues(g, g->getAllWeak(), NULL); + GCWeak::clearbyvalues(g, g->getWeak(), nullptr); + GCWeak::clearbyvalues(g, g->getAllWeak(), nullptr); origweak = g->getWeak(); origall = g->getAllWeak(); GCFinalizer::separatetobefnz(g, 0); /* separate objects to be finalized */ GCMarking::markbeingfnz(g); /* mark objects that will be finalized */ @@ -75,7 +75,7 @@ void GCCollector::atomic(lua_State* L) { GCWeak::clearbyvalues(g, g->getAllWeak(), origall); luaS_clearcache(g); g->setCurrentWhite(cast_byte(otherwhite(g))); /* flip current white */ - lua_assert(g->getGray() == NULL); + lua_assert(g->getGray() == nullptr); } @@ -100,8 +100,8 @@ void GCCollector::finishgencycle(lua_State* L, global_State* g) { void GCCollector::minor2inc(lua_State* L, global_State* g, GCKind kind) { g->setGCMajorMinor(g->getGCMarked()); /* number of live bytes */ g->setGCKind(kind); - g->setReallyOld(NULL); g->setOld1(NULL); g->setSurvival(NULL); - g->setFinObjROld(NULL); g->setFinObjOld1(NULL); g->setFinObjSur(NULL); + g->setReallyOld(nullptr); g->setOld1(nullptr); g->setSurvival(nullptr); + g->setFinObjROld(nullptr); g->setFinObjOld1(nullptr); g->setFinObjSur(nullptr); GCSweeping::entersweep(L); /* continue as an incremental cycle */ /* set a debt equal to the step size */ luaE_setdebt(g, applygcparam(g, STEPSIZE, 100)); @@ -141,10 +141,10 @@ void GCCollector::youngcollection(lua_State* L, global_State* g) { lua_assert(g->getGCState() == GCState::Propagate); if (g->getFirstOld1()) { /* are there regular OLD1 objects? */ GCMarking::markold(g, g->getFirstOld1(), g->getReallyOld()); /* mark them */ - g->setFirstOld1(NULL); /* no more OLD1 objects (for now) */ + g->setFirstOld1(nullptr); /* no more OLD1 objects (for now) */ } GCMarking::markold(g, g->getFinObj(), g->getFinObjROld()); - GCMarking::markold(g, g->getToBeFnz(), NULL); + GCMarking::markold(g, g->getToBeFnz(), nullptr); atomic(L); /* will lose 'g->marked' */ @@ -158,7 +158,7 @@ void GCCollector::youngcollection(lua_State* L, global_State* g) { g->setSurvival(g->getAllGC()); /* all news are survivals */ /* repeat for 'finobj' lists */ - dummy = NULL; /* no 'firstold1' optimization for 'finobj' lists */ + dummy = nullptr; /* no 'firstold1' optimization for 'finobj' lists */ psurvival = GCSweeping::sweepgen(L, g, g->getFinObjPtr(), g->getFinObjSur(), &dummy, &addedold1); /* sweep 'survival' */ GCSweeping::sweepgen(L, g, psurvival, g->getFinObjOld1(), &dummy, &addedold1); @@ -166,7 +166,7 @@ void GCCollector::youngcollection(lua_State* L, global_State* g) { g->setFinObjOld1(*psurvival); /* 'survival' survivals are old now */ g->setFinObjSur(g->getFinObj()); /* all news are survivals */ - GCSweeping::sweepgen(L, g, g->getToBeFnzPtr(), NULL, &dummy, &addedold1); + GCSweeping::sweepgen(L, g, g->getToBeFnzPtr(), nullptr, &dummy, &addedold1); /* keep total number of added old1 bytes */ g->setGCMarked(marked + addedold1); @@ -193,7 +193,7 @@ void GCCollector::atomic2gen(lua_State* L, global_State* g) { /* everything alive now is old */ GCObject *allgc = g->getAllGC(); g->setReallyOld(allgc); g->setOld1(allgc); g->setSurvival(allgc); - g->setFirstOld1(NULL); /* there are no OLD1 objects anywhere */ + g->setFirstOld1(nullptr); /* there are no OLD1 objects anywhere */ /* repeat for 'finobj' lists */ GCSweeping::sweep2old(L, g->getFinObjPtr()); @@ -265,7 +265,7 @@ l_mem GCCollector::singlestep(lua_State* L, int fast) { break; } case GCState::Propagate: { - if (fast || g->getGray() == NULL) { + if (fast || g->getGray() == nullptr) { g->setGCState(GCState::EnterAtomic); /* finish propagate phase */ stepresult = 1; } @@ -294,7 +294,7 @@ l_mem GCCollector::singlestep(lua_State* L, int fast) { break; } case GCState::SweepToBeFnz: { /* sweep objects to be finalized */ - GCSweeping::sweepstep(L, g, GCState::SweepEnd, NULL, fast); + GCSweeping::sweepstep(L, g, GCState::SweepEnd, nullptr, fast); stepresult = GCSWEEPMAX; break; } diff --git a/src/memory/gc/gc_core.h b/src/memory/gc/gc_core.h index 7b54f754..f9534a9c 100644 --- a/src/memory/gc/gc_core.h +++ b/src/memory/gc/gc_core.h @@ -37,7 +37,7 @@ class GCCore { /* ** Get pointer to the gclist field of an object. ** Different object types store gclist in different locations. - ** Returns pointer to gclist field, or NULL for invalid types. + ** Returns pointer to gclist field, or nullptr for invalid types. */ static GCObject** getgclist(GCObject* o); diff --git a/src/memory/gc/gc_finalizer.cpp b/src/memory/gc/gc_finalizer.cpp index 05dfce3d..8086fba8 100644 --- a/src/memory/gc/gc_finalizer.cpp +++ b/src/memory/gc/gc_finalizer.cpp @@ -55,7 +55,7 @@ void GCFinalizer::checkSizes(lua_State* L, global_State* g) { ** Find last 'next' field in list 'p' (to add elements at its end). */ GCObject** GCFinalizer::findlast(GCObject** p) { - while (*p != NULL) + while (*p != nullptr) p = (*p)->getNextPtr(); return p; } @@ -165,7 +165,7 @@ void GCFinalizer::GCTM(lua_State* L) { L->getStackSubsystem().setSlot(L->getTop().p, &v); /* ... and its argument */ L->getStackSubsystem().push(); L->getCI()->setCallStatus(L->getCI()->getCallStatus() | CIST_FIN); /* will run a finalizer */ - status = L->pCall(dothecall, NULL, L->saveStack(L->getTop().p - 2), 0); + status = L->pCall(dothecall, nullptr, L->saveStack(L->getTop().p - 2), 0); L->getCI()->setCallStatus(L->getCI()->getCallStatus() & ~CIST_FIN); /* not running a finalizer anymore */ L->setAllowHook(oldah); /* restore hooks */ g->setGCStp(oldgcstp); /* restore state */ @@ -188,7 +188,7 @@ void GCFinalizer::GCTM(lua_State* L) { ** Move all unreachable objects (or 'all' objects) that need ** finalization from list 'finobj' to list 'tobefnz' (to be finalized). ** (Note that objects after 'finobjold1' cannot be white, so they -** don't need to be traversed. In incremental mode, 'finobjold1' is NULL, +** don't need to be traversed. In incremental mode, 'finobjold1' is nullptr, ** so the whole list is traversed.) */ void GCFinalizer::separatetobefnz(global_State* g, int all) { diff --git a/src/memory/gc/gc_marking.cpp b/src/memory/gc/gc_marking.cpp index 3c1369da..97f1948f 100644 --- a/src/memory/gc/gc_marking.cpp +++ b/src/memory/gc/gc_marking.cpp @@ -83,7 +83,7 @@ static inline void linkgclistThread(lua_State* th, GCObject*& p) { ** Access to collectable objects in table array part */ #define gcvalarr(t, i) \ - ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : NULL) + ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr) /* @@ -182,20 +182,20 @@ l_mem GCMarking::traversethread(global_State* g, lua_State* th) { StkId o = th->getStack().p; if (isold(th) || g->getGCState() == GCState::Propagate) linkgclistThread(th, *g->getGrayAgainPtr()); - if (o == NULL) + if (o == nullptr) return 0; /* stack not completely built yet */ lua_assert(g->getGCState() == GCState::Atomic || - th->getOpenUpval() == NULL || th->isInTwups()); + th->getOpenUpval() == nullptr || th->isInTwups()); for (; o < th->getTop().p; o++) markvalue(g, s2v(o)); - for (uv = th->getOpenUpval(); uv != NULL; uv = uv->getOpenNext()) + for (uv = th->getOpenUpval(); uv != nullptr; uv = uv->getOpenNext()) markobject(g, uv); if (g->getGCState() == GCState::Atomic) { if (!g->getGCEmergency()) th->shrinkStack(); for (o = th->getTop().p; o < th->getStackLast().p + EXTRA_STACK; o++) setnilvalue(s2v(o)); - if (!th->isInTwups() && th->getOpenUpval() != NULL) { + if (!th->isInTwups() && th->getOpenUpval() != nullptr) { th->setTwups(g->getTwups()); g->setTwups(th); } @@ -310,7 +310,7 @@ void GCMarking::markmt(global_State* g) { */ void GCMarking::markbeingfnz(global_State* g) { GCObject* o; - for (o = g->getToBeFnz(); o != NULL; o = o->getNext()) + for (o = g->getToBeFnz(); o != nullptr; o = o->getNext()) markobject(g, o); } @@ -321,15 +321,15 @@ void GCMarking::markbeingfnz(global_State* g) { void GCMarking::remarkupvals(global_State* g) { lua_State* thread; lua_State** p = g->getTwupsPtr(); - while ((thread = *p) != NULL) { - if (!iswhite(thread) && thread->getOpenUpval() != NULL) + while ((thread = *p) != nullptr) { + if (!iswhite(thread) && thread->getOpenUpval() != nullptr) p = thread->getTwupsPtr(); else { UpVal* uv; - lua_assert(!isold(thread) || thread->getOpenUpval() == NULL); + lua_assert(!isold(thread) || thread->getOpenUpval() == nullptr); *p = thread->getTwups(); thread->setTwups(thread); /* mark out of list */ - for (uv = thread->getOpenUpval(); uv != NULL; uv = uv->getOpenNext()) { + for (uv = thread->getOpenUpval(); uv != nullptr; uv = uv->getOpenNext()) { lua_assert(getage(uv) <= getage(thread)); if (!iswhite(uv)) { lua_assert(uv->isOpen() && isgray(uv)); @@ -392,7 +392,7 @@ int GCMarking::traversearray(global_State* g, Table* h) { unsigned i; for (i = 0; i < asize; i++) { GCObject* o = gcvalarr(h, i); - if (o != NULL && iswhite(o)) { + if (o != nullptr && iswhite(o)) { marked = 1; reallymarkobject(g, o); } @@ -424,6 +424,6 @@ void GCMarking::traversestrongtable(global_State* g, Table* h) { ** Clear all gray lists (called when entering sweep phase) */ void GCMarking::cleargraylists(global_State* g) { - *g->getGrayPtr() = *g->getGrayAgainPtr() = NULL; - *g->getWeakPtr() = *g->getAllWeakPtr() = *g->getEphemeronPtr() = NULL; + *g->getGrayPtr() = *g->getGrayAgainPtr() = nullptr; + *g->getWeakPtr() = *g->getAllWeakPtr() = *g->getEphemeronPtr() = nullptr; } diff --git a/src/memory/gc/gc_marking.h b/src/memory/gc/gc_marking.h index ec52f462..437c7c1f 100644 --- a/src/memory/gc/gc_marking.h +++ b/src/memory/gc/gc_marking.h @@ -149,7 +149,7 @@ inline void markobject(global_State* g, const T* t) { } } -/* Mark an object that can be NULL */ +/* Mark an object that can be nullptr */ template inline void markobjectN(global_State* g, const T* t) { if (t) { diff --git a/src/memory/gc/gc_sweeping.cpp b/src/memory/gc/gc_sweeping.cpp index 558475e6..ab817428 100644 --- a/src/memory/gc/gc_sweeping.cpp +++ b/src/memory/gc/gc_sweeping.cpp @@ -73,14 +73,14 @@ static inline void linkgclistThread(lua_State* th, GCObject*& p) { ** 'p': pointer to pointer to start of list ** 'countin': maximum number of objects to sweep (for incremental collection) ** -** Returns: pointer to where sweeping stopped (NULL if list exhausted) +** Returns: pointer to where sweeping stopped (nullptr if list exhausted) */ GCObject** GCSweeping::sweeplist(lua_State* L, GCObject** p, l_mem countin) { global_State* g = G(L); lu_byte ow = otherwhite(g); lu_byte white = g->getWhite(); /* current white */ - while (*p != NULL && countin-- > 0) { + while (*p != nullptr && countin-- > 0) { GCObject* curr = *p; lu_byte marked = curr->getMarked(); @@ -96,7 +96,7 @@ GCObject** GCSweeping::sweeplist(lua_State* L, GCObject** p, l_mem countin) { } } - return (*p == NULL) ? NULL : p; + return (*p == nullptr) ? nullptr : p; } @@ -128,7 +128,7 @@ void GCSweeping::sweep2old(lua_State* L, GCObject** p) { GCObject* curr; global_State* g = G(L); - while ((curr = *p) != NULL) { + while ((curr = *p) != nullptr) { if (iswhite(curr)) { /* is 'curr' dead? */ lua_assert(isdead(g, curr)); *p = curr->getNext(); /* remove 'curr' from list */ @@ -198,7 +198,7 @@ GCObject** GCSweeping::sweepgen(lua_State* L, global_State* g, GCObject** p, setage(curr, nextage[static_cast(age)]); if (getage(curr) == GCAge::Old1) { addedold += objsize(curr); /* bytes becoming old */ - if (*pfirstold1 == NULL) + if (*pfirstold1 == nullptr) *pfirstold1 = curr; /* first OLD1 object in the list */ } } @@ -224,7 +224,7 @@ GCObject** GCSweeping::sweepgen(lua_State* L, global_State* g, GCObject** p, void GCSweeping::entersweep(lua_State* L) { global_State* g = G(L); g->setGCState(GCState::SweepAllGC); - lua_assert(g->getSweepGC() == NULL); + lua_assert(g->getSweepGC() == nullptr); g->setSweepGC(sweeptolive(L, g->getAllGCPtr())); } diff --git a/src/memory/gc/gc_sweeping.h b/src/memory/gc/gc_sweeping.h index 27b33c33..fc3d57ea 100644 --- a/src/memory/gc/gc_sweeping.h +++ b/src/memory/gc/gc_sweeping.h @@ -38,13 +38,13 @@ class GCSweeping { /* ** Sweep a list of objects, removing dead ones. ** 'countin' limits how many objects to sweep (for incremental collection). - ** Returns pointer to where sweeping stopped (NULL if list exhausted). + ** Returns pointer to where sweeping stopped (nullptr if list exhausted). */ static GCObject** sweeplist(lua_State* L, GCObject** p, l_mem countin); /* ** Sweep a list until finding a live object (or end of list). - ** Returns pointer to first live object (or NULL). + ** Returns pointer to first live object (or nullptr). */ static GCObject** sweeptolive(lua_State* L, GCObject** p); diff --git a/src/memory/gc/gc_weak.cpp b/src/memory/gc/gc_weak.cpp index d5d45c32..86a3fb36 100644 --- a/src/memory/gc/gc_weak.cpp +++ b/src/memory/gc/gc_weak.cpp @@ -38,7 +38,7 @@ /* Access to collectable objects in array part of tables */ #define gcvalarr(t,i) \ - ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : NULL) + ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr) /* Note: gcvalueN and valiswhite are now in lgc.h */ /* Note: markkey and markvalue are defined in gc_marking.h */ @@ -50,7 +50,7 @@ ** being finalized, keep them in keys, but not in values. */ static int iscleared(global_State* g, const GCObject* o) { - if (o == NULL) return 0; /* non-collectable value */ + if (o == nullptr) return 0; /* non-collectable value */ else if (novariant(o->getType()) == LUA_TSTRING) { markobject(g, o); /* strings are 'values', so are never weak */ return 0; @@ -138,13 +138,13 @@ void GCWeak::genlink(global_State* g, GCObject* o) { */ int GCWeak::getmode(global_State* g, Table* h) { const TValue* mode = gfasttm(g, h->getMetatable(), TMS::TM_MODE); - if (mode == NULL || !ttisshrstring(mode)) + if (mode == nullptr || !ttisshrstring(mode)) return 0; /* ignore non-(short)string modes */ else { const char* smode = getshrstr(tsvalue(mode)); const char* weakkey = strchr(smode, 'k'); const char* weakvalue = strchr(smode, 'v'); - return ((weakkey != NULL) << 1) | (weakvalue != NULL); + return ((weakkey != nullptr) << 1) | (weakvalue != nullptr); } } @@ -165,7 +165,7 @@ static int traversearray(global_State* g, Table* h) { unsigned i; for (i = 0; i < asize; i++) { GCObject* o = gcvalarr(h, i); - if (o != NULL && iswhite(o)) { + if (o != nullptr && iswhite(o)) { marked = 1; GCMarking::reallymarkobject(g, o); } @@ -275,9 +275,9 @@ void GCWeak::convergeephemerons(global_State* g) { do { GCObject* w; GCObject* next = g->getEphemeron(); /* get ephemeron list */ - g->setEphemeron(NULL); /* tables may return to this list when traversed */ + g->setEphemeron(nullptr); /* tables may return to this list when traversed */ changed = 0; - while ((w = next) != NULL) { /* for each ephemeron table */ + while ((w = next) != nullptr) { /* for each ephemeron table */ Table* h = gco2t(w); next = h->getGclist(); /* list is rebuilt during loop */ nw2black(h); /* out of the list (for now) */ diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index 20afda51..ed292800 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -81,7 +81,7 @@ ** Access to collectable objects in array part of tables */ #define gcvalarr(t,i) \ - ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : NULL) + ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr) #define markvalue(g,o) { checkliveness(mainthread(g),o); \ @@ -92,7 +92,7 @@ #define markobject(g,t) { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); } /* -** mark an object that can be NULL (either because it is really optional, +** mark an object that can be nullptr (either because it is really optional, ** or it was stripped as debug info, or inside an uncompleted structure) */ #define markobjectN(g,t) { if (t) markobject(g,t); } @@ -457,7 +457,7 @@ void freeobj (lua_State *L, GCObject *o) { ** objects, where a dead object is one marked with the old (non current) ** white; change all non-dead objects back to white (and new), preparing ** for next collection cycle. Return where to continue the traversal or -** NULL if list is finished. +** nullptr if list is finished. */ /* ** Sweep a linked list of GC objects, freeing dead objects. @@ -467,7 +467,7 @@ void freeobj (lua_State *L, GCObject *o) { ** - countin: Maximum number of objects to process (for incremental sweeping) ** ** RETURN: -** - NULL if list is fully swept +** - nullptr if list is fully swept ** - Pointer to next position to continue sweeping (for incremental work) ** ** TWO-WHITE SCHEME: @@ -579,7 +579,7 @@ static void correctpointers (global_State *g, GCObject *o) { */ static GCObject **correctgraylist (GCObject **p) { GCObject *curr; - while ((curr = *p) != NULL) { + while ((curr = *p) != nullptr) { GCObject **next = getgclist(curr); if (iswhite(curr)) goto remove; /* remove all white objects */ @@ -716,11 +716,11 @@ void luaC_freeallobjects (lua_State *L) { g->setGCStp(GCSTPCLS); /* no extra finalizers after here */ luaC_changemode(L, GCKind::Incremental); separatetobefnz(g, 1); /* separate all objects with finalizers */ - lua_assert(g->getFinObj() == NULL); + lua_assert(g->getFinObj() == nullptr); callallpendingfinalizers(L); deletelist(L, g->getAllGC(), obj2gco(mainthread(g))); - lua_assert(g->getFinObj() == NULL); /* no new finalizers */ - deletelist(L, g->getFixedGC(), NULL); /* collect fixed objects */ + lua_assert(g->getFinObj() == nullptr); /* no new finalizers */ + deletelist(L, g->getFixedGC(), nullptr); /* collect fixed objects */ lua_assert(g->getStringTable()->getNumElements() == 0); } @@ -841,8 +841,8 @@ void luaC_fullgc (lua_State *L, int isemergency) { ** Called when entering sweep phase or restarting collection. */ void global_State::clearGrayLists() { - *getGrayPtr() = *getGrayAgainPtr() = NULL; - *getWeakPtr() = *getAllWeakPtr() = *getEphemeronPtr() = NULL; + *getGrayPtr() = *getGrayAgainPtr() = nullptr; + *getWeakPtr() = *getAllWeakPtr() = *getEphemeronPtr() = nullptr; } @@ -885,11 +885,11 @@ int global_State::checkMinorMajor() { */ void global_State::correctGrayLists() { GCObject **list = correctgraylist(getGrayAgainPtr()); - *list = getWeak(); setWeak(NULL); + *list = getWeak(); setWeak(nullptr); list = correctgraylist(list); - *list = getAllWeak(); setAllWeak(NULL); + *list = getAllWeak(); setAllWeak(nullptr); list = correctgraylist(list); - *list = getEphemeron(); setEphemeron(NULL); + *list = getEphemeron(); setEphemeron(nullptr); correctgraylist(list); } @@ -912,7 +912,7 @@ void GCObject::fix(lua_State* L) const { /* const - only modifies mutable GC fi void GCObject::checkFinalizer(lua_State* L, Table* mt) { global_State *g = G(L); if (tofinalize(this) || /* obj. is already marked... */ - gfasttm(g, mt, TMS::TM_GC) == NULL || /* or has no finalizer... */ + gfasttm(g, mt, TMS::TM_GC) == nullptr || /* or has no finalizer... */ (g->getGCStp() & GCSTPCLS)) /* or closing state? */ return; /* nothing to be done */ else { /* move 'this' to 'finobj' list */ diff --git a/src/memory/lgc.h b/src/memory/lgc.h index b51eda63..ffcbc705 100644 --- a/src/memory/lgc.h +++ b/src/memory/lgc.h @@ -227,7 +227,7 @@ inline bool isdead(const global_State* g, const T* v) noexcept { ** Check liveness of a value being manipulated by the program. ** Any value being manipulated by the program either is non-collectable, ** or the collectable object has the right tag and it is not dead. -** The option 'L == NULL' allows this function to be used where L is not available. +** The option 'L == nullptr' allows this function to be used where L is not available. */ inline void checkliveness(lua_State* L, const TValue* obj) noexcept { (void)L; @@ -519,10 +519,10 @@ inline bool keyiswhite(const Node* n) noexcept { } /* -** Protected access to objects in values (returns NULL if not collectable) +** Protected access to objects in values (returns nullptr if not collectable) */ inline GCObject* gcvalueN(const TValue* o) noexcept { - return iscollectable(o) ? gcvalue(o) : NULL; + return iscollectable(o) ? gcvalue(o) : nullptr; } /* }================================================================== */ diff --git a/src/memory/lmem.cpp b/src/memory/lmem.cpp index e146d14b..528cecd2 100644 --- a/src/memory/lmem.cpp +++ b/src/memory/lmem.cpp @@ -28,15 +28,15 @@ ** void *frealloc (void *ud, void *ptr, size_t osize, size_t nsize); ** ('osize' is the old size, 'nsize' is the new size) ** -** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL. -** Particularly, frealloc(ud, NULL, 0, 0) does nothing, -** which is equivalent to free(NULL) in ISO C. +** - frealloc(ud, p, x, 0) frees the block 'p' and returns nullptr. +** Particularly, frealloc(ud, nullptr, 0, 0) does nothing, +** which is equivalent to free(nullptr) in ISO C. ** -** - frealloc(ud, NULL, x, s) creates a new block of size 's' -** (no matter 'x'). Returns NULL if it cannot create the new block. +** - frealloc(ud, nullptr, x, s) creates a new block of size 's' +** (no matter 'x'). Returns nullptr if it cannot create the new block. ** ** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from -** size 'x' to size 'y'. Returns NULL if it cannot reallocate the +** size 'x' to size 'y'. Returns nullptr if it cannot reallocate the ** block to the new size. */ @@ -68,7 +68,7 @@ */ static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { if (ns > 0 && cantryagain(g)) - return NULL; /* fail */ + return nullptr; /* fail */ else /* normal allocation */ return callfrealloc(g, block, os, ns); } @@ -149,7 +149,7 @@ l_noret luaM_toobig (lua_State *L) { */ void luaM_free_ (lua_State *L, void *block, size_t osize) { global_State *g = G(L); - lua_assert((osize == 0) == (block == NULL)); + lua_assert((osize == 0) == (block == nullptr)); callfrealloc(g, block, osize, 0); g->getGCDebtRef() += static_cast(osize); } @@ -166,7 +166,7 @@ static void *tryagain (lua_State *L, void *block, luaC_fullgc(L, 1); /* try to free some memory... */ return callfrealloc(g, block, osize, nsize); /* try again */ } - else return NULL; /* cannot run an emergency collection */ + else return nullptr; /* cannot run an emergency collection */ } @@ -176,14 +176,14 @@ static void *tryagain (lua_State *L, void *block, void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { void *newblock; global_State *g = G(L); - lua_assert((osize == 0) == (block == NULL)); + lua_assert((osize == 0) == (block == nullptr)); newblock = firsttry(g, block, osize, nsize); - if (l_unlikely(newblock == NULL && nsize > 0)) { + if (l_unlikely(newblock == nullptr && nsize > 0)) { newblock = tryagain(L, block, osize, nsize); - if (newblock == NULL) /* still no memory? */ - return NULL; /* do not update 'GCdebt' */ + if (newblock == nullptr) /* still no memory? */ + return nullptr; /* do not update 'GCdebt' */ } - lua_assert((nsize == 0) == (newblock == NULL)); + lua_assert((nsize == 0) == (newblock == nullptr)); g->getGCDebtRef() -= static_cast(nsize) - static_cast(osize); return newblock; } @@ -192,7 +192,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { void *newblock = luaM_realloc_(L, block, osize, nsize); - if (l_unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */ + if (l_unlikely(newblock == nullptr && nsize > 0)) /* allocation failed? */ luaM_error(L); return newblock; } @@ -200,13 +200,13 @@ void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, void *luaM_malloc_ (lua_State *L, size_t size, int tag) { if (size == 0) - return NULL; /* that's all */ + return nullptr; /* that's all */ else { global_State *g = G(L); - void *newblock = firsttry(g, NULL, cast_sizet(tag), size); - if (l_unlikely(newblock == NULL)) { - newblock = tryagain(L, NULL, cast_sizet(tag), size); - if (newblock == NULL) + void *newblock = firsttry(g, nullptr, cast_sizet(tag), size); + if (l_unlikely(newblock == nullptr)) { + newblock = tryagain(L, nullptr, cast_sizet(tag), size); + if (newblock == nullptr) luaM_error(L); } g->getGCDebtRef() -= static_cast(size); diff --git a/src/objects/lfunc.cpp b/src/objects/lfunc.cpp index 6b866e40..760a9d96 100644 --- a/src/objects/lfunc.cpp +++ b/src/objects/lfunc.cpp @@ -28,8 +28,8 @@ // Constructor CClosure::CClosure(int nupvals) { nupvalues = cast_byte(nupvals); - gclist = NULL; - f = NULL; + gclist = nullptr; + f = nullptr; // upvalue array initialized by caller if needed } @@ -44,9 +44,9 @@ CClosure* CClosure::create(lua_State* L, int nupvals) { // Constructor LClosure::LClosure(int nupvals) { nupvalues = cast_byte(nupvals); - gclist = NULL; - p = NULL; - // Initialize upvals array to NULL + gclist = nullptr; + p = nullptr; + // Initialize upvals array to nullptr std::fill_n(upvals, nupvals, nullptr); } @@ -111,8 +111,8 @@ static UpVal *newupval (lua_State *L, StkId level, UpVal **prev) { UpVal *luaF_findupval (lua_State *L, StkId level) { UpVal **pp = L->getOpenUpvalPtr(); UpVal *p; - lua_assert(L->isInTwups() || L->getOpenUpval() == NULL); - while ((p = *pp) != NULL && p->getLevel() >= level) { /* search for it */ + lua_assert(L->isInTwups() || L->getOpenUpval() == nullptr); + while ((p = *pp) != nullptr && p->getLevel() >= level) { /* search for it */ lua_assert(!isdead(G(L), p)); if (p->getLevel() == level) /* corresponding upvalue? */ return p; /* return it */ @@ -134,7 +134,7 @@ static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) { const TValue *tm = luaT_gettmbyobj(L, obj, TMS::TM_CLOSE); L->getStackSubsystem().setSlot(top++, tm); /* will call metamethod... */ L->getStackSubsystem().setSlot(top++, obj); /* with 'self' as the 1st argument */ - if (err != NULL) /* if there was an error... */ + if (err != nullptr) /* if there was an error... */ L->getStackSubsystem().setSlot(top++, err); /* then error object will be 2nd argument */ L->getStackSubsystem().setTopPtr(top); /* add function and arguments */ if (yy) @@ -152,8 +152,8 @@ static void checkclosemth (lua_State *L, StkId level) { const TValue *tm = luaT_gettmbyobj(L, s2v(level), TMS::TM_CLOSE); if (ttisnil(tm)) { /* no metamethod? */ int idx = cast_int(level - L->getCI()->funcRef().p); /* variable index */ - const char *vname = luaG_findlocal(L, L->getCI(), idx, NULL); - if (vname == NULL) vname = "?"; + const char *vname = luaG_findlocal(L, L->getCI(), idx, nullptr); + if (vname == nullptr) vname = "?"; luaG_runerror(L, "variable '%s' got a non-closable value", vname); } } @@ -175,7 +175,7 @@ static void prepcallclosemth (lua_State *L, StkId level, TStatus status, L->getStackSubsystem().setTopPtr(level + 1); /* call will be at this level */ /* FALLTHROUGH */ case CLOSEKTOP: /* don't need to change top */ - errobj = NULL; /* no error object */ + errobj = nullptr; /* no error object */ break; default: /* 'luaD_seterrorobj' will set top to level + 2 */ errobj = s2v(level + 1); /* error object goes after 'uv' */ @@ -224,7 +224,7 @@ void luaF_unlinkupval (UpVal *uv) { */ void luaF_closeupval (lua_State *L, StkId level) { UpVal *uv; - while ((uv = L->getOpenUpval()) != NULL && uv->getLevel() >= level) { + while ((uv = L->getOpenUpval()) != nullptr && uv->getLevel() >= level) { TValue *slot = uv->getValueSlot(); /* new position for value */ lua_assert(uv->getLevel() < L->getTop().p); luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */ @@ -316,7 +316,7 @@ void luaF_freeproto (lua_State *L, Proto *f) { /* ** Look for n-th local variable at line 'line' in function 'func'. -** Returns NULL if not found. +** Returns nullptr if not found. */ const char* Proto::getLocalName(int local_number, int pc) const { int i; @@ -327,7 +327,7 @@ const char* Proto::getLocalName(int local_number, int pc) const { return getstr(getLocVars()[i].getVarName()); } } - return NULL; /* not found */ + return nullptr; /* not found */ } const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { diff --git a/src/objects/lobject.cpp b/src/objects/lobject.cpp index 0f72ad55..1761339e 100644 --- a/src/objects/lobject.cpp +++ b/src/objects/lobject.cpp @@ -285,7 +285,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { #endif /* -** Convert string 's' to a Lua number (put in 'result'). Return NULL on +** Convert string 's' to a Lua number (put in 'result'). Return nullptr on ** fail or the address of the ending '\0' on success. ('mode' == 'x') ** means a hexadecimal numeral. */ @@ -293,9 +293,9 @@ static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { char *endptr; *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ : lua_str2number(s, &endptr); - if (endptr == s) return NULL; /* nothing recognized? */ + if (endptr == s) return nullptr; /* nothing recognized? */ while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ - return (*endptr == '\0') ? endptr : NULL; /* OK iff no trailing chars */ + return (*endptr == '\0') ? endptr : nullptr; /* OK iff no trailing chars */ } @@ -317,17 +317,17 @@ static const char *l_str2d (const char *s, lua_Number *result) { const char *pmode = strpbrk(s, ".xXnN"); /* look for special chars */ int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; if (mode == 'n') /* reject 'inf' and 'nan' */ - return NULL; + return nullptr; endptr = l_str2dloc(s, result, mode); /* try to convert */ - if (endptr == NULL) { /* failed? may be a different locale */ + if (endptr == nullptr) { /* failed? may be a different locale */ char buff[L_MAXLENNUM + 1]; const char *pdot = strchr(s, '.'); - if (pdot == NULL || strlen(s) > L_MAXLENNUM) - return NULL; /* string too long or no dot; fail */ + if (pdot == nullptr || strlen(s) > L_MAXLENNUM) + return nullptr; /* string too long or no dot; fail */ strcpy(buff, s); /* copy string to buffer */ buff[pdot - s] = lua_getlocaledecpoint(); /* correct decimal point */ endptr = l_str2dloc(buff, result, mode); /* try again */ - if (endptr != NULL) + if (endptr != nullptr) endptr = s + (endptr - buff); /* make relative to 's' */ } return endptr; @@ -355,13 +355,13 @@ static const char *l_str2int (const char *s, lua_Integer *result) { for (; lisdigit(cast_uchar(*s)); s++) { int d = *s - '0'; if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ - return NULL; /* do not accept it (as integer) */ + return nullptr; /* do not accept it (as integer) */ a = a * 10 + cast_uint(d); empty = 0; } } while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ - if (empty || *s != '\0') return NULL; /* something wrong in the numeral */ + if (empty || *s != '\0') return nullptr; /* something wrong in the numeral */ else { *result = l_castU2S((neg) ? 0u - a : a); return s; @@ -372,10 +372,10 @@ static const char *l_str2int (const char *s, lua_Integer *result) { size_t luaO_str2num (const char *s, TValue *o) { lua_Integer i; lua_Number n; const char *e; - if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */ + if ((e = l_str2int(s, &i)) != nullptr) { /* try as an integer */ setivalue(o, i); } - else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */ + else if ((e = l_str2d(s, &n)) != nullptr) { /* else try as a float */ setfltvalue(o, n); } else @@ -429,7 +429,7 @@ static int tostringbuffFloat (lua_Number n, char *buff) { /* first conversion */ int len = l_sprintf(buff, LUA_N2SBUFFSZ, LUA_NUMBER_FMT, (LUAI_UACNUMBER)n); - lua_Number check = lua_str2number(buff, NULL); /* read it back */ + lua_Number check = lua_str2number(buff, nullptr); /* read it back */ if (check != n) { /* not enough precision? */ /* convert again with more precision */ len = l_sprintf(buff, LUA_N2SBUFFSZ, LUA_NUMBER_FMT_N, @@ -534,7 +534,7 @@ static const char *clearbuff (BuffFS *buff) { lua_State *L = buff->L; const char *res; if (L->rawRunProtected( pushbuff, buff) != LUA_OK) /* errors? */ - res = NULL; /* error message is on the top of the stack */ + res = nullptr; /* error message is on the top of the stack */ else res = getstr(tsvalue(s2v(L->getTop().p - 1))); if (buff->b != buff->space) /* using dynamic buffer? */ @@ -558,10 +558,10 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { size_t newsize = buff->buffsize + slen; /* limited to MAX_SIZE/2 */ char *newb = (buff->b == buff->space) /* still using static space? */ - ? luaM_reallocvector(buff->L, NULL, 0, newsize, char) + ? luaM_reallocvector(buff->L, nullptr, 0, newsize, char) : luaM_reallocvector(buff->L, buff->b, buff->buffsize, newsize, char); - if (newb == NULL) { /* allocation error? */ + if (newb == nullptr) { /* allocation error? */ buff->err = 1; /* signal a memory error */ return; } @@ -593,12 +593,12 @@ static void addnum2buff (BuffFS *buff, TValue *num) { const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { const char *e; /* points to next '%' */ BuffFS buff(L); /* holds last part of the result */ - while ((e = strchr(fmt, '%')) != NULL) { + while ((e = strchr(fmt, '%')) != nullptr) { addstr2buff(&buff, fmt, ct_diff2sz(e - fmt)); /* add 'fmt' up to '%' */ switch (*(e + 1)) { /* conversion specifier */ case 's': { /* zero-terminated string */ const char *s = va_arg(argp, char *); - if (s == NULL) s = "(null)"; + if (s == nullptr) s = "(null)"; addstr2buff(&buff, s, strlen(s)); break; } @@ -661,7 +661,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { va_start(argp, fmt); msg = luaO_pushvfstring(L, fmt, argp); va_end(argp); - if (msg == NULL) /* error? */ + if (msg == nullptr) /* error? */ L->doThrow( LUA_ERRMEM); return msg; } @@ -701,11 +701,11 @@ void luaO_chunkid (char *out, const char *source, size_t srclen) { const char *nl = strchr(source, '\n'); /* find first new line (if any) */ addstr(out, PRE, LL(PRE)); /* add prefix */ bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */ - if (srclen < bufflen && nl == NULL) { /* small one-line source? */ + if (srclen < bufflen && nl == nullptr) { /* small one-line source? */ addstr(out, source, srclen); /* keep it */ } else { - if (nl != NULL) + if (nl != nullptr) srclen = ct_diff2sz(nl - source); /* stop at first newline */ if (srclen > bufflen) srclen = bufflen; addstr(out, source, srclen); diff --git a/src/objects/lobject.h b/src/objects/lobject.h index d500bb66..56177fb2 100644 --- a/src/objects/lobject.h +++ b/src/objects/lobject.h @@ -147,7 +147,7 @@ constexpr bool TValue::isEmpty() const noexcept { return isNil(); } /* macro defining a value corresponding to an absent key */ -#define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY +#define ABSTKEYCONSTANT {nullptr}, LUA_VABSTKEY /* mark an entry as empty */ @@ -1565,7 +1565,7 @@ class Node { } inline GCObject* getKeyGCOrNull() const noexcept { - return isKeyCollectable() ? u.key_val.gc : NULL; + return isKeyCollectable() ? u.key_val.gc : nullptr; } // Key setters @@ -1778,7 +1778,7 @@ inline constexpr int UTF8BUFFSZ = 8; { va_start(argp, fmt); \ msg = luaO_pushvfstring(L, fmt, argp); \ va_end(argp); \ - if (msg == NULL) (L)->doThrow(LUA_ERRMEM); /* only after 'va_end' */ } + if (msg == nullptr) (L)->doThrow(LUA_ERRMEM); /* only after 'va_end' */ } LUAI_FUNC int luaO_utf8esc (char *buff, l_uint32 x); diff --git a/src/objects/lstring.cpp b/src/objects/lstring.cpp index 6fb77dfd..0c05c7c3 100644 --- a/src/objects/lstring.cpp +++ b/src/objects/lstring.cpp @@ -72,7 +72,7 @@ static void tablerehash (TString **vect, unsigned int osize, unsigned int nsize) std::fill_n(vect + osize, nsize - osize, nullptr); for (i = 0; i < osize; i++) { /* rehash old part of the array */ TString *p = vect[i]; - vect[i] = NULL; + vect[i] = nullptr; while (p) { /* for each string in the list */ TString *hnext = p->getNext(); /* save next */ unsigned int h = lmod(p->getHash(), nsize); /* new position */ @@ -96,7 +96,7 @@ void luaS_resize (lua_State *L, unsigned int nsize) { if (nsize < osize) /* shrinking table? */ tablerehash(tb->getHash(), osize, nsize); /* depopulate shrinking part */ newvect = luaM_reallocvector(L, tb->getHash(), osize, nsize, TString*); - if (l_unlikely(newvect == NULL)) { /* reallocation failed? */ + if (l_unlikely(newvect == nullptr)) { /* reallocation failed? */ if (nsize < osize) /* was it shrinking table? */ tablerehash(tb->getHash(), nsize, osize); /* restore to original size */ /* leave table as it was */ @@ -254,8 +254,8 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { stringtable *tb = g->getStringTable(); unsigned int h = luaS_hash(str, l, g->getSeed()); TString **list = &tb->getHash()[lmod(h, tb->getSize())]; - lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ - for (ts = *list; ts != NULL; ts = ts->getNext()) { + lua_assert(str != nullptr); /* otherwise 'memcmp'/'memcpy' are undefined */ + for (ts = *list; ts != nullptr; ts = ts->getNext()) { if (l == cast_uint(ts->getShrlen()) && (memcmp(str, getshrstr(ts), l * sizeof(char)) == 0)) { /* found! */ diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 70fb0c96..4e5fcda0 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -237,11 +237,11 @@ inline Node* hashpointer(const Table* t, T* p) noexcept { ** Common hash part for tables with empty hash parts. That allows all ** tables to have a hash part, avoiding an extra check ("is there a hash ** part?") when indexing. Its sole node has an empty value and a key -** (DEADKEY, NULL) that is different from any valid TValue. +** (DEADKEY, nullptr) that is different from any valid TValue. */ static Node dummynode_ = Node( - {NULL}, LUA_VEMPTY, /* value's value and type */ - LUA_TDEADKEY, 0, {NULL} /* key type, next, and key value */ + {nullptr}, LUA_VEMPTY, /* value's value and type */ + LUA_TDEADKEY, 0, {nullptr} /* key type, next, and key value */ ); @@ -688,14 +688,14 @@ static Value *resizearray (lua_State *L , Table *t, else if (newasize == 0) { /* erasing array? */ Value *op = t->getArray() - oldasize; /* original array's real address */ luaM_freemem(L, op, concretesize(oldasize)); /* free it */ - return NULL; + return nullptr; } else { size_t newasizeb = concretesize(newasize); Value *np = static_cast( - static_cast(luaM_reallocvector(L, NULL, 0, newasizeb, lu_byte))); - if (np == NULL) /* allocation error? */ - return NULL; + static_cast(luaM_reallocvector(L, nullptr, 0, newasizeb, lu_byte))); + if (np == nullptr) /* allocation error? */ + return nullptr; np += newasize; /* shift pointer to the end of value segment */ if (oldasize > 0) { /* move common elements to new position */ @@ -873,7 +873,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned newasize, } /* allocate new array */ newarray = resizearray(L, t, oldasize, newasize); - if (l_unlikely(newarray == NULL && newasize > 0)) { /* allocation failed? */ + if (l_unlikely(newarray == nullptr && newasize > 0)) { /* allocation failed? */ freehash(L, &newt); /* release new hash part */ luaM_error(L); /* raise error (with array unchanged) */ } @@ -881,7 +881,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned newasize, exchangehashpart(t, &newt); /* 't' has the new hash ('newt' has the old) */ t->setArray(newarray); /* set new array part */ t->setArraySize(newasize); - if (newarray != NULL) + if (newarray != nullptr) *t->getLenHint() = newasize / 2u; /* set an initial hint */ clearNewSlice(t, oldasize, newasize); /* re-insert elements from old hash part into new parts */ @@ -1003,7 +1003,7 @@ static Node *getfreepos (Table *t) { return free; } } - return NULL; /* could not find a free place */ + return nullptr; /* could not find a free place */ } @@ -1023,7 +1023,7 @@ static int insertkey (Table *t, const TValue *key, TValue *value) { if (!isempty(gval(mp)) || t->isDummy()) { /* main position is taken? */ Node *othern; Node *f = getfreepos(t); /* get a free place */ - if (f == NULL) /* cannot find a free place? */ + if (f == nullptr) /* cannot find a free place? */ return 0; lua_assert(!t->isDummy()); othern = mainpositionfromnode(t, mp); diff --git a/src/serialization/ldump.cpp b/src/serialization/ldump.cpp index f130326a..ef6a44ed 100644 --- a/src/serialization/ldump.cpp +++ b/src/serialization/ldump.cpp @@ -50,7 +50,7 @@ inline void dumpVector(DumpState* D, const T* v, size_t n) { /* ** Dump the block of memory pointed by 'b' with given 'size'. -** 'b' should not be NULL, except for the last call signaling the end +** 'b' should not be nullptr, except for the last call signaling the end ** of the dump. */ static void dumpBlock (DumpState *D, const void *b, size_t size) { @@ -139,14 +139,14 @@ static void dumpInteger (DumpState *D, lua_Integer x) { /* -** Dump a String. First dump its "size": size==0 means NULL; +** Dump a String. First dump its "size": size==0 means nullptr; ** size==1 is followed by an index and means "reuse saved string with ** that index"; size>=2 is followed by the string contents with real ** size==size-2 and means that string, which will be saved with ** the next available index. */ static void dumpString (DumpState *D, TString *ts) { - if (ts == NULL) + if (ts == nullptr) dumpSize(D, 0); else { TValue idx; @@ -175,7 +175,7 @@ static void dumpCode (DumpState *D, const Proto *f) { auto code = f->getCodeSpan(); dumpInt(D, static_cast(code.size())); dumpAlign(D, sizeof(code[0])); - lua_assert(code.data() != NULL); + lua_assert(code.data() != nullptr); dumpVector(D, code.data(), cast_uint(code.size())); } @@ -231,7 +231,7 @@ static void dumpDebug (DumpState *D, const Proto *f) { auto lineinfo = f->getDebugInfo().getLineInfoSpan(); n = (D->strip) ? 0 : static_cast(lineinfo.size()); dumpInt(D, n); - if (lineinfo.data() != NULL) + if (lineinfo.data() != nullptr) dumpVector(D, lineinfo.data(), cast_uint(n)); auto abslineinfo = f->getDebugInfo().getAbsLineInfoSpan(); n = (D->strip) ? 0 : static_cast(abslineinfo.size()); @@ -268,7 +268,7 @@ static void dumpFunction (DumpState *D, const Proto *f) { dumpConstants(D, f); dumpUpvalues(D, f); dumpProtos(D, f); - dumpString(D, D->strip ? NULL : f->getSource()); + dumpString(D, D->strip ? nullptr : f->getSource()); dumpDebug(D, f); } @@ -308,7 +308,7 @@ int luaU_dump (lua_State *L, const Proto *f, lua_Writer w, void *data, dumpHeader(&D); dumpByte(&D, f->getUpvaluesSize()); dumpFunction(&D, f); - dumpBlock(&D, NULL, 0); /* signal end of dump */ + dumpBlock(&D, nullptr, 0); /* signal end of dump */ return D.status; } diff --git a/src/serialization/lundump.cpp b/src/serialization/lundump.cpp index 33c705b4..8e96af17 100644 --- a/src/serialization/lundump.cpp +++ b/src/serialization/lundump.cpp @@ -80,7 +80,7 @@ static void loadAlign (LoadState *S, unsigned align) { static const void *getaddr_ (LoadState *S, size_t size) { const void *block = luaZ_getaddr(S->Z, size); S->offset += size; - if (block == NULL) + if (block == nullptr) error(S, "truncated fixed buffer"); return block; } @@ -155,7 +155,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { TValue sv; size_t size = loadSize(S); if (size == 0) { /* no string? */ - lua_assert(*sl == NULL); /* must be prefilled */ + lua_assert(*sl == nullptr); /* must be prefilled */ return; } else if (size == 1) { /* previously saved string? */ @@ -175,7 +175,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { } else if (S->fixed) { /* for a fixed buffer, use a fixed string */ const char *s = getaddr(S, size + 1, char); /* get content address */ - *sl = ts = luaS_newextlstr(L, s, size, NULL, NULL); + *sl = ts = luaS_newextlstr(L, s, size, nullptr, nullptr); luaC_objbarrier(L, p, ts); } else { /* create internal copy */ @@ -238,12 +238,12 @@ static void loadConstants (LoadState *S, Proto *f) { break; case LUA_VSHRSTR: case LUA_VLNGSTR: { - lua_assert(f->getSource() == NULL); + lua_assert(f->getSource() == nullptr); loadString(S, f, f->getSourcePtr()); /* use 'source' to anchor string */ - if (f->getSource() == NULL) + if (f->getSource() == nullptr) error(S, "bad format for constant string"); setsvalue2n(S->L, o, f->getSource()); /* save it in the right place */ - f->setSource(NULL); + f->setSource(nullptr); break; } default: error(S, "invalid constant"); diff --git a/src/serialization/lzio.cpp b/src/serialization/lzio.cpp index 62d83833..308ac858 100644 --- a/src/serialization/lzio.cpp +++ b/src/serialization/lzio.cpp @@ -28,7 +28,7 @@ int luaZ_fill (ZIO *z) { lua_unlock(L); buff = z->reader(L, z->data, &size); lua_lock(L); - if (buff == NULL || size == 0) + if (buff == nullptr || size == 0) return EOZ; z->n = size - 1; /* discount char being returned */ z->p = buff; @@ -75,9 +75,9 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) { const void *luaZ_getaddr (ZIO* z, size_t n) { const void *res; if (!checkbuffer(z)) - return NULL; /* no more input */ + return nullptr; /* no more input */ if (z->n < n) /* not enough bytes? */ - return NULL; /* block not whole; cannot give an address */ + return nullptr; /* block not whole; cannot give an address */ res = z->p; /* get block address */ z->n -= n; /* consume these bytes */ z->p += n; diff --git a/src/testing/ltests.cpp b/src/testing/ltests.cpp index 0e08948e..2cb50ef8 100644 --- a/src/testing/ltests.cpp +++ b/src/testing/ltests.cpp @@ -85,7 +85,7 @@ static int tpanic (lua_State *L) { ? lua_tostring(L, -1) : "error object is not a string"; return (badexit("PANIC: unprotected error in call to Lua API (%s)\n", - msg, NULL), + msg, nullptr), 0); /* do not return to Lua */ } @@ -121,7 +121,7 @@ static void warnf (void *ud, const char *msg, int tocont) { mode = 2; else badexit("Invalid control warning in test mode: %s\naborting...\n", - msg, NULL); + msg, nullptr); return; } lasttocont = tocont; @@ -143,7 +143,7 @@ static void warnf (void *ud, const char *msg, int tocont) { case 0: { /* normal */ if (buff[0] != '#' && onoff) /* unexpected warning? */ badexit("Unexpected warning in test mode: %s\naborting...\n", - buff, NULL); + buff, nullptr); } /* FALLTHROUGH */ case 1: { /* allow */ if (onoff) @@ -223,9 +223,9 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { int type; if (mc->memlimit == 0) { /* first time? */ char *limit = getenv("MEMLIMIT"); /* initialize memory limit */ - mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; + mc->memlimit = limit ? strtoul(limit, nullptr, 10) : ULONG_MAX; } - if (block == NULL) { + if (block == nullptr) { type = (oldsize < LUA_NUMTYPES) ? cast_int(oldsize) : 0; oldsize = 0; } @@ -236,28 +236,28 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { } if (size == 0) { freeblock(mc, block); - return NULL; + return nullptr; } if (mc->failnext) { mc->failnext = 0; - return NULL; /* fake a single memory allocation error */ + return nullptr; /* fake a single memory allocation error */ } if (mc->countlimit != ~0UL && size != oldsize) { /* count limit in use? */ if (mc->countlimit == 0) - return NULL; /* fake a memory allocation error */ + return nullptr; /* fake a memory allocation error */ mc->countlimit--; } if (size > oldsize && mc->total+size-oldsize > mc->memlimit) - return NULL; /* fake a memory allocation error */ + return nullptr; /* fake a memory allocation error */ else { memHeader *newblock; int i; size_t commonsize = (oldsize < size) ? oldsize : size; size_t realsize = sizeof(memHeader) + size + MARKSIZE; - if (realsize < size) return NULL; /* arithmetic overflow! */ + if (realsize < size) return nullptr; /* arithmetic overflow! */ newblock = static_cast(malloc(realsize)); /* alloc a new block */ - if (newblock == NULL) - return NULL; /* really out of memory? */ + if (newblock == nullptr) + return nullptr; /* really out of memory? */ if (block) { memcpy(newblock + 1, block + 1, commonsize); /* copy old contents */ freeblock(mc, block); /* erase (and check) old copy */ @@ -397,7 +397,7 @@ static void checkobjref (global_State *g, GCObject *f, GCObject *t) { /* -** Version where 't' can be NULL. In that case, it should not apply the +** Version where 't' can be nullptr. In that case, it should not apply the ** macro 'obj2gco' over the object. ('t' may have several types, so this ** definition must be a macro.) Most checks need this version, because ** the check may run while an object is still being created. @@ -498,15 +498,15 @@ static void check_stack (global_State *g, lua_State *L1) { CallInfo *ci; UpVal *uv; assert(!isdead(g, L1)); - if (L1->getStack().p == NULL) { /* incomplete thread? */ - assert(L1->getOpenUpval() == NULL && L1->getCI() == NULL); + if (L1->getStack().p == nullptr) { /* incomplete thread? */ + assert(L1->getOpenUpval() == nullptr && L1->getCI() == nullptr); return; } - for (uv = L1->getOpenUpval(); uv != NULL; uv = uv->getOpenNext()) + for (uv = L1->getOpenUpval(); uv != nullptr; uv = uv->getOpenNext()) assert(uv->isOpen()); /* must be open */ assert(L1->getTop().p <= L1->getStackLast().p); assert(L1->getTbclist().p <= L1->getTop().p); - for (ci = L1->getCI(); ci != NULL; ci = ci->getPrevious()) { + for (ci = L1->getCI(); ci != nullptr; ci = ci->getPrevious()) { assert(ci->topRef().p <= L1->getStackLast().p); assert(lua_checkpc(ci)); } @@ -672,7 +672,7 @@ static l_mem checklist (global_State *g, int maybedead, int tof, incifingray(g, o, &total); assert(!tof == !tofinalize(o)); } - for (o = reallyold; o != NULL; o = o->getNext()) { + for (o = reallyold; o != nullptr; o = o->getNext()) { checkobject(g, o, 0, GCAge::Old); incifingray(g, o, &total); assert(!tof == !tofinalize(o)); @@ -692,11 +692,11 @@ int lua_checkmemory (lua_State *L) { assert(!iswhite(gcvalue(g->getRegistry()))); } assert(!isdead(g, gcvalue(g->getRegistry()))); - assert(g->getSweepGC() == NULL || g->isSweepPhase()); + assert(g->getSweepGC() == nullptr || g->isSweepPhase()); totalin = checkgrays(g); /* check 'fixedgc' list */ - for (o = g->getFixedGC(); o != NULL; o = o->getNext()) { + for (o = g->getFixedGC(); o != nullptr; o = o->getNext()) { assert(o->getType() == LUA_VSHRSTR && isgray(o) && getage(o) == GCAge::Old); } @@ -710,7 +710,7 @@ int lua_checkmemory (lua_State *L) { g->getFinObjSur(), g->getFinObjOld1(), g->getFinObjROld()); /* check 'tobefnz' list */ - for (o = g->getToBeFnz(); o != NULL; o = o->getNext()) { + for (o = g->getToBeFnz(); o != nullptr; o = o->getNext()) { checkobject(g, o, 0, GCAge::New); incifingray(g, o, &totalshould); assert(tofinalize(o)); @@ -738,7 +738,7 @@ static char *buildop (Proto *p, int pc, char *buff) { OpCode o = static_cast(InstructionView(i).opcode()); const char *name = opnames[o]; int line = luaG_getfuncline(p, pc); - int lineinfo = (p->getLineInfo() != NULL) ? p->getLineInfo()[pc] : 0; + int lineinfo = (p->getLineInfo() != nullptr) ? p->getLineInfo()[pc] : 0; if (lineinfo == ABSLINEINFO) buff += sprintf(buff, "(__"); else @@ -828,7 +828,7 @@ static int listabslineinfo (lua_State *L) { luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); p = getproto(obj_at(L, 1)); - luaL_argcheck(L, p->getAbsLineInfo() != NULL, 1, "function has no debug info"); + luaL_argcheck(L, p->getAbsLineInfo() != nullptr, 1, "function has no debug info"); lua_createtable(L, 2 * p->getAbsLineInfoSize(), 0); for (i=0; i < p->getAbsLineInfoSize(); i++) { lua_pushinteger(L, p->getAbsLineInfo()[i].getPC()); @@ -848,7 +848,7 @@ static int listlocals (lua_State *L) { luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); p = getproto(obj_at(L, 1)); - while ((name = p->getLocalName(++i, pc)) != NULL) /* Phase 25b */ + while ((name = p->getLocalName(++i, pc)) != nullptr) /* Phase 25b */ lua_pushstring(L, name); return i-1; } @@ -876,10 +876,10 @@ int lua_printallstack (lua_State *L) { CallInfo *ci = L->getBaseCI(); printf("stack: >>\n"); for (p = L->getStack().p; p < L->getTop().p; p++) { - if (ci != NULL && p == ci->funcRef().p) { + if (ci != nullptr && p == ci->funcRef().p) { printf(" ---\n"); if (ci == L->getCI()) - ci = NULL; /* printed last frame */ + ci = nullptr; /* printed last frame */ else ci = ci->getNext(); } @@ -959,7 +959,7 @@ static int alloc_failnext (lua_State *L) { static int settrick (lua_State *L) { if (ttisnil(obj_at(L, 1))) - l_Trick = NULL; + l_Trick = nullptr; else l_Trick = gcvalue(obj_at(L, 1)); return 0; @@ -1183,7 +1183,7 @@ static int string_query (lua_State *L) { else if (cast_uint(s) < tb->getSize()) { TString *ts; int n = 0; - for (ts = tb->getHash()[s]; ts != NULL; ts = ts->getNext()) { + for (ts = tb->getHash()[s]; ts != nullptr; ts = ts->getNext()) { setsvalue2s(L, L->getTop().p, ts); api_incr_top(L); n++; @@ -1238,7 +1238,7 @@ static int upvalue (lua_State *L) { luaL_checktype(L, 1, LUA_TFUNCTION); if (lua_isnone(L, 3)) { const char *name = lua_getupvalue(L, 1, n); - if (name == NULL) return 0; + if (name == nullptr) return 0; lua_pushstring(L, name); return 2; } @@ -1325,7 +1325,7 @@ static int newstate (lua_State *L) { static lua_State *getstate (lua_State *L) { lua_State *L1 = static_cast(lua_touserdata(L, 1)); - luaL_argcheck(L, L1 != NULL, 1, "state expected"); + luaL_argcheck(L, L1 != nullptr, 1, "state expected"); return L1; } @@ -1338,7 +1338,7 @@ static int loadlib (lua_State *L) { luaL_requiref(L1, "T", luaB_opentests, 0); lua_assert(lua_type(L1, -1) == LUA_TTABLE); /* 'requiref' should not reload module already loaded... */ - luaL_requiref(L1, "T", NULL, 1); /* seg. fault if it reloads */ + luaL_requiref(L1, "T", nullptr, 1); /* seg. fault if it reloads */ /* ...but should return the same module */ lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); return 0; @@ -1407,7 +1407,7 @@ static int checkpanic (lua_State *L) { b.paniccode = luaL_optstring(L, 2, ""); b.L = L; L1 = lua_newstate(f, ud, 0); /* create new state */ - if (L1 == NULL) { /* error? */ + if (L1 == nullptr) { /* error? */ lua_pushstring(L, MEMERRMSG); return 1; } @@ -1430,7 +1430,7 @@ static int checkpanic (lua_State *L) { static int externKstr (lua_State *L) { size_t len; const char *s = luaL_checklstring(L, 1, &len); - lua_pushexternalstring(L, s, len, NULL, NULL); + lua_pushexternalstring(L, s, len, nullptr, nullptr); return 1; } @@ -1446,8 +1446,8 @@ static int externstr (lua_State *L) { void *ud; lua_Alloc allocf = lua_getallocf(L, &ud); /* get allocation function */ /* create the buffer */ - char *buff = cast_charp((*allocf)(ud, NULL, 0, len + 1)); - if (buff == NULL) { /* memory error? */ + char *buff = cast_charp((*allocf)(ud, nullptr, 0, len + 1)); + if (buff == nullptr) { /* memory error? */ lua_pushliteral(L, "not enough memory"); lua_error(L); /* raise a memory error */ } @@ -1591,7 +1591,7 @@ static const char ops[] = "+-*%^/\\&|~<>_!"; static int runC (lua_State *L, lua_State *L1, const char *pc) { char buff[300]; int status = 0; - if (pc == NULL) return luaL_error(L, "attempt to runC null script"); + if (pc == nullptr) return luaL_error(L, "attempt to runC null script"); for (;;) { const char *inst = getstring; if EQ("") return 0; @@ -1624,7 +1624,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { int sz = getnum; const char *msg = getstring; if (*msg == '\0') - msg = NULL; /* to test 'luaL_checkstack' with no message */ + msg = nullptr; /* to test 'luaL_checkstack' with no message */ luaL_checkstack(L1, sz, msg); } else if EQ("rawcheckstack") { @@ -1911,7 +1911,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { } else if EQ("testudata") { int i = getindex; - lua_pushboolean(L1, luaL_testudata(L1, i, getstring) != NULL); + lua_pushboolean(L1, luaL_testudata(L1, i, getstring) != nullptr); } else if EQ("error") { lua_error(L1); @@ -1950,10 +1950,10 @@ static struct X { int x; } x; const char *s = lua_tostring(L1, getindex); const char *s1 = lua_pushstring(L1, s); cast_void(s1); /* to avoid warnings */ - lua_longassert((s == NULL && s1 == NULL) || strcmp(s, s1) == 0); + lua_longassert((s == nullptr && s1 == nullptr) || strcmp(s, s1) == 0); } else if EQ("Ltolstring") { - luaL_tolstring(L1, getindex, NULL); + luaL_tolstring(L1, getindex, nullptr); } else if EQ("type") { lua_pushstring(L1, luaL_typename(L1, getnum)); @@ -2065,7 +2065,7 @@ static void Chook (lua_State *L, lua_Debug *ar) { */ static void sethookaux (lua_State *L, int mask, int count, const char *scpt) { if (*scpt == '\0') { /* no script? */ - lua_sethook(L, NULL, 0, 0); /* turn off hooks */ + lua_sethook(L, nullptr, 0, 0); /* turn off hooks */ return; } lua_getfield(L, LUA_REGISTRYINDEX, "C_HOOK"); /* get C_HOOK table */ @@ -2084,7 +2084,7 @@ static void sethookaux (lua_State *L, int mask, int count, const char *scpt) { static int sethook (lua_State *L) { if (lua_isnoneornil(L, 1)) - lua_sethook(L, NULL, 0, 0); /* turn off hooks */ + lua_sethook(L, nullptr, 0, 0); /* turn off hooks */ else { const char *scpt = luaL_checkstring(L, 1); const char *smask = luaL_checkstring(L, 2); @@ -2118,7 +2118,7 @@ static int coresume (lua_State *L) { #if !defined(LUA_USE_POSIX) -#define nonblock NULL +#define nonblock nullptr #else @@ -2237,7 +2237,7 @@ static const struct luaL_Reg tests_funcs[] = { {"externstr", externstr}, {"testvector", testvector}, {"nonblock", nonblock}, - {NULL, NULL} + {nullptr, nullptr} }; diff --git a/src/testing/ltests.h b/src/testing/ltests.h index 878e86d2..d3c51084 100644 --- a/src/testing/ltests.h +++ b/src/testing/ltests.h @@ -127,7 +127,7 @@ LUA_API void *debug_realloc (void *ud, void *block, #define luaL_newstate() \ - lua_newstate(debug_realloc, &l_memcontrol, luaL_makeseed(NULL)) + lua_newstate(debug_realloc, &l_memcontrol, luaL_makeseed(nullptr)) #define luai_openlibs(L) \ { luaL_openlibs(L); \ luaL_requiref(L, "T", luaB_opentests, 1); \ diff --git a/src/vm/lopnames.h b/src/vm/lopnames.h index a7284b45..bc172693 100644 --- a/src/vm/lopnames.h +++ b/src/vm/lopnames.h @@ -96,7 +96,7 @@ static const char *const opnames[] = { "VARARG", "VARARGPREP", "EXTRAARG", - NULL + nullptr }; #endif diff --git a/src/vm/lvm.cpp b/src/vm/lvm.cpp index 0dd2562e..35c59525 100644 --- a/src/vm/lvm.cpp +++ b/src/vm/lvm.cpp @@ -1252,7 +1252,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { L->getStackSubsystem().setTopPtr(ra + b); /* top signals number of arguments */ /* else previous instruction set top */ savepc(ci); /* in case of errors */ - if ((newci = L->preCall( ra, nresults)) == NULL) + if ((newci = L->preCall( ra, nresults)) == nullptr) updatetrap(ci); /* C call; nothing else to be done */ else { /* Lua call: run function in this same C frame */ ci = newci; diff --git a/src/vm/lvm_comparison.cpp b/src/vm/lvm_comparison.cpp index b3167e30..ae2346d1 100644 --- a/src/vm/lvm_comparison.cpp +++ b/src/vm/lvm_comparison.cpp @@ -185,7 +185,7 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { /* ** Main operation for equality of Lua values; return 't1 == t2'. -** L == NULL means raw equality (no metamethods) +** L == nullptr means raw equality (no metamethods) */ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { const TValue *tm; @@ -232,17 +232,17 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { return luaS_eqstr(tsvalue(t1), tsvalue(t2)); case LUA_VUSERDATA: { if (uvalue(t1) == uvalue(t2)) return 1; - else if (L == NULL) return 0; + else if (L == nullptr) return 0; tm = fasttm(L, uvalue(t1)->getMetatable(), TMS::TM_EQ); - if (tm == NULL) + if (tm == nullptr) tm = fasttm(L, uvalue(t2)->getMetatable(), TMS::TM_EQ); break; /* will try TM */ } case LUA_VTABLE: { if (hvalue(t1) == hvalue(t2)) return 1; - else if (L == NULL) return 0; + else if (L == nullptr) return 0; tm = fasttm(L, hvalue(t1)->getMetatable(), TMS::TM_EQ); - if (tm == NULL) + if (tm == nullptr) tm = fasttm(L, hvalue(t2)->getMetatable(), TMS::TM_EQ); break; /* will try TM */ } @@ -251,7 +251,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { default: /* functions and threads */ return (gcvalue(t1) == gcvalue(t2)); } - if (tm == NULL) /* no TM? */ + if (tm == nullptr) /* no TM? */ return 0; /* objects are different */ else { int tag = luaT_callTMres(L, tm, t1, t2, L->getTop().p); /* call TM */ diff --git a/src/vm/lvm_table.cpp b/src/vm/lvm_table.cpp index 8f63bc30..5b4f194e 100644 --- a/src/vm/lvm_table.cpp +++ b/src/vm/lvm_table.cpp @@ -60,7 +60,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, } else { /* 't' is a table */ tm = fasttm(L, hvalue(t)->getMetatable(), TMS::TM_INDEX); /* table's metamethod */ - if (tm == NULL) { /* no metamethod? */ + if (tm == nullptr) { /* no metamethod? */ setnilvalue(s2v(val)); /* result is nil */ return LUA_VNIL; } @@ -109,7 +109,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, if (hres != HNOTATABLE) { /* is 't' a table? */ Table *h = hvalue(t); /* save 't' table */ tm = fasttm(L, h->getMetatable(), TMS::TM_NEWINDEX); /* get metamethod */ - if (tm == NULL) { /* no metamethod? */ + if (tm == nullptr) { /* no metamethod? */ sethvalue2s(L, L->getTop().p, h); /* anchor 't' */ L->getStackSubsystem().push(); /* assume EXTRA_STACK */ luaH_finishset(L, h, key, val, hres); /* set new value */