Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from 9e5cd6e6f..cdda3982c
Browse files Browse the repository at this point in the history
cdda3982c Merge branch 'main' into cpp17
2fd7a0bfa latest from coda-oss (#552)
b660acc8d Merge branch 'main' into cpp17
842bcb3c7 Merge commit 'b4e35176b5f190a9783b8e02d2a6463163cea097' into cpp17
b4e35176b Squashed 'externals/coda-oss/' changes from 8abcb1825d..7b90b5a46b
73d3dbaab latest from coda-oss
0eecce004 invoke() utility to reduce code duplication (#550)
59fb02fe9 latest from coda-oss (#551)
9fbf2b7b8 Fill out adapter free block which is used for nitf decompression (#549)

git-subtree-dir: externals/nitro
git-subtree-split: cdda3982c7ac21827c8369faa8d8f4fc963e7900
  • Loading branch information
Dan Smith authored and Dan Smith committed May 30, 2023
1 parent bd9f16e commit 7998a72
Show file tree
Hide file tree
Showing 29 changed files with 1,295 additions and 585 deletions.
6 changes: 4 additions & 2 deletions externals/coda-oss/UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
Expand All @@ -34,7 +33,6 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -259,6 +257,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\modules\c++\mt\unittests\test_mt_byte_swap.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\modules\c++\mt\unittests\ThreadGroupTest.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
Expand Down
3 changes: 3 additions & 0 deletions externals/coda-oss/UnitTest/UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
<ClCompile Include="..\modules\c++\re\unittests\test_regex.cpp">
<Filter>re</Filter>
</ClCompile>
<ClCompile Include="..\modules\c++\mt\unittests\test_mt_byte_swap.cpp">
<Filter>mt</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand Down
4 changes: 4 additions & 0 deletions externals/coda-oss/UnitTest/mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ TEST_CLASS(work_sharing_balanced_runnable_1d_test){ public:
#include "mt/unittests/work_sharing_balanced_runnable_1d_test.cpp"
};

TEST_CLASS(test_mt_byte_swap){ public:
#include "mt/unittests/test_mt_byte_swap.cpp"
};

}
2 changes: 2 additions & 0 deletions externals/coda-oss/UnitTest/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <sys/Thread.h>
#include <sys/Mutex.h>
#include <sys/FileFinder.h>
#include <sys/ByteSwap.h>
#include <import/sys.h>
#include <import/math/linear.h>
#include <import/math/poly.h>
Expand All @@ -87,6 +88,7 @@
#include <mt/RequestQueue.h>
#include <mt/ThreadPoolException.h>
#include <mt/GenerationThreadPool.h>
#include <mt/ThreadedByteSwap.h>
#include <import/mt.h>
#include <avx/extractf.h>
#include <logging/ExceptionLogger.h>
Expand Down
6 changes: 4 additions & 2 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<ClInclude Include="mt\include\mt\RequestQueue.h" />
<ClInclude Include="mt\include\mt\Runnable1D.h" />
<ClInclude Include="mt\include\mt\Singleton.h" />
<ClInclude Include="mt\include\mt\ThreadedByteSwap.h" />
<ClInclude Include="mt\include\mt\ThreadGroup.h" />
<ClInclude Include="mt\include\mt\ThreadPlanner.h" />
<ClInclude Include="mt\include\mt\ThreadPoolException.h" />
Expand Down Expand Up @@ -191,6 +192,8 @@
<ClInclude Include="sys\include\sys\AtomicCounter.h" />
<ClInclude Include="sys\include\sys\AtomicCounterCpp11.h" />
<ClInclude Include="sys\include\sys\Backtrace.h" />
<ClInclude Include="sys\include\sys\ByteSwap.h" />
<ClInclude Include="sys\include\sys\ByteSwapValue.h" />
<ClInclude Include="sys\include\sys\ConditionVar.h" />
<ClInclude Include="sys\include\sys\ConditionVarInterface.h" />
<ClInclude Include="sys\include\sys\ConditionVarPosix.h" />
Expand Down Expand Up @@ -228,6 +231,7 @@
<ClInclude Include="sys\include\sys\SemaphoreInterface.h" />
<ClInclude Include="sys\include\sys\SemaphorePosix.h" />
<ClInclude Include="sys\include\sys\SemaphoreWin32.h" />
<ClInclude Include="sys\include\sys\Span.h" />
<ClInclude Include="sys\include\sys\StopWatch.h" />
<ClInclude Include="sys\include\sys\String.h" />
<ClInclude Include="sys\include\sys\SystemException.h" />
Expand Down Expand Up @@ -421,14 +425,12 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
12 changes: 12 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,18 @@
<ClInclude Include="config\include\config\disable_compiler_warnings.h">
<Filter>config</Filter>
</ClInclude>
<ClInclude Include="sys\include\sys\ByteSwap.h">
<Filter>sys</Filter>
</ClInclude>
<ClInclude Include="sys\include\sys\ByteSwapValue.h">
<Filter>sys</Filter>
</ClInclude>
<ClInclude Include="mt\include\mt\ThreadedByteSwap.h">
<Filter>mt</Filter>
</ClInclude>
<ClInclude Include="sys\include\sys\Span.h">
<Filter>sys</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@
#endif // CODA_OSS_cplusplus

// Define a few macros as that's less verbose than testing against a version number
// https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
#define CODA_OSS_cpp11 (CODA_OSS_cplusplus >= 201103L)
#define CODA_OSS_cpp14 (CODA_OSS_cplusplus >= 201402L)
#define CODA_OSS_cpp17 (CODA_OSS_cplusplus >= 201703L)
#define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= 202002L)
#define CODA_OSS_cpp23 0
#define CODA_OSS_cpp23 (CODA_OSS_cplusplus >= 202302L)

#if !CODA_OSS_cpp17
#error "Must compile with C++17 or greater."
Expand Down
60 changes: 60 additions & 0 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
#define CODA_OSS_coda_oss_bit_h_INCLUDED_
#pragma once

#include <stdlib.h>
#include <stdint.h>
#ifdef __GNUC__
#include <byteswap.h> // "These functions are GNU extensions."
#endif

#include <type_traits>

#include "coda_oss/namespace_.h"
namespace coda_oss
{
Expand All @@ -38,6 +46,58 @@ namespace coda_oss
native = __BYTE_ORDER__
#endif
};

// https://en.cppreference.com/w/cpp/numeric/byteswap
namespace details
{
// Overloads for common types
inline constexpr uint8_t byteswap(uint8_t val) noexcept
{
return val; // no-op
}
#if defined(_MSC_VER)
// These routines should generate a single instruction; see
// https://devblogs.microsoft.com/cppblog/a-tour-of-4-msvc-backend-improvements/
inline uint16_t byteswap(uint16_t val)
{
return _byteswap_ushort(val);
}
inline uint32_t byteswap(uint32_t val)
{
return _byteswap_ulong(val);
}
inline uint64_t byteswap(uint64_t val)
{
return _byteswap_uint64(val);
}
#elif defined(__GNUC__)
inline uint16_t byteswap(uint16_t val)
{
return bswap_16(val);
}
inline uint32_t byteswap(uint32_t val)
{
return bswap_32(val);
}
inline uint64_t byteswap(uint64_t val)
{
return bswap_64(val);
}
#else
#error "No platform-specific byteswap()" // TODO: do something else?
#endif
}

template <typename T>
inline T byteswap(T n) noexcept
{
// "std::byteswap participates in overload resolution only if T satisfies integral, i.e., T is an integer type. The program is
// ill-formed if T has padding bits."
static_assert(std::is_integral<T>::value, "T must be integral");

using unsigned_t = std::make_unsigned_t<T>; // "Since C++14" https://en.cppreference.com/w/cpp/types/make_unsigned
return details::byteswap(static_cast<unsigned_t>(n));
}
}

#endif // CODA_OSS_coda_oss_bit_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
#define CODA_OSS_coda_oss_cstddef_h_INCLUDED_
#pragma once

#include <stdint.h>

#include <cstddef>
#include <type_traits>

// 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.
Expand All @@ -32,5 +35,6 @@ namespace coda_oss
{
using byte = std::byte;
}
static_assert(!std::is_same<coda_oss::byte, uint8_t>::value, "'coda_oss::byte' should be a unique type.");

#endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_
21 changes: 21 additions & 0 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "coda_oss/namespace_.h"
#include "coda_oss/span_.h"
#include "coda_oss/cstddef.h" // byte

// 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.
Expand All @@ -37,6 +38,26 @@ namespace coda_oss
#else // no gsl::span, use our own
using details::span;
#endif // GSL_SPAN_H

// https://en.cppreference.com/w/cpp/container/span/as_bytes
template <typename T>
span<const byte> as_bytes(span<const T> s) noexcept
{
const void* const p = s.data();
return span<const byte>(static_cast<const byte*>(p), s.size_bytes());
}
template <typename T>
span<const byte> as_bytes(span<T> s) noexcept
{
return as_bytes(span<const T>(s.data(), s.size()));
}
template <typename T>
span<byte> as_writable_bytes(span<T> s) noexcept
{
void* const p = s.data();
return span<byte>(static_cast<byte*>(p), s.size_bytes());
}

}

#endif // CODA_OSS_coda_oss_span_h_INCLUDED_
36 changes: 36 additions & 0 deletions externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>

#include <coda_oss/span.h>
#include <sys/Span.h>

#include "TestCase.h"

Expand Down Expand Up @@ -94,8 +95,43 @@ TEST_CASE(testGslNarrow)
TEST_THROWS(gsl::narrow<int>(d));
}

TEST_CASE(test_sys_make_span)
{
int i = 314;
int* const p = &i;
auto s = sys::make_span(p, 1);
TEST_ASSERT(s.data() == p);
TEST_ASSERT_EQ(s[0], i);
s[0] = 123;
TEST_ASSERT_EQ(i, 123);
s[0] = 314;

const int* const q = &i;
auto cs = sys::make_span(q, 1);
TEST_ASSERT(cs.data() == q);
TEST_ASSERT_EQ(cs[0], i);
//cs[0] = 123; // cs = span<const>
TEST_ASSERT_EQ(i, 314);

std::vector<int> v{314};
s = sys::make_span(v);
TEST_ASSERT(s.data() == v.data());
TEST_ASSERT_EQ(s[0], v[0]);
s[0] = 123;
TEST_ASSERT_EQ(v[0], 123);
s[0] = 314;

const std::vector<int>& u = v;
cs = sys::make_span(u);
TEST_ASSERT(cs.data() == u.data());
TEST_ASSERT_EQ(cs[0], u[0]);
// cs[0] = 123; // cs = span<const>
TEST_ASSERT_EQ(u[0], 314);
}

TEST_MAIN(
TEST_CHECK(testSpanBuffer);
TEST_CHECK(testSpanVector);
TEST_CHECK(testGslNarrow);
TEST_CHECK(test_sys_make_span);
)
Loading

0 comments on commit 7998a72

Please sign in to comment.