Commit 965fce5b authored by Brad King's avatar Brad King Committed by Code Review
Browse files

Merge topic 'update-kwsys' into master

b385607b Merge branch 'upstream-kwsys' into update-kwsys
2eede99a KWSys 2014-03-12 (dd873734)
parents eef18179 b385607b
......@@ -85,6 +85,9 @@
# written.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
IF(POLICY CMP0025)
CMAKE_POLICY(SET CMP0025 NEW)
ENDIF()
#-----------------------------------------------------------------------------
# If a namespace is not specified, use "kwsys" and enable testing.
......@@ -682,6 +685,7 @@ IF(KWSYS_USE_SystemInformation)
# usually it's in libc but on FreeBSD
# it's in libexecinfo
FIND_LIBRARY(EXECINFO_LIB "execinfo")
MARK_AS_ADVANCED(EXECINFO_LIB)
IF (NOT EXECINFO_LIB)
SET(EXECINFO_LIB "")
ENDIF()
......@@ -1073,6 +1077,11 @@ IF(MSVC OR (WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$"))
)
ENDIF()
IF(WIN32)
# Help enforce the use of wide Windows apis.
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
ENDIF()
IF(KWSYS_USE_String)
# Activate code in "String.c". See the comment in the source.
SET_SOURCE_FILES_PROPERTIES(String.c PROPERTIES
......@@ -1133,6 +1142,11 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
testEncoding
)
ENDIF(KWSYS_STL_HAS_WSTRING)
IF(KWSYS_USE_FStream)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
testFStream
)
ENDIF(KWSYS_USE_FStream)
IF(KWSYS_USE_SystemInformation)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
ENDIF(KWSYS_USE_SystemInformation)
......@@ -1214,6 +1228,9 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
# 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)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL")
# Tell IBM XL not to warn about our test infinite loop
SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010)
ENDIF()
# Test SharedForward
......
......@@ -14,6 +14,7 @@
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <@KWSYS_NAMESPACE@/stl/string>
#include <@KWSYS_NAMESPACE@/stl/vector>
/* Define these macros temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
......@@ -25,6 +26,36 @@ namespace @KWSYS_NAMESPACE@
class @KWSYS_NAMESPACE@_EXPORT Encoding
{
public:
// Container class for argc/argv.
class CommandLineArguments
{
public:
// On Windows, get the program command line arguments
// in this Encoding module's 8 bit encoding.
// On other platforms the given argc/argv is used, and
// to be consistent, should be the argc/argv from main().
static CommandLineArguments Main(int argc, char const* const* argv);
// Construct CommandLineArguments with the given
// argc/argv. It is assumed that the string is already
// in the encoding used by this module.
CommandLineArguments(int argc, char const* const* argv);
// Construct CommandLineArguments with the given
// argc and wide argv. This is useful if wmain() is used.
CommandLineArguments(int argc, wchar_t const* const* argv);
~CommandLineArguments();
CommandLineArguments(const CommandLineArguments&);
CommandLineArguments& operator=(const CommandLineArguments&);
int argc() const;
char const* const* argv() const;
protected:
std::vector<char*> argv_;
};
/**
* Convert between char and wchar_t
*/
......
......@@ -68,7 +68,7 @@ size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* str, size_t n)
char* kwsysEncoding_DupToNarrow(const wchar_t* str)
{
char* ret = NULL;
size_t length = kwsysEncoding_wcstombs(0, str, 0);
size_t length = kwsysEncoding_wcstombs(0, str, 0) + 1;
if(length > 0)
{
ret = malloc(length);
......
......@@ -29,6 +29,7 @@
#endif
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
# pragma warning (disable: 4786)
......@@ -42,6 +43,98 @@
namespace KWSYS_NAMESPACE
{
Encoding::CommandLineArguments
Encoding::CommandLineArguments::Main(int argc, char const* const* argv)
{
#ifdef _WIN32
(void) argc;
(void) argv;
int ac;
LPWSTR* w_av = CommandLineToArgvW(GetCommandLineW(), &ac);
std::vector<std::string> av1(ac);
std::vector<char const*> av2(ac);
for(int i=0; i<ac; i++)
{
av1[i] = ToNarrow(w_av[i]);
av2[i] = av1[i].c_str();
}
LocalFree(w_av);
return CommandLineArguments(ac, &av2[0]);
#else
return CommandLineArguments(argc, argv);
#endif
}
Encoding::CommandLineArguments::CommandLineArguments(int ac,
char const* const* av)
{
this->argv_.resize(ac+1);
for(int i=0; i<ac; i++)
{
this->argv_[i] = strdup(av[i]);
}
this->argv_[ac] = 0;
}
Encoding::CommandLineArguments::CommandLineArguments(int ac,
wchar_t const* const* av)
{
this->argv_.resize(ac+1);
for(int i=0; i<ac; i++)
{
this->argv_[i] = kwsysEncoding_DupToNarrow(av[i]);
}
this->argv_[ac] = 0;
}
Encoding::CommandLineArguments::~CommandLineArguments()
{
for(size_t i=0; i<this->argv_.size(); i++)
{
free(argv_[i]);
}
}
Encoding::CommandLineArguments::
CommandLineArguments(const CommandLineArguments& other)
{
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;
}
}
Encoding::CommandLineArguments&
Encoding::CommandLineArguments::operator=(const CommandLineArguments& other)
{
size_t i;
for(i=0; i<this->argv_.size(); i++)
{
free(this->argv_[i]);
}
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;
}
return *this;
}
int Encoding::CommandLineArguments::argc() const
{
return static_cast<int>(this->argv_.size() - 1);
}
char const* const* Encoding::CommandLineArguments::argv() const
{
return &this->argv_[0];
}
#if KWSYS_STL_HAS_WSTRING
kwsys_stl::wstring Encoding::ToWide(const kwsys_stl::string& str)
......
/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(FStream.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "FStream.hxx.in"
#endif
namespace KWSYS_NAMESPACE
{
namespace FStream
{
BOM ReadBOM(std::istream& in)
{
if(!in.good())
{
return BOM_None;
}
unsigned long orig = in.tellg();
unsigned char bom[4];
in.read(reinterpret_cast<char*>(bom), 2);
if(!in.good())
{
in.seekg(orig);
return BOM_None;
}
if(bom[0] == 0xEF && bom[1] == 0xBB)
{
in.read(reinterpret_cast<char*>(bom+2), 1);
if(in.good() && bom[2] == 0xBF)
{
return BOM_UTF8;
}
}
else if(bom[0] == 0xFE && bom[1] == 0xFF)
{
return BOM_UTF16BE;
}
else if(bom[0] == 0x00 && bom[1] == 0x00)
{
in.read(reinterpret_cast<char*>(bom+2), 2);
if(in.good() && bom[2] == 0xFE && bom[3] == 0xFF)
{
return BOM_UTF32BE;
}
}
else if(bom[0] == 0xFF && bom[1] == 0xFE)
{
unsigned long p = in.tellg();
in.read(reinterpret_cast<char*>(bom+2), 2);
if(in.good() && bom[2] == 0x00 && bom[3] == 0x00)
{
return BOM_UTF32LE;
}
in.seekg(p);
return BOM_UTF16LE;
}
in.seekg(orig);
return BOM_None;
}
} // FStream namespace
} //KWSYS_NAMESPACE
......@@ -25,8 +25,9 @@ namespace @KWSYS_NAMESPACE@
typedef std::basic_filebuf<CharType,Traits> my_base_type;
basic_filebuf *open(char const *s,std::ios_base::openmode mode)
{
my_base_type::open(Encoding::ToWide(s).c_str(), mode);
return this;
return static_cast<basic_filebuf*>(
my_base_type::open(Encoding::ToWide(s).c_str(), mode)
);
}
};
......@@ -81,7 +82,7 @@ namespace @KWSYS_NAMESPACE@
internal_buffer_type *rdbuf() const
{
return buf_.get();
return buf_;
}
~basic_ifstream()
......@@ -160,13 +161,28 @@ class basic_ofstream : public std::basic_ostream<CharType,Traits>
typedef basic_ofstream<char> ofstream;
#else
using @KWSYS_NAMESPACE@_ios_namespace::basic_filebuf;
using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
#endif
namespace FStream
{
enum BOM
{
BOM_None,
BOM_UTF8,
BOM_UTF16BE,
BOM_UTF16LE,
BOM_UTF32BE,
BOM_UTF32LE
};
// Read a BOM, if one exists.
// If a BOM exists, the stream is advanced to after the BOM.
// This function requires a seekable stream (but not a relative
// seekable stream).
BOM ReadBOM(std::istream& in);
}
}
#endif
......@@ -2449,6 +2449,7 @@ static void kwsysProcessKill(pid_t process_id)
if(f)
{
size_t nread = fread(buffer, 1, KWSYSPE_PIPE_BUFFER_SIZE, f);
fclose(f);
buffer[nread] = '\0';
if(nread > 0)
{
......@@ -2463,7 +2464,6 @@ static void kwsysProcessKill(pid_t process_id)
}
}
}
fclose(f);
}
}
}
......
......@@ -415,7 +415,7 @@ static int kwsys_shared_forward_realpath(const char* in_path, char* out_path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
/* Implementation for Windows. */
DWORD n = GetFullPathName(in_path, KWSYS_SHARED_FORWARD_MAXPATH,
DWORD n = GetFullPathNameA(in_path, KWSYS_SHARED_FORWARD_MAXPATH,
out_path, 0);
return n > 0 && n <= KWSYS_SHARED_FORWARD_MAXPATH;
#else
......@@ -429,9 +429,9 @@ static int kwsys_shared_forward_samepath(const char* file1, const char* file2)
{
#if defined(_WIN32)
int result = 0;
HANDLE h1 = CreateFile(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
HANDLE h2 = CreateFile(file2, GENERIC_READ, FILE_SHARE_READ, NULL,
HANDLE h2 = CreateFileA(file2, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if(h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE)
{
......@@ -462,7 +462,7 @@ static void kwsys_shared_forward_strerror(char* message)
#if defined(_WIN32) && !defined(__CYGWIN__)
/* Implementation for Windows. */
DWORD original = GetLastError();
DWORD length = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
DWORD length = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, 0, original,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message, KWSYS_SHARED_FORWARD_MAXPATH, 0);
......
......@@ -3162,8 +3162,17 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
kwsys_stl::string cores =
this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
int numberOfCoresPerCPU=atoi(cores.c_str());
this->NumberOfPhysicalCPU=static_cast<unsigned int>(
numberOfCoresPerCPU*(maxId+1));
if (maxId > 0)
{
this->NumberOfPhysicalCPU=static_cast<unsigned int>(
numberOfCoresPerCPU*(maxId+1));
}
else
{
// Linux Sparc: get cpu count
this->NumberOfPhysicalCPU=
atoi(this->ExtractValueFromCpuInfoFile(buffer,"ncpus active").c_str());
}
#else // __CYGWIN__
// does not have "physical id" entries, neither "cpu cores"
......@@ -3185,7 +3194,19 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
// CPU speed (checking only the first processor)
kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
if(!CPUSpeed.empty())
{
this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
}
#ifdef __linux
else
{
// Linux Sparc: CPU speed is in Hz and encoded in hexadecimal
CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"Cpu0ClkTck");
this->CPUSpeedInMHz = static_cast<float>(
strtoull(CPUSpeed.c_str(),0,16))/1000000.0f;
}
#endif
// Chip family
kwsys_stl::string familyStr =
......@@ -4677,11 +4698,28 @@ bool SystemInformationImplementation::QueryHaikuInfo()
{
#if defined(__HAIKU__)
// CPU count
system_info info;
get_system_info(&info);
this->NumberOfPhysicalCPU = info.cpu_count;
this->CPUSpeedInMHz = info.cpu_clock_speed / 1000000.0F;
// CPU speed
uint32 topologyNodeCount = 0;
cpu_topology_node_info* topology = 0;
get_cpu_topology_info(0, &topologyNodeCount);
if (topologyNodeCount != 0)
topology = new cpu_topology_node_info[topologyNodeCount];
get_cpu_topology_info(topology, &topologyNodeCount);
for (uint32 i = 0; i < topologyNodeCount; i++) {
if (topology[i].type == B_TOPOLOGY_CORE) {
this->CPUSpeedInMHz = topology[i].data.core.default_frequency /
1000000.0f;
break;
}
}
delete[] topology;
// Physical Memory
this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ;
......@@ -4991,7 +5029,12 @@ bool SystemInformationImplementation::QueryHPUXProcessor()
case CPU_PA_RISC2_0:
this->ChipID.Vendor = "Hewlett-Packard";
this->ChipID.Family = 0x200;
# ifdef CPU_HP_INTEL_EM_1_0
case CPU_HP_INTEL_EM_1_0:
# endif
# ifdef CPU_IA64_ARCHREV_0
case CPU_IA64_ARCHREV_0:
# endif
this->ChipID.Vendor = "GenuineIntel";
this->Features.HasIA64 = true;
break;
......
......@@ -188,6 +188,9 @@ static inline char *realpath(const char *path, char *resolved_path)
#endif
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__))
#include <wctype.h>
inline int Mkdir(const char* dir)
{
return _wmkdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
......@@ -2115,10 +2118,10 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
SystemTools::RemoveFile(destination);
#if defined(_WIN32) || defined(__CYGWIN__)
kwsys_ios::ofstream fout(destination,
kwsys::ofstream fout(destination,
kwsys_ios::ios::binary | kwsys_ios::ios::out | kwsys_ios::ios::trunc);
#else
kwsys_ios::ofstream fout(destination,
kwsys::ofstream fout(destination,
kwsys_ios::ios::out | kwsys_ios::ios::trunc);
#endif
if(!fout)
......@@ -4915,8 +4918,8 @@ void SystemTools::ClassInitialize()
// Strip off one directory level and see if the logical
// mapping still works.
pwd_str = SystemTools::GetFilenamePath(pwd_str.c_str());
cwd_str = SystemTools::GetFilenamePath(cwd_str.c_str());
pwd_str = SystemTools::GetFilenamePath(pwd_str);
cwd_str = SystemTools::GetFilenamePath(cwd_str);
Realpath(pwd_str.c_str(), pwd_path);
}
......
......@@ -155,6 +155,7 @@ static const char* kwsysTerminalVT100Names[] =
"mach-color",
"mlterm",
"putty",
"putty-256color",
"rxvt",
"rxvt-256color",
"rxvt-cygwin",
......
......@@ -16,14 +16,18 @@
#endif
#include KWSYS_HEADER(Encoding.hxx)
#include KWSYS_HEADER(Encoding.h)
#include KWSYS_HEADER(ios/iostream)
#include <locale.h>
#include <string.h>
#include <stdlib.h>
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "Encoding.hxx.in"
# include "Encoding.h.in"
# include "kwsys_ios_iostream.h.in"
#endif
......@@ -68,11 +72,16 @@ static int testHelloWorldEncoding()
std::cout << str << std::endl;
std::wstring wstr = kwsys::Encoding::ToWide(str);
std::string str2 = kwsys::Encoding::ToNarrow(wstr);
if(!wstr.empty() && str != str2)
wchar_t* c_wstr = kwsysEncoding_DupToWide(str.c_str());
char* c_str2 = kwsysEncoding_DupToNarrow(c_wstr);
if(!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str())))
{
std::cout << "converted string was different: " << str2 << std::endl;
std::cout << "converted string was different: " << c_str2 << std::endl;
ret++;
}
free(c_wstr);
free(c_str2);
}
return ret;
}
......@@ -136,6 +145,36 @@ static int testRobustEncoding()
return ret;
}
static int testCommandLineArguments()
{
int status = 0;
char const* argv[2] = {
"./app.exe",
(char const*)helloWorldStrings[1]
};
kwsys::Encoding::CommandLineArguments args(2, argv);
kwsys::Encoding::CommandLineArguments arg2 =
kwsys::Encoding::CommandLineArguments(args);
char const* const* u8_argv = args.argv();
for(int i=0; i<args.argc(); i++)
{
char const* u8_arg = u8_argv[i];
if(strcmp(argv[i], u8_arg) != 0)
{
std::cout << "argv[" << i << "] " << argv[i] << " != "
<< u8_arg << std::endl;
status++;
}
}
kwsys::Encoding::CommandLineArguments args3 =
kwsys::Encoding::CommandLineArguments::Main(2, argv);
return status;
}
//----------------------------------------------------------------------------
int testEncoding(int, char*[])
......@@ -154,6 +193,7 @@ int testEncoding(int, char*[])
ret |= testHelloWorldEncoding();
ret |= testRobustEncoding();
ret |= testCommandLineArguments();
return ret;
}
/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "kwsysPrivate.h"
#if defined(_MSC_VER)
# pragma warning (disable:4786)
#endif