Skip to content

Commit

Permalink
Replace use of WIN32 CPP macro with _MSC_VER (#1124)
Browse files Browse the repository at this point in the history
+ This generally more standardized.  Also, `WIN32` might be defined for non-MSVC environments on
  Windows platforms.
+ `WIN32` is the correct variable to check within CMake files.
+ Fix copyright blocks based on pre-commit-hook.
  • Loading branch information
KineticTheory authored Sep 1, 2021
1 parent 39f9f38 commit 347d3d1
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/c4/C4_MPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Thomas M. Evans
* \date Thu Mar 21 16:56:17 2002
* \brief C4 MPI implementation.
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "c4/config.h"
Expand Down Expand Up @@ -118,7 +118,7 @@ double wall_clock_time() { return MPI_Wtime(); }
// overloaded function (provide POSIX timer information).
double wall_clock_time(DRACO_TIME_TYPE &now) {
// obtain POSIX timer information and return it to the user via the reference value argument "now".
#ifdef WIN32
#ifdef _MSC_VER
now = std::chrono::high_resolution_clock::now();
#else
times(&now);
Expand Down
4 changes: 2 additions & 2 deletions src/c4/C4_Serial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Thomas M. Evans
* \date Mon Mar 25 17:06:25 2002
* \brief Implementation of C4 serial option.
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "C4_Functions.hh"
Expand Down Expand Up @@ -66,7 +66,7 @@ void global_barrier() { /* empty */
// TIMING FUNCTIONS
//------------------------------------------------------------------------------------------------//

#if defined(WIN32)
#if defined(_MSC_VER)
double wall_clock_time(DRACO_TIME_TYPE &now) {
using namespace std::chrono;
now = high_resolution_clock::now();
Expand Down
6 changes: 3 additions & 3 deletions src/c4/C4_sys_times.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
* \author Kelly Thompson
* \date Mon Sep 20 21:54:18 2010
* \brief Encapsulate system headers for timing information.
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#ifndef c4_C4_sys_times_h
#define c4_C4_sys_times_h

#include "ds++/config.h"

#if defined(WIN32) || defined(MINGW)
#if defined(_MSC_VER) || defined(MINGW)
#include <chrono>
#include <ctime>
#else
#include <sys/times.h>
#include <unistd.h>
#endif

#if defined(WIN32)
#if defined(_MSC_VER)
// Consider using GetProcessTimes instead of this as a higher resolution timer.
#define DRACO_TIME_TYPE std::chrono::high_resolution_clock::time_point
#define DRACO_CLOCKS_PER_SEC CLOCKS_PER_SEC
Expand Down
4 changes: 2 additions & 2 deletions src/c4/Timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \file c4/Timer.cc
* \author Thomas M. Evans
* \date Mon Mar 25 17:56:11 2002
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "Timer.hh"
Expand Down Expand Up @@ -41,7 +41,7 @@ Timer::Timer()
: tms_begin(DRACO_TIME_TYPE()), tms_end(DRACO_TIME_TYPE()),
posix_clock_ticks_per_second(static_cast<int>(DRACO_CLOCKS_PER_SEC)),
isMPIWtimeAvailable(setIsMPIWtimeAvailable()) {
#if defined(WIN32)
#if defined(_MSC_VER)
static_assert(DRACO_CLOCKS_PER_SEC < INT32_MAX, "!(DRACO_CLOCKS_PER_SEC < INT32_MAX)");
#else
Check(DRACO_CLOCKS_PER_SEC < INT32_MAX);
Expand Down
6 changes: 3 additions & 3 deletions src/c4/Timer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Thomas M. Evans
* \date Mon Mar 25 17:35:07 2002
* \brief Define class Timer, a POSIX standard timer.
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#ifndef rtt_c4_Timer_hh
Expand Down Expand Up @@ -322,7 +322,7 @@ double Timer::wall_clock() const {
//! Return the system cpu time in seconds, for the last interval.
double Timer::system_cpu() const {
Require(!timer_on);
#if defined(WIN32)
#if defined(_MSC_VER)
return 0.0; // difftime( tms_end, tms_begin );
#else
return static_cast<double>(tms_end.tms_stime - tms_begin.tms_stime) /
Expand All @@ -334,7 +334,7 @@ double Timer::system_cpu() const {
//! Return the user cpu time in seconds, for the last interval.
double Timer::user_cpu() const {
Require(!timer_on);
#if defined(WIN32)
#if defined(_MSC_VER)
using namespace std::chrono;
duration<double> diff = tms_end - tms_begin;
return duration_cast<nanoseconds>(diff).count() / 1.0e9;
Expand Down
8 changes: 3 additions & 5 deletions src/c4/test/tstTime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* \author Thomas M. Evans
* \date Mon Mar 25 17:19:16 2002
* \brief Test timing functions in C4.
* \note Copyright (C) 2016-2020 Triad National Security, LLC.
* All rights reserved. */
* \note Copyright (C) 2010-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "c4/Global_Timer.hh"
Expand Down Expand Up @@ -63,7 +62,7 @@ void wall_clock_test(rtt_dsxx::UnitTest &ut) {

Timer t;

#ifdef WIN32
#ifdef _MSC_VER
// KT: I'm not sure why I'm having so much trouble on Win32 for the timing
// precision check. I may need to use a different mechanism for timing
// values. Right now the ngihtly tests fail about 1 out of 20 times.
Expand Down Expand Up @@ -271,8 +270,7 @@ void test_pause(rtt_dsxx::UnitTest &ut) {

double end(rtt_c4::wall_clock_time());

if (end - begin < pauseTime)
ITFAILS;
FAIL_IF(end - begin < pauseTime);

std::cout << "Starting tstTime::test_pause tests...done\n" << std::endl;

Expand Down
6 changes: 3 additions & 3 deletions src/c4/xthi_cpuset.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Mike Berry <[email protected]>, Kelly Thompson <[email protected]>
* \date Wednesday, Aug 09, 2017, 11:45 am
* \brief Helper functions to generate string for core affinity.
* \note Copyright (C) 2017-2020 Triad National Security, LLC., All rights reserved.
* \note Copyright (C) 2019-2021 Triad National Security, LLC., All rights reserved.
*
* These functions are needed by c4's xthi and ythi programs to report human readable thread
* bindings. It is also used by the unit test for libquo.
Expand All @@ -20,7 +20,7 @@
#include <bitset>
#include <sstream>

#ifdef WIN32
#ifdef _MSC_VER
#include <processthreadsapi.h> // requries SystemCall.hh to be loaded first.
#endif

Expand Down Expand Up @@ -102,7 +102,7 @@ inline int sched_getaffinity(pid_t /*pid*/, size_t /*cpu_size*/, cpu_set_t *cpu_

#endif

#ifdef WIN32
#ifdef _MSC_VER

//! \param[in] num_cpu Number of CPU's per node.
inline std::string cpuset_to_string(unsigned const num_cpu) {
Expand Down
4 changes: 2 additions & 2 deletions src/ds++/DracoMath.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Kent G. Budge
* \date Wed Jan 22 15:18:23 MST 2003
* \brief New or overloaded cmath or cmath-like functions.
* \note Copyright (C) 2016-2021 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2013-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#ifndef rtt_dsxx_DracoMath_hh
Expand All @@ -27,7 +27,7 @@ namespace rtt_dsxx {
// namespace. The problem here is that PGI/13.7 does not have these language features. However,
// PGI does provide the C99 _macros_ of the same name (w/o namespace qualifier).
//------------------------------------------------------------------------------------------------//
#if defined _WIN32 || defined __CYGWIN__
#if defined _MSC_VER || defined __CYGWIN__

template <typename T> bool isNan(T a) { return _isnan(a); }
template <typename T> bool isInf(T a) { return !_finite(a); }
Expand Down
6 changes: 3 additions & 3 deletions src/ds++/DracoStrings.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//--------------------------------------------*-C++-*---------------------------------------------//
/*!
* \file ds++/DracoStrings.cc
* \author Kelly G. Thompson <[email protected]
* \author Kelly G. Thompson <[email protected]>
* \date Wednesday, Aug 23, 2017, 12:48 pm
* \brief Encapsulates common string manipulations (implementation).
* \note Copyright (C) 2017-2020 Triad National Security, LLC. All rights reserved. */
* \note Copyright (C) 2017-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "DracoStrings.hh"
Expand Down Expand Up @@ -53,7 +53,7 @@ template <> auto parse_number_impl<uint64_t>(std::string const &str) -> uint64_t
}

// See notes in DracoStrings.hh about this CPP block
#if defined(WIN32) || defined(APPLE)
#if defined(_MSC_VER) || defined(APPLE)

template <> auto parse_number_impl<long>(std::string const &str) -> long {
return std::stol(str); // use stoull or stul?
Expand Down
10 changes: 4 additions & 6 deletions src/ds++/DracoStrings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* \author Kelly G. Thompson <[email protected]
* \date Wednesday, Aug 23, 2017, 12:48 pm
* \brief Encapsulates common string manipulations.
* \note Copyright (C) 2017-2020 Triad National Security, LLC.
* All rights reserved. */
* \note Copyright (C) 2017-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#ifndef rtt_dsxx_DracoStrings_hh
Expand Down Expand Up @@ -114,7 +113,7 @@ template <> auto parse_number_impl<uint64_t>(std::string const &str) -> uint64_t
// If we are using Visual Studio, we need these definitions. I expect that they will be needed for
// 32-bit Linux as well, but I can't test that. Might need to add "|| (defined(__GNUC__) &&
// __WORDSIZE != 64)"
#if defined(WIN32) || defined(APPLE)
#if defined(_MSC_VER) || defined(APPLE)

template <> auto parse_number_impl<long>(std::string const &str) -> long;
template <> auto parse_number_impl<unsigned long>(std::string const &str) -> unsigned long;
Expand All @@ -126,8 +125,7 @@ template <> auto parse_number_impl<double>(std::string const &str) -> double;

//------------------------------------------------------------------------------------------------//
/*!
* \brief Convert a string into a floating-point type or an integral type with
* error checking.
* \brief Convert a string into a floating-point type or an integral type with error checking.
*
* \param[in] str The string that contains a number.
* \param[in] verbose Should the function print conversion message warnings (default: true).
Expand All @@ -140,7 +138,7 @@ template <> auto parse_number_impl<double>(std::string const &str) -> double;
* appropriate.
*
* Consider catching thrown conversion errors using code similar to this:
*
* \code
try {
parse_number<T>(str);
Expand Down
6 changes: 3 additions & 3 deletions src/ds++/StackTrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \author Kelly Thompson
* \date Friday, Dec 20, 2013, 10:15 am
* \brief Linux/X86 implementation of stack trace functions.
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
* \note Copyright (C) 2014-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "StackTrace.hh"
Expand Down Expand Up @@ -156,7 +156,7 @@ std::string rtt_dsxx::print_stacktrace(std::string const &error_message) {
//------------------------------------------------------------------------------------------------//
// Stack trace feature is also available on Win32-based systems when compiled with Visual Studio.
// ------------------------------------------------------------------------------------------------//
#ifdef WIN32
#ifdef _MSC_VER

//------------------------------------------------------------------------------------------------//
// Print a demangled stack backtrace of the caller function.
Expand Down Expand Up @@ -184,7 +184,7 @@ std::string rtt_dsxx::print_stacktrace(std::string const &error_message) {
return msg.str();
}

#endif // WIN32
#endif // _MSC_VER

//------------------------------------------------------------------------------------------------//
// end of ds++/StackTrace.cc
Expand Down
24 changes: 12 additions & 12 deletions src/ds++/SystemCall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \file ds++/SystemCall.cc
* \brief Implementation for the Draco wrapper for system calls. This routine attempts to hide
* differences between Unix/Windows system calls.
* \note Copyright (C) 2016-2020 Triad National Security, LLC. All rights reserved. */
* \note Copyright (C) 2012-2021 Triad National Security, LLC., All rights reserved. */
//------------------------------------------------------------------------------------------------//

#include "SystemCall.hh"
Expand All @@ -17,7 +17,7 @@
#include <sys/param.h> // MAXPATHLEN
#include <unistd.h> // gethostname
#endif
#ifdef WIN32
#ifdef _MSC_VER
#include <direct.h> // _getcwd
#include <process.h> // _getpid
#include <sstream>
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace rtt_dsxx {
*/
std::string draco_gethostname() {
// Windows: gethostname from <winsock2.h>
#ifdef WIN32
#ifdef _MSC_VER
std::array<char, HOST_NAME_MAX> hostname;
hostname.fill('x');
int err = gethostname(&hostname[0], sizeof(hostname));
Expand Down Expand Up @@ -83,7 +83,7 @@ std::string draco_gethostname() {
* Catamount systems do not have getpid(). This function will return -1.
*/
int draco_getpid() {
#ifdef WIN32
#ifdef _MSC_VER
int i = _getpid();
return i;
#else
Expand All @@ -104,7 +104,7 @@ int draco_getpid() {
*/
std::string draco_getcwd() {
// Identify the current working directory.
#ifdef WIN32
#ifdef _MSC_VER
char *buffer;
Insist((buffer = _getcwd(nullptr, 0)) != nullptr,
std::string("getcwd failed: " + std::string(strerror(errno))));
Expand Down Expand Up @@ -133,7 +133,7 @@ std::string draco_getcwd() {
* Linux
* http://en.wikipedia.org/wiki/Stat_%28system_call%29
*/
#ifdef WIN32
#ifdef _MSC_VER
draco_getstat::draco_getstat(std::string const &fqName)
: stat_return_code(0), buf(), FileInformation({0}) {
filefound = true;
Expand Down Expand Up @@ -179,7 +179,7 @@ draco_getstat::draco_getstat(std::string const &fqName) : stat_return_code(0), b
//------------------------------------------------------------------------------------------------//
//! Is this a regular file?
bool draco_getstat::isreg() {
#ifdef WIN32
#ifdef _MSC_VER
bool b = FileInformation.dwFileAttributes & FILE_ATTRIBUTE_NORMAL;
return filefound && b;
#else
Expand All @@ -191,7 +191,7 @@ bool draco_getstat::isreg() {
//------------------------------------------------------------------------------------------------//
//! Is this a directory?
bool draco_getstat::isdir() {
#ifdef WIN32
#ifdef _MSC_VER
bool b = FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
return filefound && b;
#else
Expand All @@ -202,7 +202,7 @@ bool draco_getstat::isdir() {

//------------------------------------------------------------------------------------------------//
//! Is a Unix permission bit set?
#ifdef WIN32
#ifdef _MSC_VER
bool draco_getstat::has_permission_bit(int /*mask*/) {
Insist(isreg(), "Can only check permission bit for regular files.");
Insist(false, "draco_getstat::hsa_permission_bit() not implemented for WIN32");
Expand All @@ -221,7 +221,7 @@ bool draco_getstat::has_permission_bit(int mask) {
std::string draco_getrealpath(std::string const &path) {
std::array<char, MAXPATHLEN> buffer; // _MAX_PATH
buffer.fill('a');
#ifdef WIN32
#ifdef _MSC_VER
// http://msdn.microsoft.com/en-us/library/506720ff%28v=vs.100%29.aspx
Insist(_fullpath(&buffer[0], path.c_str(), MAXPATHLEN) != nullptr, "Invalid path.");
std::string retVal(buffer.data());
Expand All @@ -243,7 +243,7 @@ std::string draco_getrealpath(std::string const &path) {
* \todo Do we need a permissions argument?
*/
void draco_mkdir(std::string const &path) {
#ifdef WIN32
#ifdef _MSC_VER
draco_getstat dirInfo(path);
if (!dirInfo.isdir()) {
/*! \note If path contains the location of a directory, it cannot contain a trailing
Expand Down Expand Up @@ -297,7 +297,7 @@ void draco_mkdir(std::string const &path) {
*/
void draco_remove(std::string const &dirpath) {
// remove() works for all unix items but only for files (not directories) for windows.
#ifdef WIN32
#ifdef _MSC_VER
if (draco_getstat(dirpath).isdir()) {
// Clear any special directory attributes.
bool ok = ::SetFileAttributes(dirpath.c_str(), FILE_ATTRIBUTE_NORMAL);
Expand Down
Loading

0 comments on commit 347d3d1

Please sign in to comment.