Commit ce26403a authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2015-04-16 (1ea01a46)

Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ 1ea01a46 | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' 5843f590..1ea01a46
Ben Boeckel (1):
      425fa73e Add missing malloc return value casts

Brad King (11):
      dec9c30b SharedForward: Hard-code the ldpath buffer size to below VS 14 limit
      9c3eacf8 Add CONTRIBUTING.rst file with instructions to contribute
      cc4046a8 Directory: Work around PGI problem with Linux Large File Support
      5a15cb3b Base64: Use size_t for lenghts in API
      57c3ef1d Suppress deprecation warnings for GetVersionEx on Intel compiler
      b33e7b96 FStream: Fix exception spec on our standard stream replacements
      d4e7f08e Directory: Check opendir return value before using it
      4a698414 hashtable: Give prime number table functions internal linkage
      20f50727 SystemInformation: Add missing 'break' in StacktraceSignalHandler
      69bccf2e SystemTools: Teach Touch with !create to succeed on missing file
      1ea01a46 Tell Git to export '.gitattributes'

Domen Vrankar (5):
      2b042ff6 SystemTools: Optionally report error from GetRealPath
      7c9a970a Glob: Remove dead code
      1b75ad3d Glob: Remove addition of extra '/'
      5d6204e9 Glob: Handle symlink cycles in directory paths
      4890f30c Glob: Add support for directory listing

Jean-Christophe Fillion-Robin (2):
      c38ba638 SystemInformation: Improve Get(Available/Total)VirtualMemory for windows
      58308145 SystemInformation: Improve comments in private implementation

Paul Martin (1):
      d2aa1afd SystemTools: Update CopyFileAlways stream library workarounds

Sean McBride (3):
      87c65319 SharedForward: Suppress clang -Wcast-qual warnings with conditional pragma
      093eae34 SystemInformation: Fix -Wswitch-enum warnings
      9367a33b testHashSTL: Fix warnings by marking private functions static

Simon Gomizelj (1):
      2f0165f1 Terminal: Add xterm-termite to VT100 color support whitelist

Stephen Kelly (3):
      e4fe1d1a SystemTools: Refactor selection of Windows directory APIs
      af86ac7d SystemTools: Fix build with SunCC/stlport.
      d30c9b03 Workaround SolarisStudio bug with libstdc++.
parent 14f6f347
.git* export-ignore
.gitattributes -export-ignore
/GitSetup export-ignore
/SetupForDevelopment.sh export-ignore eol=lf
/CONTRIBUTING.rst conflict-marker-size=78
*.c whitespace=tab-in-indent,no-lf-at-eof
*.h whitespace=tab-in-indent,no-lf-at-eof
*.h.in whitespace=tab-in-indent,no-lf-at-eof
*.cxx whitespace=tab-in-indent,no-lf-at-eof
*.hxx whitespace=tab-in-indent,no-lf-at-eof
*.hxx.in whitespace=tab-in-indent,no-lf-at-eof
*.txt whitespace=tab-in-indent,no-lf-at-eof
*.cmake whitespace=tab-in-indent,no-lf-at-eof
......@@ -115,10 +115,10 @@ void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
actually knowing how much data to expect (if the input is not a multiple of
3 bytes then the extra padding needed to complete the encode 4 bytes will
stop the decoding anyway). */
unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,
unsigned char *output,
int mark_end)
size_t kwsysBase64_Encode(const unsigned char *input,
size_t length,
unsigned char *output,
int mark_end)
{
const unsigned char *ptr = input;
const unsigned char *end = input + length;
......@@ -157,7 +157,7 @@ unsigned long kwsysBase64_Encode(const unsigned char *input,
optr += 4;
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
/*--------------------------------------------------------------------------*/
......@@ -207,10 +207,10 @@ int kwsysBase64_Decode3(const unsigned char *src, unsigned char *dest)
'length' parameter is ignored. This enables the caller to decode a stream
without actually knowing how much decoded data to expect (of course, the
buffer must be large enough). */
unsigned long kwsysBase64_Decode(const unsigned char *input,
unsigned long length,
unsigned char *output,
unsigned long max_input_length)
size_t kwsysBase64_Decode(const unsigned char *input,
size_t length,
unsigned char *output,
size_t max_input_length)
{
const unsigned char *ptr = input;
unsigned char *optr = output;
......@@ -226,7 +226,7 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
ptr += 4;
}
......@@ -240,7 +240,7 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
ptr += 4;
}
......@@ -275,5 +275,5 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
}
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
......@@ -14,6 +14,8 @@
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <stddef.h> /* size_t */
/* Redefine all public interface symbol names to be in the proper
namespace. These macros are used internally to kwsys only, and are
not visible to user code. Use kwsysHeaderDump.pl to reproduce
......@@ -68,10 +70,10 @@ kwsysEXPORT void kwsysBase64_Encode1(const unsigned char *src,
* the extra padding needed to complete the encode 4 bytes will stop
* the decoding anyway).
*/
kwsysEXPORT unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,
unsigned char *output,
int mark_end);
kwsysEXPORT size_t kwsysBase64_Encode(const unsigned char *input,
size_t length,
unsigned char *output,
int mark_end);
/**
* Decode 4 bytes into a 3 byte string. Returns the number of bytes
......@@ -92,10 +94,10 @@ kwsysEXPORT int kwsysBase64_Decode3(const unsigned char *src,
* much decoded data to expect (of course, the buffer must be large
* enough).
*/
kwsysEXPORT unsigned long kwsysBase64_Decode(const unsigned char *input,
unsigned long length,
unsigned char *output,
unsigned long max_input_length);
kwsysEXPORT size_t kwsysBase64_Decode(const unsigned char *input,
size_t length,
unsigned char *output,
size_t max_input_length);
#if defined(__cplusplus)
} /* extern "C" */
......
Contributing to KWSys
*********************
Overview
========
KWSys is kept in its own Git repository and shared by several projects
via copies in their source trees. Changes to KWSys should not be made
directly in a host project, except perhaps in maintenance branches.
Please visit
http://public.kitware.com/Wiki/KWSys/Git
to contribute changes directly to KWSys upstream. Once changes are
reviewed, tested, and integrated there then the copies of KWSys within
dependent projects can be updated to get the changes.
Issues
======
KWSys has no independent issue tracker. After encountering an issue
(bug) please try to submit a patch using the above instructions.
Otherwise please report the issue to the tracker for the project that
hosts the copy of KWSys in which the problem was found.
License
=======
We do not require any formal copyright assignment or contributor license
agreement. Any contributions intentionally sent upstream are presumed
to be offerred under terms of the OSI-approved BSD 3-clause License.
See `Copyright.txt`_ for details.
.. _`Copyright.txt`: Copyright.txt
......@@ -203,13 +203,18 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& na
#include <sys/types.h>
#include <dirent.h>
/* There is a problem with the Portland compiler, large file
support and glibc/Linux system headers:
http://www.pgroup.com/userforum/viewtopic.php?
p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
*/
#if defined(__PGI) && defined(__USE_FILE_OFFSET64)
# define dirent dirent64
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
// p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
// Work around the problem by mapping dirent the same way as readdir.
#if defined(__PGI) && defined(__GLIBC__)
# define kwsys_dirent_readdir dirent
# define kwsys_dirent_readdir64 dirent64
# define kwsys_dirent kwsys_dirent_lookup(readdir)
# define kwsys_dirent_lookup(x) kwsys_dirent_lookup_delay(x)
# define kwsys_dirent_lookup_delay(x) kwsys_dirent_##x
#else
# define kwsys_dirent dirent
#endif
namespace KWSYS_NAMESPACE
......@@ -226,7 +231,7 @@ bool Directory::Load(const kwsys_stl::string& name)
return 0;
}
for (dirent* d = readdir(dir); d; d = readdir(dir) )
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir) )
{
this->Internal->Files.push_back(d->d_name);
}
......@@ -239,8 +244,13 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& na
{
DIR* dir = opendir(name.c_str());
if (!dir)
{
return 0;
}
unsigned long count = 0;
for (dirent* d = readdir(dir); d; d = readdir(dir) )
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir) )
{
count++;
}
......
......@@ -44,7 +44,7 @@ wchar_t* kwsysEncoding_DupToWide(const char* str)
size_t length = kwsysEncoding_mbstowcs(NULL, str, 0) + 1;
if(length > 0)
{
ret = malloc((length)*sizeof(wchar_t));
ret = (wchar_t*)malloc((length)*sizeof(wchar_t));
ret[0] = 0;
kwsysEncoding_mbstowcs(ret, str, length);
}
......@@ -71,7 +71,7 @@ char* kwsysEncoding_DupToNarrow(const wchar_t* str)
size_t length = kwsysEncoding_wcstombs(0, str, 0) + 1;
if(length > 0)
{
ret = malloc(length);
ret = (char*)malloc(length);
ret[0] = 0;
kwsysEncoding_wcstombs(ret, str, length);
}
......
......@@ -18,6 +18,11 @@
namespace @KWSYS_NAMESPACE@
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
# if defined(_NOEXCEPT)
# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT
# else
# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT
# endif
template<typename CharType,typename Traits>
class basic_filebuf : public std::basic_filebuf<CharType,Traits>
{
......@@ -85,7 +90,7 @@ namespace @KWSYS_NAMESPACE@
return buf_;
}
~basic_ifstream()
~basic_ifstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT
{
buf_->close();
delete buf_;
......@@ -147,7 +152,7 @@ class basic_ofstream : public std::basic_ostream<CharType,Traits>
{
return buf_.get();
}
~basic_ofstream()
~basic_ofstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT
{
buf_->close();
delete buf_;
......@@ -160,6 +165,7 @@ class basic_ofstream : public std::basic_ostream<CharType,Traits>
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
# undef @KWSYS_NAMESPACE@_FStream_NOEXCEPT
#else
using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
......
......@@ -19,6 +19,7 @@
#include KWSYS_HEADER(Directory.hxx)
#include KWSYS_HEADER(stl/string)
#include KWSYS_HEADER(stl/vector)
#include KWSYS_HEADER(stl/algorithm)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
......@@ -30,6 +31,8 @@
# include "SystemTools.hxx.in"
# include "kwsys_stl.hxx.in"
# include "kwsys_stl_string.hxx.in"
# include "kwsys_stl_vector.hxx.in"
# include "kwsys_stl_algorithm.hxx.in"
#endif
#include <ctype.h>
......@@ -66,6 +69,10 @@ Glob::Glob()
// RecurseThroughSymlinks is true by default for backwards compatibility,
// not because it's a good idea...
this->FollowedSymlinkCount = 0;
// Keep separate variables for directory listing for back compatibility
this->ListDirs = true;
this->RecurseListDirs = false;
}
//----------------------------------------------------------------------------
......@@ -214,16 +221,15 @@ kwsys_stl::string Glob::PatternToRegex(const kwsys_stl::string& pattern,
}
//----------------------------------------------------------------------------
void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir)
bool Glob::RecurseDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir, GlobMessages* messages)
{
kwsys::Directory d;
if ( !d.Load(dir) )
{
return;
return true;
}
unsigned long cc;
kwsys_stl::string fullname;
kwsys_stl::string realname;
kwsys_stl::string fname;
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
......@@ -248,15 +254,6 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
fname = kwsys::SystemTools::LowerCase(fname);
#endif
if ( start == 0 )
{
fullname = dir + fname;
}
else
{
fullname = dir + "/" + fname;
}
bool isDir = kwsys::SystemTools::FileIsDirectory(realname);
bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname);
......@@ -265,8 +262,67 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
if (isSymLink)
{
++this->FollowedSymlinkCount;
kwsys_stl::string realPathErrorMessage;
kwsys_stl::string canonicalPath(SystemTools::GetRealPath(dir,
&realPathErrorMessage));
if(!realPathErrorMessage.empty())
{
if(messages)
{
messages->push_back(Message(
Glob::error, "Canonical path generation from path '"
+ dir + "' failed! Reason: '" + realPathErrorMessage + "'"));
}
return false;
}
if(kwsys_stl::find(this->VisitedSymlinks.begin(),
this->VisitedSymlinks.end(),
canonicalPath) == this->VisitedSymlinks.end())
{
if(this->RecurseListDirs)
{
// symlinks are treated as directories
this->AddFile(this->Internals->Files, realname);
}
this->VisitedSymlinks.push_back(canonicalPath);
if(!this->RecurseDirectory(start+1, realname, messages))
{
this->VisitedSymlinks.pop_back();
return false;
}
this->VisitedSymlinks.pop_back();
}
// else we have already visited this symlink - prevent cyclic recursion
else if(messages)
{
kwsys_stl::string message;
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator
pathIt = kwsys_stl::find(this->VisitedSymlinks.begin(),
this->VisitedSymlinks.end(),
canonicalPath);
pathIt != this->VisitedSymlinks.end(); ++pathIt)
{
message += *pathIt + "\n";
}
message += canonicalPath + "/" + fname;
messages->push_back(Message(Glob::cyclicRecursion, message));
}
}
else
{
if(this->RecurseListDirs)
{
this->AddFile(this->Internals->Files, realname);
}
if(!this->RecurseDirectory(start+1, realname, messages))
{
return false;
}
}
this->RecurseDirectory(start+1, realname);
}
else
{
......@@ -277,17 +333,19 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
}
}
}
return true;
}
//----------------------------------------------------------------------------
void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir)
const kwsys_stl::string& dir, GlobMessages* messages)
{
//kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
bool last = ( start == this->Internals->Expressions.size()-1 );
if ( last && this->Recurse )
{
this->RecurseDirectory(start, dir);
this->RecurseDirectory(start, dir, messages);
return;
}
......@@ -302,7 +360,6 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
return;
}
unsigned long cc;
kwsys_stl::string fullname;
kwsys_stl::string realname;
kwsys_stl::string fname;
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
......@@ -327,22 +384,14 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
fname = kwsys::SystemTools::LowerCase(fname);
#endif
if ( start == 0 )
{
fullname = dir + fname;
}
else
{
fullname = dir + "/" + fname;
}
//kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl;
//kwsys_ios::cout << "Match: "
// << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
//kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl;
//kwsys_ios::cout << "Real name: " << realname << kwsys_ios::endl;
if ( !last &&
!kwsys::SystemTools::FileIsDirectory(realname) )
if( (!last && !kwsys::SystemTools::FileIsDirectory(realname))
|| (!this->ListDirs && last &&
kwsys::SystemTools::FileIsDirectory(realname)) )
{
continue;
}
......@@ -355,14 +404,14 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
}
else
{
this->ProcessDirectory(start+1, realname + "/");
this->ProcessDirectory(start+1, realname, messages);
}
}
}
}
//----------------------------------------------------------------------------
bool Glob::FindFiles(const kwsys_stl::string& inexpr)
bool Glob::FindFiles(const kwsys_stl::string& inexpr, GlobMessages* messages)
{
kwsys_stl::string cexpr;
kwsys_stl::string::size_type cc;
......@@ -458,11 +507,11 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
// Handle network paths
if ( skip > 0 )
{
this->ProcessDirectory(0, fexpr.substr(0, skip) + "/");
this->ProcessDirectory(0, fexpr.substr(0, skip) + "/", messages);
}
else
{
this->ProcessDirectory(0, "/");
this->ProcessDirectory(0, "/", messages);
}
return true;
}
......
......@@ -39,12 +39,37 @@ class GlobInternals;
*/
class @KWSYS_NAMESPACE@_EXPORT Glob
{
public:
enum MessageType
{
error,
cyclicRecursion
};
struct Message
{
MessageType type;
kwsys_stl::string content;
Message(MessageType t, const kwsys_stl::string& c) :
type(t),
content(c)
{}
Message(const Message& msg) :
type(msg.type),
content(msg.content)
{}
};
typedef kwsys_stl::vector<Message> GlobMessages;
typedef kwsys_stl::vector<Message>::iterator GlobMessagesIterator;
public:
Glob();
~Glob();
//! Find all files that match the pattern.
bool FindFiles(const kwsys_stl::string& inexpr);
bool FindFiles(const kwsys_stl::string& inexpr,
GlobMessages* messages = 0);
//! Return the list of files that matched.
kwsys_stl::vector<kwsys_stl::string>& GetFiles();
......@@ -80,15 +105,26 @@ public:
bool require_whole_string = true,
bool preserve_case = false);
/** Getters and setters for enabling and disabling directory
listing in recursive and non recursive globbing mode.
If listing is enabled in recursive mode it also lists
directory symbolic links even if follow symlinks is enabled. */
void SetListDirs(bool list) { this->ListDirs=list; }
bool GetListDirs() const { return this->ListDirs; }
void SetRecurseListDirs(bool list) { this->RecurseListDirs=list; }
bool GetRecurseListDirs() const { return this->RecurseListDirs; }
protected:
//! Process directory
void ProcessDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir);
const kwsys_stl::string& dir,
GlobMessages* messages);
//! Process last directory, but only when recurse flags is on. That is
// effectively like saying: /path/to/file/**/file
void RecurseDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir);
bool RecurseDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir,
GlobMessages* messages);
//! Add regular expression
void AddExpression(const kwsys_stl::string& expr);
......@@ -101,6 +137,9 @@ protected:
kwsys_stl::string Relative;
bool RecurseThroughSymlinks;
unsigned int FollowedSymlinkCount;
kwsys_stl::vector<kwsys_stl::string> VisitedSymlinks;
bool ListDirs;
bool RecurseListDirs;
private:
Glob(const Glob&); // Not implemented.
......
......@@ -547,7 +547,7 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int prPipe, const char* file)
}
if(file)
{
*pfile = malloc(strlen(file)+1);
*pfile = (char*)malloc(strlen(file)+1);
if(!*pfile)
{
return 0;
......@@ -1468,7 +1468,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp)
cp->RealWorkingDirectoryLength = 4096;
#endif
cp->RealWorkingDirectory =
malloc((size_t)(cp->RealWorkingDirectoryLength));
(char*)malloc((size_t)(cp->RealWorkingDirectoryLength));
if(!cp->RealWorkingDirectory)
{
return 0;
......
......@@ -340,7 +340,11 @@ kwsysProcess* kwsysProcess_New(void)
osv.dwOSVersionInfoSize = sizeof(osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
# pragma warning (push)
# pragma warning (disable:4996)
# ifdef __INTEL_COMPILER
# pragma warning (disable:1478)
# else
# pragma warning (disable:4996)
# endif
#endif
GetVersionEx(&osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
......@@ -2382,7 +2386,11 @@ static kwsysProcess_List* kwsysProcess_List_New(void)
osv.dwOSVersionInfoSize = sizeof(osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
# pragma warning (push)
# pragma warning (disable:4996)
# ifdef __INTEL_COMPILER
# pragma warning (disable:1478)
# else
# pragma warning (disable:4996)
# endif
#endif
GetVersionEx(&osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
......
......@@ -8,3 +8,5 @@ details.
You are probably reading this file in the source tree of a surrounding
project. In that case, see "../README.kwsys" for details of using
KWSys in your project.
See CONTRIBUTING.rst for instructions to contribute KWSys changes.
......@@ -65,6 +65,15 @@
See the comments below for specific explanations of each macro.
*/
/* Disable -Wcast-qual warnings since they are too hard to fix in a
cross-platform way. */
#if defined(__clang__) && defined(__has_warning)
# if __has_warning("-Wcast-qual")
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wcast-qual"
# endif
#endif
/*--------------------------------------------------------------------------*/
/* Full path to the directory in which this executable is built. Do
......@@ -813,7 +822,7 @@ static void kwsys_shared_forward_print_failure(char const* const* argv)
}
/* Static storage space to store the updated environment variable. */
static char kwsys_shared_forward_ldpath[KWSYS_SHARED_FORWARD_MAXPATH*16] = KWSYS_SHARED_FORWARD_LDPATH "=";
static char kwsys_shared_forward_ldpath[65535] = KWSYS_SHARED_FORWARD_LDPATH "=";
/*--------------------------------------------------------------------------*/
/* Main driver function to be called from main. */
......@@ -917,6 +926,13 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
return 1;
}
/* Restore warning stack. */
#if defined(__clang__) && defined(__has_warning)
# if __has_warning("-Wcast-qual")
# pragma clang diagnostic pop
# endif
#endif
#else
# error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once."
#endif