Commit 7d7f3b2d authored by Hans Johnson's avatar Hans Johnson Committed by Brad King

Configure: Add KWSYS_NULLPTR macro for C++ code

When building with C++11 or greater, use the `nullptr` keyword.
parent 8f755ee9
......@@ -68,8 +68,8 @@ class CommandLineArgumentsInternal
public:
CommandLineArgumentsInternal()
{
this->UnknownArgumentCallback = 0;
this->ClientData = 0;
this->UnknownArgumentCallback = KWSYS_NULLPTR;
this->ClientData = KWSYS_NULLPTR;
this->LastArgument = 0;
}
......@@ -187,7 +187,7 @@ int CommandLineArguments::Parse()
switch (cs->ArgumentType) {
case NO_ARGUMENT:
// No value
if (!this->PopulateVariable(cs, 0)) {
if (!this->PopulateVariable(cs, KWSYS_NULLPTR)) {
return 0;
}
break;
......@@ -340,7 +340,7 @@ void CommandLineArguments::AddCallback(const char* argument,
s.Callback = callback;
s.CallData = call_data;
s.VariableType = CommandLineArguments::NO_VARIABLE_TYPE;
s.Variable = 0;
s.Variable = KWSYS_NULLPTR;
s.Help = help;
this->Internals->Callbacks[argument] = s;
......@@ -355,8 +355,8 @@ void CommandLineArguments::AddArgument(const char* argument,
CommandLineArgumentsCallbackStructure s;
s.Argument = argument;
s.ArgumentType = type;
s.Callback = 0;
s.CallData = 0;
s.Callback = KWSYS_NULLPTR;
s.CallData = KWSYS_NULLPTR;
s.VariableType = vtype;
s.Variable = variable;
s.Help = help;
......@@ -427,7 +427,7 @@ const char* CommandLineArguments::GetHelp(const char* arg)
CommandLineArguments::Internal::CallbacksMap::iterator it =
this->Internals->Callbacks.find(arg);
if (it == this->Internals->Callbacks.end()) {
return 0;
return KWSYS_NULLPTR;
}
// Since several arguments may point to the same argument, find the one this
......@@ -621,7 +621,7 @@ void CommandLineArguments::PopulateVariable(bool* variable,
void CommandLineArguments::PopulateVariable(int* variable,
const std::string& value)
{
char* res = 0;
char* res = KWSYS_NULLPTR;
*variable = static_cast<int>(strtol(value.c_str(), &res, 10));
// if ( res && *res )
// {
......@@ -632,7 +632,7 @@ void CommandLineArguments::PopulateVariable(int* variable,
void CommandLineArguments::PopulateVariable(double* variable,
const std::string& value)
{
char* res = 0;
char* res = KWSYS_NULLPTR;
*variable = strtod(value.c_str(), &res);
// if ( res && *res )
// {
......@@ -669,7 +669,7 @@ void CommandLineArguments::PopulateVariable(std::vector<bool>* variable,
void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
const std::string& value)
{
char* res = 0;
char* res = KWSYS_NULLPTR;
variable->push_back(static_cast<int>(strtol(value.c_str(), &res, 10)));
// if ( res && *res )
// {
......@@ -680,7 +680,7 @@ void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
void CommandLineArguments::PopulateVariable(std::vector<double>* variable,
const std::string& value)
{
char* res = 0;
char* res = KWSYS_NULLPTR;
variable->push_back(strtod(value.c_str(), &res));
// if ( res && *res )
// {
......
......@@ -20,6 +20,12 @@
#define @KWSYS_NAMESPACE@__has_cpp_attribute(x) 0
#endif
#if __cplusplus >= 201103L
#define @KWSYS_NAMESPACE@_NULLPTR nullptr
#else
#define @KWSYS_NAMESPACE@_NULLPTR 0
#endif
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
#if __cplusplus >= 201703L && @KWSYS_NAMESPACE@__has_cpp_attribute(fallthrough)
#define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]]
......@@ -48,6 +54,7 @@
#define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
#define KWSYS_FALLTHROUGH @KWSYS_NAMESPACE@_FALLTHROUGH
#define KWSYS_NULLPTR @KWSYS_NAMESPACE@_NULLPTR
#endif
#endif
......@@ -48,7 +48,7 @@ unsigned long Directory::GetNumberOfFiles() const
const char* Directory::GetFile(unsigned long dindex) const
{
if (dindex >= this->Internal->Files.size()) {
return 0;
return KWSYS_NULLPTR;
}
return this->Internal->Files[dindex].c_str();
}
......
......@@ -65,7 +65,7 @@ Encoding::CommandLineArguments::CommandLineArguments(int ac,
for (int i = 0; i < ac; i++) {
this->argv_[i] = strdup(av[i]);
}
this->argv_[ac] = 0;
this->argv_[ac] = KWSYS_NULLPTR;
}
Encoding::CommandLineArguments::CommandLineArguments(int ac,
......@@ -75,7 +75,7 @@ Encoding::CommandLineArguments::CommandLineArguments(int ac,
for (int i = 0; i < ac; i++) {
this->argv_[i] = kwsysEncoding_DupToNarrow(av[i]);
}
this->argv_[ac] = 0;
this->argv_[ac] = KWSYS_NULLPTR;
}
Encoding::CommandLineArguments::~CommandLineArguments()
......@@ -90,7 +90,7 @@ Encoding::CommandLineArguments::CommandLineArguments(
{
this->argv_.resize(other.argv_.size());
for (size_t i = 0; i < this->argv_.size(); i++) {
this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : KWSYS_NULLPTR;
}
}
......@@ -105,7 +105,7 @@ Encoding::CommandLineArguments& Encoding::CommandLineArguments::operator=(
this->argv_.resize(other.argv_.size());
for (i = 0; i < this->argv_.size(); i++) {
this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : KWSYS_NULLPTR;
}
}
......@@ -193,7 +193,7 @@ std::string Encoding::ToNarrow(const std::wstring& str)
std::wstring Encoding::ToWide(const char* cstr)
{
std::wstring wstr;
size_t length = kwsysEncoding_mbstowcs(0, cstr, 0) + 1;
size_t length = kwsysEncoding_mbstowcs(KWSYS_NULLPTR, cstr, 0) + 1;
if (length > 0) {
std::vector<wchar_t> wchars(length);
if (kwsysEncoding_mbstowcs(&wchars[0], cstr, length) > 0) {
......@@ -206,7 +206,7 @@ std::wstring Encoding::ToWide(const char* cstr)
std::string Encoding::ToNarrow(const wchar_t* wcstr)
{
std::string str;
size_t length = kwsysEncoding_wcstombs(0, wcstr, 0) + 1;
size_t length = kwsysEncoding_wcstombs(KWSYS_NULLPTR, wcstr, 0) + 1;
if (length > 0) {
std::vector<char> chars(length);
if (kwsysEncoding_wcstombs(&chars[0], wcstr, length) > 0) {
......
......@@ -430,7 +430,7 @@ void Glob::SetRelative(const char* dir)
const char* Glob::GetRelative()
{
if (this->Relative.empty()) {
return 0;
return KWSYS_NULLPTR;
}
return this->Relative.c_str();
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -306,7 +306,7 @@ inline int Chdir(const std::string& dir)
return chdir(dir.c_str());
}
inline void Realpath(const std::string& path, std::string& resolved_path,
std::string* errorMessage = 0)
std::string* errorMessage = KWSYS_NULLPTR)
{
char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
......@@ -352,7 +352,7 @@ double SystemTools::GetTime(void)
11644473600.0);
#else
struct timeval t;
gettimeofday(&t, 0);
gettimeofday(&t, KWSYS_NULLPTR);
return 1.0 * double(t.tv_sec) + 0.000001 * double(t.tv_usec);
#endif
}
......@@ -414,7 +414,7 @@ public:
const envchar* Release(const envchar* env)
{
const envchar* old = 0;
const envchar* old = KWSYS_NULLPTR;
iterator i = this->find(env);
if (i != this->end()) {
old = *i;
......@@ -489,7 +489,7 @@ void SystemTools::GetPath(std::vector<std::string>& path, const char* env)
const char* SystemTools::GetEnvImpl(const char* key)
{
const char* v = 0;
const char* v = KWSYS_NULLPTR;
#if defined(_WIN32)
std::string env;
if (SystemTools::GetEnv(key, env)) {
......@@ -545,7 +545,7 @@ bool SystemTools::HasEnv(const char* key)
#else
const char* v = getenv(key);
#endif
return v != 0;
return v != KWSYS_NULLPTR;
}
bool SystemTools::HasEnv(const std::string& key)
......@@ -776,7 +776,7 @@ bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
while ((pos = dir.find('/', pos)) != std::string::npos) {
topdir = dir.substr(0, pos);
if (Mkdir(topdir) == 0 && mode != 0) {
if (Mkdir(topdir) == 0 && mode != KWSYS_NULLPTR) {
SystemTools::SetPermissions(topdir, *mode);
}
......@@ -795,7 +795,7 @@ bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
) {
return false;
}
} else if (mode != 0) {
} else if (mode != KWSYS_NULLPTR) {
SystemTools::SetPermissions(topdir, *mode);
}
......@@ -1520,7 +1520,7 @@ char* SystemTools::AppendStrings(const char* str1, const char* str2)
size_t len1 = strlen(str1);
char* newstr = new char[len1 + strlen(str2) + 1];
if (!newstr) {
return 0;
return KWSYS_NULLPTR;
}
strcpy(newstr, str1);
strcat(newstr + len1, str2);
......@@ -1543,7 +1543,7 @@ char* SystemTools::AppendStrings(const char* str1, const char* str2,
size_t len1 = strlen(str1), len2 = strlen(str2);
char* newstr = new char[len1 + len2 + strlen(str3) + 1];
if (!newstr) {
return 0;
return KWSYS_NULLPTR;
}
strcpy(newstr, str1);
strcat(newstr + len1, str2);
......@@ -1593,7 +1593,7 @@ size_t SystemTools::CountChar(const char* str, char c)
char* SystemTools::RemoveChars(const char* str, const char* toremove)
{
if (!str) {
return NULL;
return KWSYS_NULLPTR;
}
char* clean_str = new char[strlen(str) + 1];
char* ptr = clean_str;
......@@ -1615,7 +1615,7 @@ char* SystemTools::RemoveChars(const char* str, const char* toremove)
char* SystemTools::RemoveCharsButUpperHex(const char* str)
{
if (!str) {
return 0;
return KWSYS_NULLPTR;
}
char* clean_str = new char[strlen(str) + 1];
char* ptr = clean_str;
......@@ -1696,7 +1696,7 @@ bool SystemTools::StringEndsWith(const std::string& str1, const char* str2)
const char* SystemTools::FindLastString(const char* str1, const char* str2)
{
if (!str1 || !str2) {
return NULL;
return KWSYS_NULLPTR;
}
size_t len1 = strlen(str1), len2 = strlen(str2);
......@@ -1709,7 +1709,7 @@ const char* SystemTools::FindLastString(const char* str1, const char* str2)
} while (ptr-- != str1);
}
return NULL;
return KWSYS_NULLPTR;
}
// Duplicate string
......@@ -1719,7 +1719,7 @@ char* SystemTools::DuplicateString(const char* str)
char* newstr = new char[strlen(str) + 1];
return strcpy(newstr, str);
}
return NULL;
return KWSYS_NULLPTR;
}
// Return a cropped string
......@@ -3100,7 +3100,7 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut,
std::string SystemTools::CollapseFullPath(const std::string& in_relative)
{
return SystemTools::CollapseFullPath(in_relative, 0);
return SystemTools::CollapseFullPath(in_relative, KWSYS_NULLPTR);
}
void SystemTools::AddTranslationPath(const std::string& a,
......
......@@ -76,7 +76,7 @@ int testCommandLineArguments(int argc, char* argv[])
int some_int_variable = 10;
double some_double_variable = 10.10;
char* some_string_variable = 0;
char* some_string_variable = KWSYS_NULLPTR;
std::string some_stl_string_variable = "";
bool some_bool_variable = false;
bool some_bool_variable1 = false;
......@@ -202,7 +202,7 @@ int testCommandLineArguments(int argc, char* argv[])
for (cc = 0; cc < strings_argument.size(); ++cc) {
delete[] strings_argument[cc];
strings_argument[cc] = 0;
strings_argument[cc] = KWSYS_NULLPTR;
}
return res;
}
......@@ -21,7 +21,7 @@ int testCommandLineArguments1(int argc, char* argv[])
arg.Initialize(argc, argv);
int n = 0;
char* m = 0;
char* m = KWSYS_NULLPTR;
std::string p;
int res = 0;
......@@ -55,11 +55,11 @@ int testCommandLineArguments1(int argc, char* argv[])
delete[] m;
}
char** newArgv = 0;
char** newArgv = KWSYS_NULLPTR;
int newArgc = 0;
arg.GetUnusedArguments(&newArgc, &newArgv);
int cc;
const char* valid_unused_args[9] = { 0,
const char* valid_unused_args[9] = { KWSYS_NULLPTR,
"--ignored",
"--second-ignored",
"third-ignored",
......
......@@ -84,7 +84,7 @@ static int testRobustEncoding()
// this conversion could fail
std::wstring wstr = kwsys::Encoding::ToWide(cstr);
wstr = kwsys::Encoding::ToWide(NULL);
wstr = kwsys::Encoding::ToWide(KWSYS_NULLPTR);
if (wstr != L"") {
const wchar_t* wcstr = wstr.c_str();
std::cout << "ToWide(NULL) returned";
......@@ -112,7 +112,7 @@ static int testRobustEncoding()
std::string win_str = kwsys::Encoding::ToNarrow(cwstr);
#endif
std::string str = kwsys::Encoding::ToNarrow(NULL);
std::string str = kwsys::Encoding::ToNarrow(KWSYS_NULLPTR);
if (str != "") {
std::cout << "ToNarrow(NULL) returned " << str << std::endl;
ret++;
......
......@@ -52,7 +52,7 @@ static const char* toUnixPaths[][2] = {
{ "\\\\usr\\local\\bin\\passwd", "//usr/local/bin/passwd" },
{ "\\\\usr\\lo cal\\bin\\pa sswd", "//usr/lo cal/bin/pa sswd" },
{ "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo\\ cal/bin/pa\\ sswd" },
{ 0, 0 }
{ KWSYS_NULLPTR, KWSYS_NULLPTR }
};
static bool CheckConvertToUnixSlashes(std::string const& input,
......@@ -68,10 +68,11 @@ static bool CheckConvertToUnixSlashes(std::string const& input,
return true;
}
static const char* checkEscapeChars[][4] = { { "1 foo 2 bar 2", "12", "\\",
"\\1 foo \\2 bar \\2" },
{ " {} ", "{}", "#", " #{#} " },
{ 0, 0, 0, 0 } };
static const char* checkEscapeChars[][4] = {
{ "1 foo 2 bar 2", "12", "\\", "\\1 foo \\2 bar \\2" },
{ " {} ", "{}", "#", " #{#} " },
{ KWSYS_NULLPTR, KWSYS_NULLPTR, KWSYS_NULLPTR, KWSYS_NULLPTR }
};
static bool CheckEscapeChars(std::string const& input,
const char* chars_to_escape, char escape_char,
......@@ -159,7 +160,7 @@ static bool CheckFileOperations()
res = false;
}
// calling with 0 pointer should return false
if (kwsys::SystemTools::MakeDirectory(0)) {
if (kwsys::SystemTools::MakeDirectory(KWSYS_NULLPTR)) {
std::cerr << "Problem with MakeDirectory(0)" << std::endl;
res = false;
}
......@@ -217,11 +218,11 @@ static bool CheckFileOperations()
}
// calling with 0 pointer should return false
if (kwsys::SystemTools::FileExists(0)) {
if (kwsys::SystemTools::FileExists(KWSYS_NULLPTR)) {
std::cerr << "Problem with FileExists(0)" << std::endl;
res = false;
}
if (kwsys::SystemTools::FileExists(0, true)) {
if (kwsys::SystemTools::FileExists(KWSYS_NULLPTR, true)) {
std::cerr << "Problem with FileExists(0) as file" << std::endl;
res = false;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment