all: minor updates

This commit is contained in:
Markus F.X.J. Oberhumer
2024-02-04 13:37:00 +01:00
parent 41f6945be1
commit 29ce4807fb
6 changed files with 27 additions and 12 deletions
+2
View File
@@ -27,6 +27,7 @@
// lots of tests (and probably quite a number of redundant tests) // lots of tests (and probably quite a number of redundant tests)
// modern compilers will optimize away much of this code // modern compilers will optimize away much of this code
#if 0 // TODO later
// libc++ hardenining // libc++ hardenining
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18) #if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
#if DEBUG #if DEBUG
@@ -40,6 +41,7 @@
#define _LIBCPP_ENABLE_ASSERTIONS 1 #define _LIBCPP_ENABLE_ASSERTIONS 1
#endif #endif
#endif #endif
#endif // TODO later
#include "../headers.h" #include "../headers.h"
#include <vector> #include <vector>
+2
View File
@@ -28,6 +28,7 @@
// doctest support code implementation // doctest support code implementation
**************************************************************************/ **************************************************************************/
#if 0 // TODO later
// libc++ hardenining // libc++ hardenining
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18) #if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
#if DEBUG #if DEBUG
@@ -41,6 +42,7 @@
#define _LIBCPP_ENABLE_ASSERTIONS 1 #define _LIBCPP_ENABLE_ASSERTIONS 1
#endif #endif
#endif #endif
#endif // TODO later
#if defined(__has_include) #if defined(__has_include)
#if __has_include(<features.h>) #if __has_include(<features.h>)
+6 -1
View File
@@ -242,7 +242,7 @@ TEST_CASE("basic xspan usage") {
} }
TEST_CASE("xspan array access") { TEST_CASE("xspan array access") {
constexpr size_t N = 16; const size_t N = 16;
char buf[N]; char buf[N];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
XSPAN_0_VAR(char, c0, buf, sizeof(buf)); XSPAN_0_VAR(char, c0, buf, sizeof(buf));
@@ -254,6 +254,7 @@ TEST_CASE("xspan array access") {
cp[i] += 1; cp[i] += 1;
for (size_t i = 0; i != N; ++i) for (size_t i = 0; i != N; ++i)
cs[i] += 1; cs[i] += 1;
#if __cplusplus >= 201103L
for (auto ptr = c0; ptr != c0 + N; ++ptr) for (auto ptr = c0; ptr != c0 + N; ++ptr)
*ptr += 1; *ptr += 1;
for (auto ptr = c0 + 0; ptr < c0 + N; ++ptr) for (auto ptr = c0 + 0; ptr < c0 + N; ++ptr)
@@ -266,6 +267,7 @@ TEST_CASE("xspan array access") {
*ptr += 1; *ptr += 1;
for (auto ptr = cs + 0; ptr < cs + N; ++ptr) for (auto ptr = cs + 0; ptr < cs + N; ++ptr)
*ptr += 1; *ptr += 1;
#endif
} }
/************************************************************************* /*************************************************************************
@@ -685,6 +687,9 @@ TEST_CASE("Span subspan") {
CHECK((as + 2).subspan(0, -2)[0] == 0); CHECK((as + 2).subspan(0, -2)[0] == 0);
CHECK_THROWS(as.subspan(1, 0)[0]); CHECK_THROWS(as.subspan(1, 0)[0]);
CHECK_THROWS(as.subspan(1, 1)[-1]); CHECK_THROWS(as.subspan(1, 1)[-1]);
CHECK(as.subspan(1)[0] == 1);
CHECK(as.subspan(2)[0] == 2);
CHECK(as.subspan(3)[0] == 3);
} }
TEST_CASE("Span constness") { TEST_CASE("Span constness") {
+4
View File
@@ -253,6 +253,10 @@ TEST_CASE("MemBuffer core") {
CHECK_THROWS(mb.alloc(0x30000000 + 1)); CHECK_THROWS(mb.alloc(0x30000000 + 1));
CHECK(raw_bytes(mb, 0) == nullptr); CHECK(raw_bytes(mb, 0) == nullptr);
CHECK_THROWS(raw_bytes(mb, 1)); CHECK_THROWS(raw_bytes(mb, 1));
CHECK_THROWS(mb.begin());
CHECK_THROWS(mb.end());
CHECK_THROWS(mb.cbegin());
CHECK_THROWS(mb.cend());
mb.alloc(N); mb.alloc(N);
mb.checkState(); mb.checkState();
CHECK(mb.begin() == mb.cbegin()); CHECK(mb.begin() == mb.cbegin());
+1 -2
View File
@@ -45,8 +45,7 @@ public:
typedef pointer iterator; typedef pointer iterator;
typedef typename std::add_pointer<const T>::type const_iterator; typedef typename std::add_pointer<const T>::type const_iterator;
protected: protected:
static constexpr size_t element_size = sizeof(element_type); static const size_t element_size = sizeof(element_type);
static_assert(element_size >= 1 && element_size <= UPX_RSIZE_MAX_MEM);
protected: protected:
pointer ptr; pointer ptr;
+12 -9
View File
@@ -271,14 +271,17 @@ public:
Self &operator=(MemBuffer &mb) { return assign(Self(mb)); } Self &operator=(MemBuffer &mb) { return assign(Self(mb)); }
#endif #endif
// subspan (creates a new value)
Self subspan(ptrdiff_t offset, ptrdiff_t count) const { Self subspan(ptrdiff_t offset, ptrdiff_t count) const {
pointer begin = check_add(ptr, offset); pointer p_begin = check_add(ptr, offset);
pointer end = check_add(begin, count); pointer p_end = check_add(p_begin, count);
if (begin <= end) if (p_begin <= p_end)
return Self(Unchecked, begin, (end - begin) * sizeof(T), begin); return Self(Unchecked, p_begin, (p_end - p_begin) * sizeof(T), p_begin);
else else
return Self(Unchecked, end, (begin - end) * sizeof(T), end); return Self(Unchecked, p_end, (p_begin - p_end) * sizeof(T), p_end);
} }
// subspan (creates a new value)
Self subspan(ptrdiff_t offset) const { return subspan(offset, size() - offset); }
// cast to a different type (creates a new value) // cast to a different type (creates a new value)
template <class U> template <class U>
@@ -454,16 +457,16 @@ public: // raw access
// like C++20 std::span // like C++20 std::span
pointer data() const noexcept { return ptr; } pointer data() const noexcept { return ptr; }
pointer data(size_t bytes) const { return raw_bytes(bytes); } // UPX extra pointer data(size_t bytes) const { return raw_bytes(bytes); } // UPX extra
// size_type size() const { return size_bytes() / sizeof(element_type); } // NOT USED size_type size() const noexcept { return size_bytes() / sizeof(element_type); }
size_type size_bytes() const { size_type size_bytes() const {
assertInvariants(); assertInvariants();
if __acc_cte (!configRequirePtr && ptr == nullptr) if __acc_cte (!configRequirePtr && ptr == nullptr)
return 0; return 0;
if __acc_cte (!configRequireBase && base == nullptr) if __acc_cte (!configRequireBase && base == nullptr)
return 0; return 0;
const charptr begin = (const charptr) ptr; const charptr p_begin = (const charptr) ptr;
const charptr end = (const charptr) base + size_in_bytes; const charptr p_end = (const charptr) base + size_in_bytes;
return end - begin; return p_end - p_begin;
} }
#if CLANG_FORMAT_DUMMY_CLASS #if CLANG_FORMAT_DUMMY_CLASS