Skip to content

Commit

Permalink
En masse NULL -> nullptr replace
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerw authored and archshift committed Oct 23, 2014
1 parent 2ac3a80 commit a26541a
Show file tree
Hide file tree
Showing 211 changed files with 1,768 additions and 1,746 deletions.
6 changes: 3 additions & 3 deletions src/AllocationPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class cListAllocationPool : public cAllocationPool<T>
for (size_t i = 0; i < NumElementsInReserve; i++)
{
void * space = malloc(sizeof(T));
if (space == NULL)
if (space == nullptr)
{
m_Callbacks->OnStartUsingReserve();
break;
Expand All @@ -68,7 +68,7 @@ class cListAllocationPool : public cAllocationPool<T>
if (m_FreeList.size() <= NumElementsInReserve)
{
void * space = malloc(sizeof(T));
if (space != NULL)
if (space != nullptr)
{
return new(space) T;
}
Expand All @@ -90,7 +90,7 @@ class cListAllocationPool : public cAllocationPool<T>
}
virtual void Free(T * a_ptr) override
{
if (a_ptr == NULL)
if (a_ptr == nullptr)
{
return;
}
Expand Down
36 changes: 18 additions & 18 deletions src/Bindings/DeprecatedBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushnumber(tolua_S, (lua_Number)cBlockInfo::GetLightValue((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -55,7 +55,7 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushnumber(tolua_S, (lua_Number)cBlockInfo::GetSpreadLightFalloff((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -81,7 +81,7 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -107,7 +107,7 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, cBlockInfo::IsOneHitDig((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -133,7 +133,7 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, cBlockInfo::IsPistonBreakable((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -159,7 +159,7 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, cBlockInfo::IsSnowable((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -185,7 +185,7 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, (bool)cBlockInfo::IsSolid((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -211,7 +211,7 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
{
tolua_error(tolua_S, "array indexing out of range.", NULL);
tolua_error(tolua_S, "array indexing out of range.", nullptr);
}
tolua_pushboolean(tolua_S, (bool)cBlockInfo::FullyOccupiesVoxel((BLOCKTYPE)BlockType));
return 1;
Expand All @@ -224,16 +224,16 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)

void DeprecatedBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, NULL);

tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, NULL);
tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, NULL);
tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, NULL);
tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, NULL);
tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, NULL);
tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, NULL);
tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, NULL);
tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, NULL);
tolua_beginmodule(tolua_S, nullptr);

tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, nullptr);
tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, nullptr);
tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, nullptr);
tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, nullptr);
tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, nullptr);
tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, nullptr);
tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, nullptr);
tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, nullptr);

tolua_endmodule(tolua_S);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/LuaChunkStay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

cLuaChunkStay::cLuaChunkStay(cPluginLua & a_Plugin) :
m_Plugin(a_Plugin),
m_LuaState(NULL)
m_LuaState(nullptr)
{
}

Expand Down
54 changes: 27 additions & 27 deletions src/Bindings/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const cLuaState::cRet cLuaState::Return = {};
// cLuaState:

cLuaState::cLuaState(const AString & a_SubsystemName) :
m_LuaState(NULL),
m_LuaState(nullptr),
m_IsOwned(false),
m_SubsystemName(a_SubsystemName),
m_NumCurrentFunctionArgs(-1)
Expand Down Expand Up @@ -90,7 +90,7 @@ cLuaState::~cLuaState()

void cLuaState::Create(void)
{
if (m_LuaState != NULL)
if (m_LuaState != nullptr)
{
LOGWARNING("%s: Trying to create an already-existing LuaState, ignoring.", __FUNCTION__);
return;
Expand Down Expand Up @@ -119,7 +119,7 @@ void cLuaState::RegisterAPILibs(void)

void cLuaState::Close(void)
{
if (m_LuaState == NULL)
if (m_LuaState == nullptr)
{
LOGWARNING("%s: Trying to close an invalid LuaState, ignoring.", __FUNCTION__);
return;
Expand All @@ -134,7 +134,7 @@ void cLuaState::Close(void)
return;
}
lua_close(m_LuaState);
m_LuaState = NULL;
m_LuaState = nullptr;
m_IsOwned = false;
}

Expand All @@ -144,7 +144,7 @@ void cLuaState::Close(void)

void cLuaState::Attach(lua_State * a_State)
{
if (m_LuaState != NULL)
if (m_LuaState != nullptr)
{
LOGINFO("%s: Already contains a LuaState (0x%p), will be closed / detached.", __FUNCTION__, m_LuaState);
if (m_IsOwned)
Expand All @@ -166,7 +166,7 @@ void cLuaState::Attach(lua_State * a_State)

void cLuaState::Detach(void)
{
if (m_LuaState == NULL)
if (m_LuaState == nullptr)
{
return;
}
Expand All @@ -179,7 +179,7 @@ void cLuaState::Detach(void)
Close();
return;
}
m_LuaState = NULL;
m_LuaState = nullptr;
}


Expand Down Expand Up @@ -869,7 +869,7 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
size_t len = 0;
const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
if (data != NULL)
if (data != nullptr)
{
a_Value.assign(data, len);
}
Expand Down Expand Up @@ -919,7 +919,7 @@ void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
{
if (lua_isnil(m_LuaState, a_StackPos))
{
a_ReturnedVal = NULL;
a_ReturnedVal = nullptr;
return;
}
tolua_Error err;
Expand All @@ -937,7 +937,7 @@ void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
{
if (lua_isnil(m_LuaState, a_StackPos))
{
a_ReturnedVal = NULL;
a_ReturnedVal = nullptr;
return;
}
tolua_Error err;
Expand Down Expand Up @@ -1002,7 +1002,7 @@ bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable,
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
Expand Down Expand Up @@ -1035,7 +1035,7 @@ bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, in
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
Expand Down Expand Up @@ -1068,7 +1068,7 @@ bool cLuaState::CheckParamTable(int a_StartParam, int a_EndParam)
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
Expand Down Expand Up @@ -1101,7 +1101,7 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam)
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
Expand Down Expand Up @@ -1134,7 +1134,7 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam)
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
Expand Down Expand Up @@ -1167,7 +1167,7 @@ bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam)
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s",
(entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str()
(entry.name != nullptr) ? entry.name : "?", i, GetTypeText(i).c_str()
);
return false;
} // for i - Param
Expand Down Expand Up @@ -1200,7 +1200,7 @@ bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam)
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s",
(entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str()
(entry.name != nullptr) ? entry.name : "?", i, GetTypeText(i).c_str()
);
return false;
} // for i - Param
Expand All @@ -1224,7 +1224,7 @@ bool cLuaState::CheckParamEnd(int a_Param)
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
AString ErrMsg = Printf("#ferror in function '%s': Too many arguments.", (entry.name != NULL) ? entry.name : "?");
AString ErrMsg = Printf("#ferror in function '%s': Too many arguments.", (entry.name != nullptr) ? entry.name : "?");
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
}
Expand Down Expand Up @@ -1403,7 +1403,7 @@ int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_Sr
case LUA_TUSERDATA:
{
// Get the class name:
const char * type = NULL;
const char * type = nullptr;
if (lua_getmetatable(a_SrcLuaState, i) == 0)
{
LOGWARNING("%s: Unknown class in pos %d, cannot copy.", __FUNCTION__, i);
Expand All @@ -1415,7 +1415,7 @@ int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_Sr
lua_pop(a_SrcLuaState, 1); // Stack -1

// Copy the value:
void * ud = tolua_touserdata(a_SrcLuaState, i, NULL);
void * ud = tolua_touserdata(a_SrcLuaState, i, nullptr);
tolua_pushusertype(m_LuaState, ud, type);
break;
}
Expand All @@ -1441,7 +1441,7 @@ void cLuaState::ToString(int a_StackPos, AString & a_String)
{
size_t len;
const char * s = lua_tolstring(m_LuaState, a_StackPos, &len);
if (s != NULL)
if (s != nullptr)
{
a_String.assign(s, len);
}
Expand All @@ -1463,7 +1463,7 @@ void cLuaState::LogStack(const char * a_Header)
void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header)
{
// Format string consisting only of %s is used to appease the compiler
LOG("%s", (a_Header != NULL) ? a_Header : "Lua C API Stack contents:");
LOG("%s", (a_Header != nullptr) ? a_Header : "Lua C API Stack contents:");
for (int i = lua_gettop(a_LuaState); i > 0; i--)
{
AString Value;
Expand Down Expand Up @@ -1500,7 +1500,7 @@ int cLuaState::ReportFnCallErrors(lua_State * a_LuaState)
// cLuaState::cRef:

cLuaState::cRef::cRef(void) :
m_LuaState(NULL),
m_LuaState(nullptr),
m_Ref(LUA_REFNIL)
{
}
Expand All @@ -1510,7 +1510,7 @@ cLuaState::cRef::cRef(void) :


cLuaState::cRef::cRef(cLuaState & a_LuaState, int a_StackPos) :
m_LuaState(NULL),
m_LuaState(nullptr),
m_Ref(LUA_REFNIL)
{
RefStack(a_LuaState, a_StackPos);
Expand All @@ -1522,7 +1522,7 @@ cLuaState::cRef::cRef(cLuaState & a_LuaState, int a_StackPos) :

cLuaState::cRef::~cRef()
{
if (m_LuaState != NULL)
if (m_LuaState != nullptr)
{
UnRef();
}
Expand All @@ -1535,7 +1535,7 @@ cLuaState::cRef::~cRef()
void cLuaState::cRef::RefStack(cLuaState & a_LuaState, int a_StackPos)
{
ASSERT(a_LuaState.IsValid());
if (m_LuaState != NULL)
if (m_LuaState != nullptr)
{
UnRef();
}
Expand All @@ -1556,7 +1556,7 @@ void cLuaState::cRef::UnRef(void)
{
luaL_unref(*m_LuaState, LUA_REGISTRYINDEX, m_Ref);
}
m_LuaState = NULL;
m_LuaState = nullptr;
m_Ref = LUA_REFNIL;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Bindings/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class cLuaState
void Detach(void);

/** Returns true if the m_LuaState is valid */
bool IsValid(void) const { return (m_LuaState != NULL); }
bool IsValid(void) const { return (m_LuaState != nullptr); }

/** Adds the specified path to package.<a_PathVariable> */
void AddPackagePath(const AString & a_PathVariable, const AString & a_Path);
Expand Down Expand Up @@ -318,10 +318,10 @@ class cLuaState
void ToString(int a_StackPos, AString & a_String);

/** Logs all the elements' types on the API stack, with an optional header for the listing. */
void LogStack(const char * a_Header = NULL);
void LogStack(const char * a_Header = nullptr);

/** Logs all the elements' types on the API stack, with an optional header for the listing. */
static void LogStack(lua_State * a_LuaState, const char * a_Header = NULL);
static void LogStack(lua_State * a_LuaState, const char * a_Header = nullptr);

protected:

Expand Down

6 comments on commit a26541a

@Fatmice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to comment the if block out to get it to compile. Is this an okay thing to do?

/home/quyen/MCServer/src/Generating/ComposableGenerator.cpp(148): error: no operator "!=" matches these operands
operand types are: cBiomeGenPtr != std::nullptr_t
if (m_BiomeGen != nullptr) // Quick fix for generator deinitializing before the world storage finishes loading
^

compilation aborted for /home/quyen/MCServer/src/Generating/ComposableGenerator.cpp (code 2)
make[2]: *** [src/Generating/CMakeFiles/Generating.dir/ComposableGenerator.cpp.o] Error 2
make[1]: *** [src/Generating/CMakeFiles/Generating.dir/all] Error 2
make: *** [all] Error 2

@Fatmice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why is a comparison to null needed? Doesn't this do the same thing?

if (m_BiomeGen) // Quick fix for generator deinitializing before the world storage finishes loading
{
m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap);
}

I thought anything != 0 will always evaluate to true, so a comparison to null is superfluous? Am I missing something?

@madmaxoft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer explicit comparisons.

@Fatmice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but then how could I make the compile error go away?

@madmaxoft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try

if (m_BiomeGen.get() != nullptr)

@Fatmice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works. Compiled successfully on icpc version 15. Thank you.

Please sign in to comment.