Skip to content

Commit

Permalink
KWSys 2018-01-08 (f7990fc2)
Browse files Browse the repository at this point in the history
Code extracted from:

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

at commit f7990fc29bfb102ead2024ebca07939f690a64e6 (master).

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

Brad King (11):
      c8cfe4e0 SystemTools: Drop SplitProgramFromArgs function
      aa9f3a82 macOS: Account for deployment target when checking for utimensat
      41c93d97 Remove unnecessary testIOS
      7a4cca11 Process: Refactor test compile flag addition
      90886a99 Process: Fix tests under ubsan
      bfdbfe9b Avoid requiring CMake 3.4 string(APPEND)
      1b09cf0d Configure: Add KWSYS_FALLTHROUGH macro for C++ code
      7b6fa277 ConsoleBuf: Add explicit switch case fallthrough markup
      e9557f37 RegularExpression: Fix regression in 'find' method
      09724ac8 hashtable: Avoid use of std::unary_function
      9995f700 hashtable: Drop when building inside CMake

Bradley Lowekamp (1):
      b4507c9c Remove dead code from Configure.h.in

Bryon Bean (1):
      8e428c18 Process: Add function to kill process (and children) with pid

Clinton Stimpson (1):
      e9d2b696 SystemTools: Cache only existing path names in GetActualCaseForPath

Domen Vrankar (1):
      9e0b4d1a SystemTools: set default MakeDirectory permissions mode

Gregor Jasny (1):
      8e029751 SystemTools: Fix IsSubDirectory for subdirs of drive root

Hans Johnson (1):
      7d7f3b2d Configure: Add KWSYS_NULLPTR macro for C++ code

Justin Berger (2):
      6d73752d Allow KWSYSPE_USE_SELECT macro to be overriden at compile time.
      da61baff Added cmake settable property to enable the macro

Matthias Maennich (5):
      6599eda6 testRobustEncoding: restore format flags for std::cout before exiting
      862562ce SystemInformation: fix potential off-by-one write
      13e02b76 processUNIX: close intermediate file descriptor in error case
      73c491e8 processUNIX: fix not null terminated buffer during error reporting
      ce55a255 testSystemTools: fix some copy'n'paste issues

Rolf Eike Beer (9):
      caaef6bb testSystemTools: avoid strcpy()
      a5046656 SystemTool: remove unused Convert*MacroString()
      6ca15069 SystemTools: make Getcwd() more efficient on Windows
      6d7eb3a1 CommandLineArguments: do not check variable before delete[]
      3b8fefea remove pointer checks before calling free()
      cf8beae3 ProcessUNIX: use strdup() instead of open coding it
      5d2aff9d ProcessWin32: use strdup() instead of open coding it
      8717ac15 DynamicLoader: use std::string instead of strcpy() + strcat()
      88d4dd4b CommandLineArguments: use std::string in GenerateHelp()

Sebastian Holtermann (4):
      4d1e8738 RegularExpression: Make compile() reentrant (thread safe)
      64f80068 RegularExpression: Make find() reentrant (thread safe)
      bbc94ba8 RegularExpression: Remove unused code
      cff58f07 RegularExpression: New RegularExpressionMatch class

Steven Velez (1):
      80652055 Directory: Use Windows Extended Paths

Volo Zyko (1):
      9f6cd407 SystemTools: Fix removing of soft links to directories on Windows.

Wouter Klouwen (1):
      749b7506 ProcessUNIX: Use monotonic clock in kwsysProcessTimeGetCurrent() for POSIX

luzpaz (1):
      9a1d5901 Fix trivial typos in text
  • Loading branch information
kwrobot authored and bradking committed Jan 8, 2018
1 parent 035a10a commit cc74cc1
Show file tree
Hide file tree
Showing 32 changed files with 849 additions and 766 deletions.
36 changes: 28 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,20 @@ 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)
GET_PROPERTY(ProcessUNIX_FLAGS SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS)
SET_PROPERTY(SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS "${ProcessUNIX_FLAGS} -DKWSYSPE_USE_SELECT=${KWSYSPE_USE_SELECT}")
ENDIF()

IF(KWSYS_USE_DynamicLoader)
GET_PROPERTY(KWSYS_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
IF(KWSYS_SUPPORTS_SHARED_LIBS)
Expand Down Expand Up @@ -695,9 +705,13 @@ ENDIF()
# selected components. Initialize with required components.
SET(KWSYS_CLASSES)
SET(KWSYS_H_FILES Configure SharedForward)
SET(KWSYS_HXX_FILES Configure String
hashtable hash_fun hash_map hash_set
)
SET(KWSYS_HXX_FILES Configure String)

IF(NOT CMake_SOURCE_DIR)
SET(KWSYS_HXX_FILES ${KWSYS_HXX_FILES}
hashtable hash_fun hash_map hash_set
)
ENDIF()

# Add selected C++ classes.
SET(cppclasses
Expand Down Expand Up @@ -1017,16 +1031,17 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
ENDFOREACH()

# C++ tests
IF(NOT WATCOM)
IF(NOT WATCOM AND NOT CMake_SOURCE_DIR)
SET(KWSYS_CXX_TESTS
testHashSTL
)
ENDIF()
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
testIOS
testConfigure
testSystemTools
testCommandLineArguments
testCommandLineArguments1
testDirectory
)
IF(KWSYS_STL_HAS_WSTRING)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
Expand Down Expand Up @@ -1137,17 +1152,22 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
ENDFOREACH()

SET(testProcess_COMPILE_FLAGS "")
# Some Apple compilers produce bad optimizations in this source.
IF(APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(GNU|LLVM)$")
SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0)
SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -O0")
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL" AND
NOT (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.1.1"))
# Tell IBM XL not to warn about our test infinite loop
# v13.1.1 and newer on Linux ppc64le is clang based and does not accept
# the -qsuppress option
SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010)
SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -qsuppress=1500-010")
ENDIF()
IF(CMAKE_C_FLAGS MATCHES "-fsanitize=")
SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -DCRASH_USING_ABORT")
ENDIF()
SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS "${testProcess_COMPILE_FLAGS}")

# Test SharedForward
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in
Expand Down
47 changes: 19 additions & 28 deletions CommandLineArguments.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -529,38 +529,32 @@ 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
for (mpit = mp.begin(); mpit != mp.end(); mpit++) {
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);
Expand Down Expand Up @@ -627,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 )
// {
Expand All @@ -638,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 )
// {
Expand All @@ -649,10 +643,7 @@ void CommandLineArguments::PopulateVariable(double* variable,
void CommandLineArguments::PopulateVariable(char** variable,
const std::string& value)
{
if (*variable) {
delete[] * variable;
*variable = 0;
}
delete[] * variable;
*variable = new char[value.size() + 1];
strcpy(*variable, value.c_str());
}
Expand All @@ -678,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 )
// {
Expand All @@ -689,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 )
// {
Expand Down
3 changes: 0 additions & 3 deletions Configure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
#define _FILE_OFFSET_BITS 64
#endif
#if 0 && (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64)
#error "_FILE_OFFSET_BITS must be defined to at least 64"
#endif
#endif
#endif

Expand Down
33 changes: 33 additions & 0 deletions Configure.hxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@
#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@

#if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute)
#define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_attribute(x)
#elif defined(__has_cpp_attribute)
#define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_cpp_attribute(x)
#else
#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]]
#elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@__has_cpp_attribute(gnu::fallthrough)
#define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]]
#elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@__has_cpp_attribute(clang::fallthrough)
#define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]]
#endif
#endif
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
#define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0)
#endif

#undef @KWSYS_NAMESPACE@__has_cpp_attribute

/* If building a C++ file in kwsys itself, give the source file
access to the macros without a configured namespace. */
#if defined(KWSYS_NAMESPACE)
Expand All @@ -22,6 +53,8 @@
#define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
#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
2 changes: 2 additions & 0 deletions ConsoleBuf.hxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ private:
if (m_isConsoleInput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeInputCodepage = input_pipe_codepage;
break;
Expand All @@ -290,6 +291,7 @@ private:
if (m_isConsoleOutput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeOutputCodepage = output_pipe_codepage;
break;
Expand Down
6 changes: 3 additions & 3 deletions Directory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -118,8 +118,8 @@ bool Directory::Load(const std::string& name)
struct _wfinddata_t data; // data of current file

// Now put them into the file array
srchHandle =
_wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
srchHandle = _wfindfirst_func(
(wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data);
delete[] buf;

if (srchHandle == -1) {
Expand Down
17 changes: 4 additions & 13 deletions DynamicLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions DynamicLoader.hxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace @KWSYS_NAMESPACE@ {
* or absolute) pathname. Otherwise, the dynamic linker searches for the
* library as follows : see ld.so(8) for further details):
* Whereas this distinction does not exist on Win32. Therefore ideally you
* should be doing full path to garantee to have a consistent way of dealing
* should be doing full path to guarantee to have a consistent way of dealing
* with dynamic loading of shared library.
*
* \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
Expand Down Expand Up @@ -72,7 +72,7 @@ public:
static LibraryHandle OpenLibrary(const std::string&);

/** Attempt to detach a dynamic library from the
* process. A value of true is returned if it is sucessful. */
* process. A value of true is returned if it is successful. */
static int CloseLibrary(LibraryHandle);

/** Find the address of the symbol in the given library. */
Expand Down
Loading

0 comments on commit cc74cc1

Please sign in to comment.