Skip to content

Commit

Permalink
Merge branch 'master' into feature/xml.lite_tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 28, 2020
2 parents fbd1061 + 1db3751 commit d505f35
Show file tree
Hide file tree
Showing 55 changed files with 328 additions and 77 deletions.
2 changes: 1 addition & 1 deletion modules/c++/io/source/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
void copyPermissions(const std::string& src,
const std::string& dest)
{
#ifndef WIN32
#if !(defined(WIN32) || defined(_WIN32))
// set up permissions on unix --
// copy the source's permissions
struct stat statBuf;
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/mt/include/mt/CPUAffinityInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <mt/AbstractCPUAffinityInitializer.h>

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)
#include <mt/CPUAffinityInitializerWin32.h>
namespace mt
{
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/mt/include/mt/CPUAffinityInitializerWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef __MT_CPU_AFFINITY_INITIALIZER_WIN32_H__
#define __MT_CPU_AFFINITY_INITIALIZER_WIN32_H__

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)

#include <mt/AbstractCPUAffinityInitializer.h>
#include <mt/CPUAffinityThreadInitializerWin32.h>
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/mt/include/mt/CPUAffinityThreadInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <mt/AbstractCPUAffinityThreadInitializer.h>

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)
#include <mt/CPUAffinityThreadInitializerWin32.h>
namespace mt
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef __MT_CPU_AFFINITY_THREAD_INITIALIZER_WIN32_H__
#define __MT_CPU_AFFINITY_THREAD_INITIALIZER_WIN32_H__

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)

#include <mt/AbstractCPUAffinityThreadInitializer.h>

Expand Down
2 changes: 1 addition & 1 deletion modules/c++/net/include/net/Daemon.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __NET_DAEMON_H__
#define __NET_DAEMON_H__

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)
# include "net/DaemonWin32.h"
namespace net
{
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/net/include/net/DaemonUnix.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __NET_DAEMON_UNIX_H__
#define __NET_DAEMON_UNIX_H__

#if !defined(WIN32)
#if !(defined(WIN32) || defined(_WIN32))

#include "net/DaemonInterface.h"
#include <import/sys.h>
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/net/include/net/DaemonWin32.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __NET_DAEMON_WIN32_H__
#define __NET_DAEMON_WIN32_H__

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)

#include "net/DaemonInterface.h"
#include <import/except.h>
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/net/source/DaemonUnix.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !defined(WIN32)
#if !(defined(WIN32) || defined(_WIN32))
#include "net/DaemonUnix.h"

#include <iostream>
Expand Down
4 changes: 2 additions & 2 deletions modules/c++/plugin/include/plugin/PluginDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/* #define PLUGIN_DESTRUCTOR_NAME "DestroyPlugin" */
#define GET_PLUGIN_IDENT "GetPluginIdentity"

#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
# define PLUGIN_DSO_EXTENSION ".dll"
#else
# define PLUGIN_DSO_EXTENSION ".so"
Expand All @@ -47,7 +47,7 @@
#define PLUGIN_API_MINOR_VERSION 0


#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
# if defined(PLUGIN_MODULE_EXPORTS)
# define PLUGIN_HOOK extern "C" __declspec(dllexport)
# else
Expand Down
1 change: 1 addition & 0 deletions modules/c++/sys/include/import/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
//#include "sys/Process.h"
#include "sys/String.h"
#include "sys/Filesystem.h"
#include "sys/Bit.h"

/*!
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/sys/include/sys/AtomicCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
#include <sys/AtomicCounterX86.h>
#elif defined(WIN32)
#elif (defined(WIN32) || defined(_WIN32))
#include <sys/AtomicCounterWin32.h>
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
// atomic.h is available in Solaris 10+
Expand Down
69 changes: 69 additions & 0 deletions modules/c++/sys/include/sys/Bit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* =========================================================================
* This file is part of sys-c++
* =========================================================================
*
* (C) Copyright 2020, Maxar Technologies, Inc.
*
* sys-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not, http://www.gnu.org/licenses/.
*
*/
#ifndef CODA_OSS_sys_Bit_h_INCLUDED_
#define CODA_OSS_sys_Bit_h_INCLUDED_
#pragma once

#include "Conf.h"

namespace sys
{
// https://en.cppreference.com/w/cpp/types/endian
enum class Endian
{
#ifdef _WIN32
little = 0,
big = 1,
native = little
#else
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__,
native = __BYTE_ORDER__
#endif
};
}



#ifndef CODA_OSS_DEFINE_std_endian_
#if CODA_OSS_cpp20
#define CODA_OSS_DEFINE_std_endian_ 0 // std::endian part of C++20
#else
#define CODA_OSS_DEFINE_std_endian_ CODA_OSS_AUGMENT_std_namespace // pre C++20
#endif // CODA_OSS_cpp20
#endif // CODA_OSS_DEFINE_std_endian_

#if CODA_OSS_DEFINE_std_endian_
// This is ever-so-slightly uncouth: we're not supposed to augment "std".
namespace std
{
using endian = sys::Endian;
}
#else

// Not doing our own std::endian, can we get the real one?
#if CODA_OSS_cpp17 && __has_include(<bit>) // __has_include is C++17
#include <bit>
#endif // CODA_OSS_cpp20

#endif // CODA_OSS_DEFINE_std_endian_

#endif // CODA_OSS_sys_Bit_h_INCLUDED_
2 changes: 1 addition & 1 deletion modules/c++/sys/include/sys/ConditionVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace sys
{
typedef ConditionVarNSPR ConditionVar;
}
# elif defined(WIN32)
# elif (defined(WIN32) || defined(_WIN32))
# include "sys/ConditionVarWin32.h"
namespace sys
{
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/sys/include/sys/ConditionVarWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef __SYS_WIN32_CONDITION_VARIABLE_H__
#define __SYS_WIN32_CONDITION_VARIABLE_H__

#if defined(WIN32)
#if defined(WIN32) || defined(_WIN32)
#if !defined(USE_NSPR_THREADS)

#include "sys/ConditionVarInterface.h"
Expand Down
62 changes: 54 additions & 8 deletions modules/c++/sys/include/sys/Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#ifndef __SYS_CONF_H__
#define __SYS_CONF_H__
#pragma once

#include <config/coda_oss_config.h>
#include <str/Convert.h>
Expand Down Expand Up @@ -56,7 +57,7 @@
#if defined(__GNUC__)
/* We get a really nice function macro */
# define NativeLayer_func__ __PRETTY_FUNCTION__
#elif defined(WIN32) && (_MSC_VER >= 1300)
#elif (defined(WIN32) || defined(_WIN32)) && (_MSC_VER >= 1300)
# define NativeLayer_func__ __FUNCSIG__
/* Otherwise, lets look for C99 compatibility */
#elif defined (__STDC_VERSION__)
Expand Down Expand Up @@ -187,7 +188,7 @@ namespace sys
* NOTE: This should be updated as architectures require greater
* intervals. Alignments require base 2 increments.
*/
static const size_t SSE_INSTRUCTION_ALIGNMENT = 32;
static constexpr size_t SSE_INSTRUCTION_ALIGNMENT = 32;

/*!
* Returns true if the system is big-endian, otherwise false.
Expand All @@ -214,7 +215,7 @@ namespace sys
if (!bufferPtr || elemSize < 2 || !numElems)
return;

unsigned short half = elemSize >> 1;
const auto half = elemSize >> 1;
size_t offset = 0, innerOff = 0, innerSwap = 0;

for(size_t i = 0; i < numElems; ++i, offset += elemSize)
Expand Down Expand Up @@ -252,7 +253,7 @@ namespace sys
return;
}

const unsigned short half = elemSize >> 1;
const auto half = elemSize >> 1;
size_t offset = 0;

for (size_t ii = 0; ii < numElems; ++ii, offset += elemSize)
Expand Down Expand Up @@ -319,13 +320,13 @@ namespace sys
inline void* alignedAlloc(size_t size,
size_t alignment = SSE_INSTRUCTION_ALIGNMENT)
{
#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
void* p = _aligned_malloc(size, alignment);
#elif defined(HAVE_POSIX_MEMALIGN)
void* p = NULL;
void* p = nullptr;
if (posix_memalign(&p, alignment, size) != 0)
{
p = NULL;
p = nullptr;
}
#elif defined(HAVE_MEMALIGN)
void* const p = memalign(alignment, size);
Expand All @@ -348,7 +349,7 @@ namespace sys
*/
inline void alignedFree(void* p)
{
#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
_aligned_free(p);
#else
free(p);
Expand All @@ -358,4 +359,49 @@ namespace sys

}

#define CODA_OSS_cplusplus __cplusplus
#if CODA_OSS_cplusplus < 201103L // We need at least C++11
#undef CODA_OSS_cplusplus // oops...try to fix

// MSVC only sets __cplusplus >199711L with the /Zc:__cplusplus command-line option.
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG)
// https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160
// "Defined as an integer literal that specifies the C++ language standard targeted by the compiler."
#define CODA_OSS_cplusplus _MSVC_LANG
#endif // _MSVC_LANG

#if defined(__GNUC__)
// ... similar things needed for other compilers ... ?
#endif // __GNUC__

#endif // CODA_OSS_cplusplus
static_assert(CODA_OSS_cplusplus >= 201103L, "Must compile with C++11 or greater.");

// Define a few macros as that's less verbose than testing against a version number
#if CODA_OSS_cplusplus >= 201103L
#define CODA_OSS_cpp11 1
#endif
#if CODA_OSS_cplusplus >= 201402L
#define CODA_OSS_cpp14 1
#endif
#if CODA_OSS_cplusplus >= 201703L
#define CODA_OSS_cpp17 1
#endif
#if CODA_OSS_cplusplus >= 202002L
#define CODA_OSS_cpp20 1
#endif

// We've got various "replacements" (to a degree) for C++ library functionality
// only available in later releases. Adding these names to "std" is technically
// forbidden, but it makes for fewer (eventual) changes in client code.
#define CODA_OSS_AUGMENT_std_namespace 0
#ifndef CODA_OSS_AUGMENT_std_namespace
#if CODA_OSS_cplusplus == 201103L
#define CODA_OSS_AUGMENT_std_namespace 0 // assume we've already got everything for C++11
#else
#define CODA_OSS_AUGMENT_std_namespace 1
#endif
#endif

#endif // __SYS_CONF_H__
2 changes: 1 addition & 1 deletion modules/c++/sys/include/sys/DLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
*/

# if defined(WIN32)
# if defined(WIN32) || defined(_WIN32)
# include "sys/Conf.h"
# define DLL_PUBLIC_FUNCTION extern "C" __declspec (dllexport)
typedef HINSTANCE DYNAMIC_LIBRARY;
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/sys/include/sys/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "sys/SystemException.h"
#include "sys/Path.h"

#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
# define _SYS_SEEK_CUR FILE_CURRENT
# define _SYS_SEEK_SET FILE_BEGIN
# define _SYS_SEEK_END FILE_END
Expand Down
Loading

0 comments on commit d505f35

Please sign in to comment.