mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
KWSys 2018-06-14 (2b0ca1d8)
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 2b0ca1d85d6e3fcf3b3fa375783c33524629f256 (master).
Upstream Shortlog
-----------------
Marian Klymov (3):
0b9f51a1 Remove redundant calls to c_str
361e54e3 Get rid of redundant string initialization
61501133 SystemInformation: Avoid use of dangling pointers on Solaris
This commit is contained in:
committed by
Brad King
parent
3af8c7715b
commit
f3cd44263e
@@ -3495,7 +3495,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
|
|||||||
|
|
||||||
// Chip Model Name
|
// Chip Model Name
|
||||||
this->ChipID.ModelName =
|
this->ChipID.ModelName =
|
||||||
this->ExtractValueFromCpuInfoFile(buffer, "model name").c_str();
|
this->ExtractValueFromCpuInfoFile(buffer, "model name");
|
||||||
|
|
||||||
// L1 Cache size
|
// L1 Cache size
|
||||||
// Different architectures may show different names for the caches.
|
// Different architectures may show different names for the caches.
|
||||||
@@ -4613,7 +4613,7 @@ std::string SystemInformationImplementation::ExtractValueFromSysCtl(
|
|||||||
std::string SystemInformationImplementation::RunProcess(
|
std::string SystemInformationImplementation::RunProcess(
|
||||||
std::vector<const char*> args)
|
std::vector<const char*> args)
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
std::string buffer;
|
||||||
|
|
||||||
// Run the application
|
// Run the application
|
||||||
kwsysProcess* gp = kwsysProcess_New();
|
kwsysProcess* gp = kwsysProcess_New();
|
||||||
@@ -4668,11 +4668,7 @@ std::string SystemInformationImplementation::RunProcess(
|
|||||||
std::string SystemInformationImplementation::ParseValueFromKStat(
|
std::string SystemInformationImplementation::ParseValueFromKStat(
|
||||||
const char* arguments)
|
const char* arguments)
|
||||||
{
|
{
|
||||||
std::vector<const char*> args;
|
std::vector<std::string> args_string;
|
||||||
args.clear();
|
|
||||||
args.push_back("kstat");
|
|
||||||
args.push_back("-p");
|
|
||||||
|
|
||||||
std::string command = arguments;
|
std::string command = arguments;
|
||||||
size_t start = std::string::npos;
|
size_t start = std::string::npos;
|
||||||
size_t pos = command.find(' ', 0);
|
size_t pos = command.find(' ', 0);
|
||||||
@@ -4691,35 +4687,35 @@ std::string SystemInformationImplementation::ParseValueFromKStat(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!inQuotes) {
|
if (!inQuotes) {
|
||||||
std::string arg = command.substr(start + 1, pos - start - 1);
|
args_string.push_back(command.substr(start + 1, pos - start - 1));
|
||||||
|
std::string& arg = args_string.back();
|
||||||
|
|
||||||
// Remove the quotes if any
|
// Remove the quotes if any
|
||||||
size_t quotes = arg.find('"');
|
arg.erase(std::remove(arg.begin(), arg.end(), '"'), arg.end());
|
||||||
while (quotes != std::string::npos) {
|
|
||||||
arg.erase(quotes, 1);
|
|
||||||
quotes = arg.find('"');
|
|
||||||
}
|
|
||||||
args.push_back(arg.c_str());
|
|
||||||
start = pos;
|
start = pos;
|
||||||
}
|
}
|
||||||
pos = command.find(' ', pos + 1);
|
pos = command.find(' ', pos + 1);
|
||||||
}
|
}
|
||||||
std::string lastArg = command.substr(start + 1, command.size() - start - 1);
|
args_string.push_back(command.substr(start + 1, command.size() - start - 1));
|
||||||
args.push_back(lastArg.c_str());
|
|
||||||
|
|
||||||
|
std::vector<const char*> args;
|
||||||
|
args.reserve(3 + args_string.size());
|
||||||
|
args.push_back("kstat");
|
||||||
|
args.push_back("-p");
|
||||||
|
for (size_t i = 0; i < args_string.size(); ++i) {
|
||||||
|
args.push_back(args_string[i].c_str());
|
||||||
|
}
|
||||||
args.push_back(KWSYS_NULLPTR);
|
args.push_back(KWSYS_NULLPTR);
|
||||||
|
|
||||||
std::string buffer = this->RunProcess(args);
|
std::string buffer = this->RunProcess(args);
|
||||||
|
|
||||||
std::string value = "";
|
std::string value;
|
||||||
for (size_t i = buffer.size() - 1; i > 0; i--) {
|
for (size_t i = buffer.size() - 1; i > 0; i--) {
|
||||||
if (buffer[i] == ' ' || buffer[i] == '\t') {
|
if (buffer[i] == ' ' || buffer[i] == '\t') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (buffer[i] != '\n' && buffer[i] != '\r') {
|
if (buffer[i] != '\n' && buffer[i] != '\r') {
|
||||||
std::string val = value;
|
value.insert(0u, 1, buffer[i]);
|
||||||
value = buffer[i];
|
|
||||||
value += val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ public:
|
|||||||
for (iterator i = this->begin(); i != this->end(); ++i) {
|
for (iterator i = this->begin(); i != this->end(); ++i) {
|
||||||
# if defined(_WIN32)
|
# if defined(_WIN32)
|
||||||
const std::string s = Encoding::ToNarrow(*i);
|
const std::string s = Encoding::ToNarrow(*i);
|
||||||
kwsysUnPutEnv(s.c_str());
|
kwsysUnPutEnv(s);
|
||||||
# else
|
# else
|
||||||
kwsysUnPutEnv(*i);
|
kwsysUnPutEnv(*i);
|
||||||
# endif
|
# endif
|
||||||
@@ -1973,7 +1973,7 @@ std::string SystemTools::ConvertToUnixOutputPath(const std::string& path)
|
|||||||
}
|
}
|
||||||
// escape spaces and () in the path
|
// escape spaces and () in the path
|
||||||
if (ret.find_first_of(" ") != std::string::npos) {
|
if (ret.find_first_of(" ") != std::string::npos) {
|
||||||
std::string result = "";
|
std::string result;
|
||||||
char lastch = 1;
|
char lastch = 1;
|
||||||
for (const char* ch = ret.c_str(); *ch != '\0'; ++ch) {
|
for (const char* ch = ret.c_str(); *ch != '\0'; ++ch) {
|
||||||
// if it is already escaped then don't try to escape it again
|
// if it is already escaped then don't try to escape it again
|
||||||
@@ -3140,7 +3140,7 @@ void SystemTools::AddTranslationPath(const std::string& a,
|
|||||||
void SystemTools::AddKeepPath(const std::string& dir)
|
void SystemTools::AddKeepPath(const std::string& dir)
|
||||||
{
|
{
|
||||||
std::string cdir;
|
std::string cdir;
|
||||||
Realpath(SystemTools::CollapseFullPath(dir).c_str(), cdir);
|
Realpath(SystemTools::CollapseFullPath(dir), cdir);
|
||||||
SystemTools::AddTranslationPath(cdir, dir);
|
SystemTools::AddTranslationPath(cdir, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ int testCommandLineArguments(int argc, char* argv[])
|
|||||||
int some_int_variable = 10;
|
int some_int_variable = 10;
|
||||||
double some_double_variable = 10.10;
|
double some_double_variable = 10.10;
|
||||||
char* some_string_variable = KWSYS_NULLPTR;
|
char* some_string_variable = KWSYS_NULLPTR;
|
||||||
std::string some_stl_string_variable = "";
|
std::string some_stl_string_variable;
|
||||||
bool some_bool_variable = false;
|
bool some_bool_variable = false;
|
||||||
bool some_bool_variable1 = false;
|
bool some_bool_variable1 = false;
|
||||||
bool bool_arg1 = false;
|
bool bool_arg1 = false;
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ static bool CheckFileOperations()
|
|||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true)) {
|
if (!kwsys::SystemTools::Touch(testNewFile, true)) {
|
||||||
std::cerr << "Problem with Touch for: " << testNewFile << std::endl;
|
std::cerr << "Problem with Touch for: " << testNewFile << std::endl;
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
@@ -415,7 +415,7 @@ static bool CheckFileOperations()
|
|||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
kwsys::SystemTools::Touch(testNewFile.c_str(), true);
|
kwsys::SystemTools::Touch(testNewFile, true);
|
||||||
if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
|
if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
|
||||||
std::cerr << "Problem with RemoveADirectory for: " << testNewDir
|
std::cerr << "Problem with RemoveADirectory for: " << testNewDir
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@@ -806,7 +806,7 @@ static bool CheckFind()
|
|||||||
const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/" +
|
const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/" +
|
||||||
testFindFileName);
|
testFindFileName);
|
||||||
|
|
||||||
if (!kwsys::SystemTools::Touch(testFindFile.c_str(), true)) {
|
if (!kwsys::SystemTools::Touch(testFindFile, true)) {
|
||||||
std::cerr << "Problem with Touch for: " << testFindFile << std::endl;
|
std::cerr << "Problem with Touch for: " << testFindFile << std::endl;
|
||||||
// abort here as the existence of the file only makes the test meaningful
|
// abort here as the existence of the file only makes the test meaningful
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user