Commit e44b0cb2 authored by Kitware Robot's avatar Kitware Robot Committed by Brad King

KWSys 2017-10-12 (ef0ad34d)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit ef0ad34d280f0553fc4f6e7202a5e7d6241cdc9c (master).

Upstream Shortlog
-----------------

Rolf Eike Beer (2):
      8717ac15 DynamicLoader: use std::string instead of strcpy() + strcat()
      88d4dd4b CommandLineArguments: use std::string in GenerateHelp()

Wouter Klouwen (1):
      749b7506 ProcessUNIX: Use monotonic clock in kwsysProcessTimeGetCurrent() for POSIX
parent c551ff58
......@@ -445,8 +445,13 @@ KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_PTRDIFF_T
"Checking whether C compiler has ptrdiff_t in stddef.h" DIRECT)
KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_SSIZE_T
"Checking whether C compiler has ssize_t in unistd.h" DIRECT)
IF(KWSYS_USE_Process)
KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
"Checking whether C compiler has clock_gettime" DIRECT)
ENDIF()
SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES
COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}"
COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T} -DKWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC=${KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC}"
)
IF(DEFINED KWSYS_PROCESS_USE_SELECT)
......
......@@ -529,10 +529,7 @@ void CommandLineArguments::GenerateHelp()
}
}
// Create format for that string
char format[80];
sprintf(format, " %%-%us ", static_cast<unsigned int>(maxlen));
CommandLineArguments::Internal::String::size_type maxstrlen = maxlen;
maxlen += 4; // For the space before and after the option
// Print help for each option
......@@ -540,27 +537,24 @@ void CommandLineArguments::GenerateHelp()
CommandLineArguments::Internal::SetOfStrings::iterator sit;
for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) {
str << std::endl;
char argument[100];
sprintf(argument, "%s", sit->c_str());
std::string argument = *sit;
switch (this->Internals->Callbacks[*sit].ArgumentType) {
case CommandLineArguments::NO_ARGUMENT:
break;
case CommandLineArguments::CONCAT_ARGUMENT:
strcat(argument, "opt");
argument += "opt";
break;
case CommandLineArguments::SPACE_ARGUMENT:
strcat(argument, " opt");
argument += " opt";
break;
case CommandLineArguments::EQUAL_ARGUMENT:
strcat(argument, "=opt");
argument += "=opt";
break;
case CommandLineArguments::MULTI_ARGUMENT:
strcat(argument, " opt opt ...");
argument += " opt opt ...";
break;
}
char buffer[80];
sprintf(buffer, format, argument);
str << buffer;
str << " " << argument.substr(0, maxstrlen) << " ";
}
const char* ptr = this->Internals->Callbacks[mpit->first].Help;
size_t len = strlen(ptr);
......
......@@ -163,17 +163,13 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
{
void* result = 0;
// Need to prepend symbols with '_' on Apple-gcc compilers
size_t len = sym.size();
char* rsym = new char[len + 1 + 1];
strcpy(rsym, "_");
strcat(rsym + 1, sym.c_str());
std::string rsym = '_' + sym;
NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
NSSymbol symbol = NSLookupSymbolInModule(lib, rsym.c_str());
if (symbol) {
result = NSAddressOfSymbol(symbol);
}
delete[] rsym;
// Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
......@@ -237,17 +233,12 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
void* result;
#if defined(__BORLANDC__) || defined(__WATCOMC__)
// Need to prepend symbols with '_'
size_t len = sym.size();
char* rsym = new char[len + 1 + 1];
strcpy(rsym, "_");
strcat(rsym, sym.c_str());
std::string ssym = '_' + sym;
const char* rsym = ssym.c_str();
#else
const char* rsym = sym.c_str();
#endif
result = (void*)GetProcAddress(lib, rsym);
#if defined(__BORLANDC__) || defined(__WATCOMC__)
delete[] rsym;
#endif
// Hack to cast pointer-to-data to pointer-to-function.
#ifdef __WATCOMC__
return *(DynamicLoader::SymbolPointer*)(&result);
......
......@@ -2026,7 +2026,15 @@ static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
{
kwsysProcessTime current;
kwsysProcessTimeNative current_native;
#if KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
struct timespec current_timespec;
clock_gettime(CLOCK_MONOTONIC, &current_timespec);
current_native.tv_sec = current_timespec.tv_sec;
current_native.tv_usec = current_timespec.tv_nsec / 1000;
#else
gettimeofday(&current_native, 0);
#endif
current.tv_sec = (long)current_native.tv_sec;
current.tv_usec = (long)current_native.tv_usec;
return current;
......
......@@ -55,6 +55,21 @@ int KWSYS_PLATFORM_TEST_C_MAIN()
}
#endif
#ifdef TEST_KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
#error "clock_gettime not available on macOS < 10.12"
#endif
#endif
#include <time.h>
int KWSYS_PLATFORM_TEST_C_MAIN()
{
struct timespec ts;
return clock_gettime(CLOCK_MONOTONIC, &ts);
}
#endif
#ifdef TEST_KWSYS_C_TYPE_MACROS
char* info_macros =
#if defined(__SIZEOF_SHORT__)
......
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