CI updates and minor cleanups

This commit is contained in:
Markus F.X.J. Oberhumer
2024-04-01 20:31:05 +02:00
parent 70b20d7d89
commit 24f3824524
29 changed files with 176 additions and 128 deletions
+1 -1
View File
@@ -427,7 +427,7 @@ template <class T>
inline void owner_free(OwningPointer(T)(&object)) noexcept {
static_assert(!std::is_class_v<T>); // UPX convention
if (object != nullptr) {
free((T *) object);
::free((T *) object);
object = nullptr;
}
assert_noexcept((T *) object == nullptr);
+1 -1
View File
@@ -128,7 +128,7 @@ int upx_safe_vasprintf(char **ptr, const char *format, va_list ap) {
va_end(ap_copy);
if (len >= 0) {
*ptr = (char *) malloc(len + 1);
*ptr = (char *) ::malloc(len + 1);
assert(*ptr != nullptr);
if (*ptr == nullptr)
return -1;
+1 -1
View File
@@ -55,7 +55,7 @@
#if DEBUG
#define _LIBCPP_ENABLE_ASSERTIONS 1
#endif
#endif
#endif // clang >= 18
#endif // TODO later
/* vim:set ts=4 sw=4 et: */
+22 -19
View File
@@ -254,17 +254,19 @@ TEST_CASE("ptr_check_no_overlap 3") {
// stdlib
**************************************************************************/
int upx_rand(void) noexcept { return ::rand(); }
void *upx_calloc(size_t n, size_t element_size) may_throw {
size_t bytes = mem_size(element_size, n); // assert size
void *p = malloc(bytes);
void *p = ::malloc(bytes);
if (p != nullptr)
memset(p, 0, bytes);
return p;
}
// simple unoptimized memswap()
void upx_memswap(void *a, void *b, size_t n) noexcept {
if (a != b && n != 0) {
void upx_memswap(void *a, void *b, size_t bytes) noexcept {
if (a != b && bytes != 0) {
byte *x = (byte *) a;
byte *y = (byte *) b;
do {
@@ -273,16 +275,16 @@ void upx_memswap(void *a, void *b, size_t n) noexcept {
byte tmp = *x; // NOLINT(*core.uninitialized.Assign) // bogus clang-analyzer warning
*x++ = *y;
*y++ = tmp;
} while (--n != 0);
} while (--bytes != 0);
}
}
// much better memswap(), optimized for our use case in sort functions below
static void memswap_no_overlap(byte *a, byte *b, size_t n) noexcept {
static inline void memswap_no_overlap(byte *a, byte *b, size_t bytes) noexcept {
#if defined(__clang__) && __clang_major__ < 15
// work around a clang < 15 ICE (Internal Compiler Error)
// @COMPILER_BUG @CLANG_BUG
upx_memswap(a, b, n);
upx_memswap(a, b, bytes);
#else // clang bug
upx_alignas_max byte tmp_buf[16];
#define SWAP(x) \
@@ -294,15 +296,15 @@ static void memswap_no_overlap(byte *a, byte *b, size_t n) noexcept {
b += x; \
} while (0)
for (; n >= 16; n -= 16)
for (; bytes >= 16; bytes -= 16)
SWAP(16);
if (n & 8)
if (bytes & 8)
SWAP(8);
if (n & 4)
if (bytes & 4)
SWAP(4);
if (n & 2)
if (bytes & 2)
SWAP(2);
if (n & 1) {
if (bytes & 1) {
byte tmp = *a;
*a = *b;
*b = tmp;
@@ -347,7 +349,7 @@ void upx_shellsort_memcpy(void *array, size_t n, size_t element_size, upx_compar
upx_alignas_max byte tmp_buf[MAX_INLINE_ELEMENT_SIZE]; // buffer for one element
byte *tmp = tmp_buf;
if (element_size > MAX_INLINE_ELEMENT_SIZE) {
tmp = (byte *) malloc(element_size);
tmp = (byte *) ::malloc(element_size);
assert(tmp != nullptr);
}
size_t gap = 0; // 0, 1, 4, 13, 40, 121, 364, 1093, ...
@@ -368,7 +370,7 @@ void upx_shellsort_memcpy(void *array, size_t n, size_t element_size, upx_compar
}
}
if (element_size > MAX_INLINE_ELEMENT_SIZE)
free(tmp);
::free(tmp);
}
// wrap std::stable_sort()
@@ -391,9 +393,10 @@ void upx_std_stable_sort(void *array, size_t n, upx_compare_func_t compare) {
}
#if UPX_CONFIG_USE_STABLE_SORT
// instantiate function templates for all element sizes we need; efficient run time, but code size
// bloat (about 4KiB code size for each function with my current libstdc++); not really needed as
// libc qsort() is good enough for our use cases
// instantiate function templates for all element sizes we need; efficient
// run-time, but code size bloat (about 4KiB code size for each function
// with my current libstdc++); not really needed as libc qsort() is
// good enough for our use cases
template void upx_std_stable_sort<1>(void *, size_t, upx_compare_func_t);
template void upx_std_stable_sort<2>(void *, size_t, upx_compare_func_t);
template void upx_std_stable_sort<4>(void *, size_t, upx_compare_func_t);
@@ -405,7 +408,7 @@ template void upx_std_stable_sort<56>(void *, size_t, upx_compare_func_t);
template void upx_std_stable_sort<72>(void *, size_t, upx_compare_func_t);
#endif
#if !defined(DOCTEST_CONFIG_DISABLE) && DEBUG >= 1
#if !defined(DOCTEST_CONFIG_DISABLE) && DEBUG
#if __cplusplus >= 202002L // use C++20 std::next_permutation() to test all permutations
namespace {
template <class ElementType, upx_compare_func_t CompareFunc>
@@ -588,7 +591,7 @@ int find(const void *buf, int blen, const void *what, int wlen) noexcept {
return -1;
const byte *b = (const byte *) buf;
byte first_byte = *(const byte *) what;
const byte first_byte = *(const byte *) what;
blen -= wlen;
for (int i = 0; i <= blen; i++, b++)
@@ -769,8 +772,8 @@ int fn_strcmp(const char *n1, const char *n2) {
// misc
**************************************************************************/
// UPX convention: any environment variable that is set and is not strictly equal to "0" is true
bool is_envvar_true(const char *envvar, const char *alternate_name) noexcept {
// UPX convention: any environment variable that is set and is not strictly equal to "0" is true
const char *e = getenv(envvar);
if (e != nullptr && e[0])
return strcmp(e, "0") != 0;
+5 -3
View File
@@ -143,9 +143,11 @@ inline void ptr_invalidate_and_poison(T *(&ptr)) noexcept {
// stdlib
**************************************************************************/
void *upx_calloc(size_t n, size_t element_size) may_throw;
noinline void *upx_calloc(size_t n, size_t element_size) may_throw;
void upx_memswap(void *a, void *b, size_t n) noexcept;
void upx_memswap(void *a, void *b, size_t bytes) noexcept;
noinline int upx_rand(void) noexcept;
typedef int(__acc_cdecl_qsort *upx_compare_func_t)(const void *, const void *);
typedef void (*upx_sort_func_t)(void *array, size_t n, size_t element_size, upx_compare_func_t);
@@ -165,7 +167,7 @@ void upx_std_stable_sort(void *array, size_t n, upx_compare_func_t compare);
upx_std_stable_sort<(element_size)>((a), (n), (compare))
#else
// use libc qsort(); good enough for our use cases
#define upx_qsort qsort
#define upx_qsort ::qsort
#endif
/*************************************************************************