Skip to content

Commit

Permalink
latest from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Feb 2, 2022
1 parent 091a463 commit 2da0bfc
Show file tree
Hide file tree
Showing 105 changed files with 5,912 additions and 12,391 deletions.
23 changes: 23 additions & 0 deletions externals/coda-oss/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```
_________________________
| ____ _||_ ___ __ |
| /___ \/_||_\| __\/ \ |
| // \// || \|| \\ _ \ |
| || [===||===] ||(_)| |
| || _|| || ||| ||__ | |
| \\ _/ |\_||_/||__/|| || |
| \___/ \_||_/|___/|| || |
|__________||_____________|
```
# coda-oss Release Notes

## (WIP: Release 2022-??-??)
* new `EnocdedString` and `EncodedStringView` to manage strings in different encodings
* XML containing UTF-8 characters can now be validated
* Update to [GSL 4.0.0](https://github.com/microsoft/GSL/releases/tag/v4.0.0)
* our implementation of `std` stuff is all in the `coda_oss` namespace
* old, unused **log4j.jar** deleted to remove any questions about the security vulnerability

## [Release 2021-12-13](https://github.com/mdaus/coda-oss/releases/tag/2021-12-13)
* Try hard to parse XML encoded in various ways
* Simplify XML element creation for common idioms
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace coda_oss
native = __BYTE_ORDER__
#endif
};
#define CODA_OSS_coda_oss_endian 201907L // __cpp_lib_endian
}

#endif // CODA_OSS_coda_oss_bit_h_INCLUDED_
15 changes: 10 additions & 5 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@

#include <cstddef>

#include "coda_oss/namespace_.h"
// Need a fairly decent C++ compiler to use the real GSL. This brings in more than
// we really need for span (e.g., gsl::narrow()), but it keeps things simple.
#include "gsl/gsl.h" // not gsl/byte; need #pragma here to turn off warnings

namespace coda_oss
{
// https://en.cppreference.com/w/cpp/types/byte
enum class byte : unsigned char {};

#define CODA_OSS_coda_oss_byte 201603L // __cpp_lib_byte
#if defined(GSL_BYTE_H) // the above #include'd gsl/byte
using byte = gsl::byte;
#else // no gsl::byte, use our own
// https://en.cppreference.com/w/cpp/types/byte
enum class byte : unsigned char {};
#endif // GSL_BYTE_H
}

#endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ std::unique_ptr<T> make_unique(size_t size)
template <typename T, typename... TArgs, typename std::enable_if<std::extent<T>::value != 0, int>::type = 0>
void make_unique(TArgs&&...) = delete;

#define CODA_OSS_coda_oss_make_unique 201304L // c.f., __cpp_lib_make_unique

} // namespace coda_oss

#endif // CODA_OSS_coda_oss_memory_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ namespace coda_oss
#endif // GSL_SPAN_H
}

#define CODA_OSS_coda_oss_span 202002L // c.f., __cpp_lib_span

#endif // CODA_OSS_coda_oss_span_h_INCLUDED_
77 changes: 2 additions & 75 deletions externals/coda-oss/modules/c++/gsl/include/gsl/Gsl_.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,11 @@
#define CODA_OSS_gsl_Gsl__h_INCLUDED_
#pragma once

#include <assert.h>

#include <exception>
#include <type_traits>
#include <utility>

#include <config/compiler_extensions.h>
#include "gsl/use_gsl.h" // Can't compile all of GSL with older versions of GCC/MSVC

#if defined(__INTEL_COMPILER) // ICC, high-side
// Don't have access to Intel compiler on the low-side so just turn this off
// completely ... far too much hassle trying to get push/pop/etc. right
#pragma warning(disable: 3377) // "constexpr function return is non-constant"
#endif

namespace Gsl
{
// narrow_cast(): a searchable way to do narrowing casts of values
template <class T, class U> constexpr T narrow_cast(U&& u) noexcept
{
return static_cast<T>(std::forward<U>(u));
}

struct narrowing_error final : public std::exception { };

namespace details
{
template <typename Exception>
[[noreturn]] void throw_exception(Exception&& e)
{
throw e;
}

template <class T, class U>
struct is_same_signedness final
: public std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value> { };

// this is messy to preserve "constexpr" with C++11
CODA_OSS_disable_warning_push
#if _MSC_VER
#pragma warning(disable : 4702) // unreachable code
#endif
template <class T>
constexpr T narrow_throw_exception(T t) noexcept(false)
{
return throw_exception(narrowing_error()), t;
}
CODA_OSS_disable_warning_pop
template <class T, class U>
constexpr T narrow1_(T t, U u) noexcept(false)
{
return (static_cast<U>(t) != u) ? narrow_throw_exception(t) : t;
}

CODA_OSS_disable_warning_push
CODA_OSS_UNREFERENCED_FORMAL_PARAMETER
template <class T, class U>
constexpr T narrow2_(T t, U u) noexcept(false)
{
return (!is_same_signedness<T, U>::value && ((t < T{}) != (u < U{}))) ?
narrow_throw_exception(t) : t;
}
CODA_OSS_disable_warning_pop

template <class T, class U>
constexpr T narrow(T t, U u) noexcept(false)
{
return narrow1_(t, u) ? narrow2_(t, u) : t;
}
} // namespace details
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
template <class T, class U>
constexpr T narrow(U u) noexcept(false)
{
return details::narrow(narrow_cast<T>(u), u);
}
}
#include "gsl/Gsl_narrow.h"

#include "gsl/use_gsl.h" // Can't compile all of GSL with older versions of GCC/MSVC
#if !CODA_OSS_gsl_use_real_gsl_
// Add to "gsl" if we're not using the real thing
namespace gsl
Expand Down
105 changes: 105 additions & 0 deletions externals/coda-oss/modules/c++/gsl/include/gsl/Gsl_narrow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* =========================================================================
* This file is part of gsl-c++
* =========================================================================
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
* (C) Copyright 2021, Maxar Technologies, Inc.
*
* gsl-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,
* see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CODA_OSS_gsl_Gsl_narrow_h_INCLUDED_
#define CODA_OSS_gsl_Gsl_narrow_h_INCLUDED_
#pragma once

#include <assert.h>

#include <exception>
#include <type_traits>
#include <utility>

#include <config/compiler_extensions.h>
#include "gsl/use_gsl.h" // Can't compile all of GSL with older versions of GCC/MSVC

#if defined(__INTEL_COMPILER) // ICC, high-side
// Don't have access to Intel compiler on the low-side so just turn this off
// completely ... far too much hassle trying to get push/pop/etc. right
#pragma warning(disable: 3377) // "constexpr function return is non-constant"
#endif

namespace Gsl
{
// narrow_cast(): a searchable way to do narrowing casts of values
template <class T, class U> constexpr T narrow_cast(U&& u) noexcept
{
return static_cast<T>(std::forward<U>(u));
}

struct narrowing_error final : public std::exception { };

namespace details
{
template <typename Exception>
[[noreturn]] void throw_exception(Exception&& e)
{
throw e;
}

template <class T, class U>
struct is_same_signedness final
: public std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value> { };

// this is messy to preserve "constexpr" with C++11
CODA_OSS_disable_warning_push
#if _MSC_VER
#pragma warning(disable : 4702) // unreachable code
#endif
template <class T>
constexpr T narrow_throw_exception(T t) noexcept(false)
{
return throw_exception(narrowing_error()), t;
}
CODA_OSS_disable_warning_pop
template <class T, class U>
constexpr T narrow1_(T t, U u) noexcept(false)
{
return (static_cast<U>(t) != u) ? narrow_throw_exception(t) : t;
}

CODA_OSS_disable_warning_push
CODA_OSS_UNREFERENCED_FORMAL_PARAMETER
template <class T, class U>
constexpr T narrow2_(T t, U u) noexcept(false)
{
return (!is_same_signedness<T, U>::value && ((t < T{}) != (u < U{}))) ?
narrow_throw_exception(t) : t;
}
CODA_OSS_disable_warning_pop

template <class T, class U>
constexpr T narrow(T t, U u) noexcept(false)
{
return narrow1_(t, u) ? narrow2_(t, u) : t;
}
} // namespace details
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
template <class T, class U>
constexpr T narrow(U u) noexcept(false)
{
return details::narrow(narrow_cast<T>(u), u);
}
}

#endif // CODA_OSS_gsl_Gsl_narrow_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef GSL_ALGORITHM_H
#define GSL_ALGORITHM_H

#include "gsl_assert" // for Expects
#include "span" // for dynamic_extent, span
#include <gsl/assert> // for Expects
#include <gsl/span> // for dynamic_extent, span

#include <algorithm> // for copy_n
#include <cstddef> // for ptrdiff_t
Expand Down Expand Up @@ -48,7 +48,9 @@ void copy(span<SrcElementType, SrcExtent> src, span<DestElementType, DestExtent>
"Source range is longer than target range");

Expects(dest.size() >= src.size());
// clang-format off
GSL_SUPPRESS(stl.1) // NO-FORMAT: attribute
// clang-format on
std::copy_n(src.data(), src.size(), dest.data());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// Currently terminate is a no-op in this mode, so we add termination behavior back
//
#if defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS))
#define GSL_KERNEL_MODE

#define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND
#include <intrin.h>
Expand All @@ -32,11 +33,13 @@
#pragma clang diagnostic ignored "-Winvalid-noreturn"
#endif // defined(__clang__)

#else // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS))
#else // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) &&
// !_HAS_EXCEPTIONS))

#include <exception>

#endif // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS))
#endif // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) &&
// !_HAS_EXCEPTIONS))

//
// make suppress attributes parse for some compilers
Expand All @@ -45,7 +48,7 @@
#if defined(__clang__)
#define GSL_SUPPRESS(x) [[gsl::suppress("x")]]
#else
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
#else
#define GSL_SUPPRESS(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#if defined(__clang__)
#define GSL_SUPPRESS(x) [[gsl::suppress("x")]]
#else
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
#else
#define GSL_SUPPRESS(x)
Expand All @@ -40,30 +40,34 @@
#pragma warning(push)

// Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool.
#pragma warning(disable : 26493) // don't use c-style casts // TODO: MSVC suppression in templates does not always work
#pragma warning(disable : 26493) // don't use c-style casts // TODO: MSVC suppression in templates
// does not always work

#ifndef GSL_USE_STD_BYTE
// this tests if we are under MSVC and the standard lib has std::byte and it is enabled
#if (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || (defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603)
#if (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || \
(defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603)

#define GSL_USE_STD_BYTE 1

#else // (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || (defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603)
#else // (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || (defined(__cpp_lib_byte) && __cpp_lib_byte >=
// 201603)

#define GSL_USE_STD_BYTE 0

#endif // (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || (defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603)
#endif // (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE) || (defined(__cpp_lib_byte) && __cpp_lib_byte >=
// 201603)
#endif // GSL_USE_STD_BYTE

#else // _MSC_VER

#ifndef GSL_USE_STD_BYTE
#include <cstddef> /* __cpp_lib_byte */
// this tests if we are under GCC or Clang with enough -std:c++1z power to get us std::byte
// also check if libc++ version is sufficient (> 5.0) or libstc++ actually contains std::byte
#if defined(__cplusplus) && (__cplusplus >= 201703L) && \
(defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) || \
defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000))
// this tests if we are under GCC or Clang with enough -std=c++1z power to get us std::byte
// also check if libc++ version is sufficient (> 5.0) or libstdc++ actually contains std::byte
#if defined(__cplusplus) && (__cplusplus >= 201703L) && \
(defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) || \
defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000))

#define GSL_USE_STD_BYTE 1

Expand All @@ -73,7 +77,7 @@

#define GSL_USE_STD_BYTE 0

#endif //defined(__cplusplus) && (__cplusplus >= 201703L) &&
#endif // defined(__cplusplus) && (__cplusplus >= 201703L) &&
// (defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) ||
// defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000))
#endif // GSL_USE_STD_BYTE
Expand Down
Loading

0 comments on commit 2da0bfc

Please sign in to comment.