all: cosmetic cleanups
This commit is contained in:
@@ -634,7 +634,7 @@ TEST_CASE("libc qsort") {
|
||||
struct Elem {
|
||||
upx_uint16_t id;
|
||||
upx_uint16_t value;
|
||||
static int compare(const void *aa, const void *bb) noexcept {
|
||||
static int __acc_cdecl_qsort compare(const void *aa, const void *bb) noexcept {
|
||||
const Elem *a = (const Elem *) aa;
|
||||
const Elem *b = (const Elem *) bb;
|
||||
assert_noexcept(a->id != b->id); // check not IDENTICAL
|
||||
@@ -657,11 +657,11 @@ TEST_CASE("libc qsort") {
|
||||
constexpr size_t N = 4096;
|
||||
Elem e[N];
|
||||
for (size_t n = 0; n <= N; n = 2 * n + 1) {
|
||||
CHECK(Elem::check_sort(qsort, e, n));
|
||||
// CHECK(Elem::check_sort(qsort, e, n)); // libc qsort()
|
||||
CHECK(Elem::check_sort(upx_gnomesort, e, n));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memswap, e, n));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memcpy, e, n));
|
||||
#if UPX_QSORT_IS_STABLE_SORT
|
||||
#if UPX_CONFIG_USE_STABLE_SORT
|
||||
upx_sort_func_t wrap_stable_sort = [](void *aa, size_t nn, size_t, upx_compare_func_t cc) {
|
||||
upx_std_stable_sort<sizeof(Elem)>(aa, nn, cc);
|
||||
};
|
||||
|
||||
+83
-1
@@ -806,7 +806,7 @@ TEST_CASE("PtrOrSpan int") {
|
||||
|
||||
namespace {
|
||||
template <class T>
|
||||
__acc_static_noinline int foo(T p) {
|
||||
static noinline int foo(T p) {
|
||||
unsigned r = 0;
|
||||
r += *p++;
|
||||
r += *++p;
|
||||
@@ -849,4 +849,86 @@ TEST_CASE("Span codegen") {
|
||||
|
||||
#endif // WITH_XSPAN >= 2
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
namespace {
|
||||
template <class T>
|
||||
struct PointerTraits {
|
||||
typedef typename std::add_lvalue_reference<T>::type reference;
|
||||
typedef
|
||||
typename std::add_lvalue_reference<typename std::add_const<T>::type>::type const_reference;
|
||||
typedef typename std::add_pointer<T>::type pointer;
|
||||
typedef typename std::add_pointer<typename std::add_const<T>::type>::type const_pointer;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
|
||||
TEST_CASE("decltype integral constants") {
|
||||
static_assert((std::is_same<decltype(0), int>::value), "");
|
||||
static_assert((std::is_same<decltype(0u), unsigned>::value), "");
|
||||
static_assert((std::is_same<decltype(0l), long>::value), "");
|
||||
static_assert((std::is_same<decltype(0ul), unsigned long>::value), "");
|
||||
static_assert((std::is_same<decltype(0ll), long long>::value), "");
|
||||
static_assert((std::is_same<decltype(0ull), unsigned long long>::value), "");
|
||||
static_assert((std::is_same<decltype((char) 0), char>::value), "");
|
||||
static_assert((std::is_same<decltype((short) 0), short>::value), "");
|
||||
static_assert((std::is_same<decltype((long) 0), long>::value), "");
|
||||
static_assert((std::is_same<decltype((long long) 0), long long>::value), "");
|
||||
static_assert((std::is_same<decltype(char(0)), char>::value), "");
|
||||
static_assert((std::is_same<decltype(short(0)), short>::value), "");
|
||||
static_assert((std::is_same<decltype(long(0)), long>::value), "");
|
||||
}
|
||||
|
||||
TEST_CASE("decltype pointer") {
|
||||
int dummy = 0;
|
||||
int *p = &dummy;
|
||||
const int *c = &dummy;
|
||||
static_assert((std::is_same<decltype(p - p), std::ptrdiff_t>::value), "");
|
||||
static_assert((std::is_same<decltype(c - c), std::ptrdiff_t>::value), "");
|
||||
static_assert((std::is_same<decltype(p - c), std::ptrdiff_t>::value), "");
|
||||
static_assert((std::is_same<decltype(c - p), std::ptrdiff_t>::value), "");
|
||||
typedef PointerTraits<int> TInt;
|
||||
typedef PointerTraits<const int> TConstInt;
|
||||
static_assert((std::is_same<int *, TInt::pointer>::value), "");
|
||||
static_assert((std::is_same<const int *, TInt::const_pointer>::value), "");
|
||||
static_assert((std::is_same<const int *, TConstInt::pointer>::value), "");
|
||||
static_assert((std::is_same<const int *, TConstInt::const_pointer>::value), "");
|
||||
//
|
||||
static_assert((std::is_same<decltype(p), TInt::pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c), TInt::const_pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c), TConstInt::pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(p + 1), TInt::pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c + 1), TInt::const_pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c + 1), TConstInt::pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c + 1), TConstInt::const_pointer>::value), "");
|
||||
static_assert((std::is_same<decltype(c + 1), const int *>::value), "");
|
||||
// dereference
|
||||
static_assert((std::is_same<decltype(*p), TInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*c), TInt::const_reference>::value), "");
|
||||
#if 0
|
||||
// this works, but avoid clang warnings:
|
||||
// "Expression with side effects has no effect in an unevaluated context"
|
||||
static_assert((std::is_same<decltype(*p++), TInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*++p), TInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*c++), TInt::const_reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*c++), TConstInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*c++), TConstInt::const_reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*++c), TInt::const_reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*++c), TConstInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(*++c), TConstInt::const_reference>::value), "");
|
||||
#endif
|
||||
// array access
|
||||
static_assert((std::is_same<decltype(p[0]), TInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(c[0]), TInt::const_reference>::value), "");
|
||||
static_assert((std::is_same<decltype(c[0]), TConstInt::reference>::value), "");
|
||||
static_assert((std::is_same<decltype(c[0]), TConstInt::const_reference>::value), "");
|
||||
UNUSED(p);
|
||||
UNUSED(c);
|
||||
}
|
||||
|
||||
#endif // __cplusplus >= 201103L
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
||||
+5
-5
@@ -64,7 +64,7 @@ static void handle_opterr(acc_getopt_p g, const char *f, void *v) {
|
||||
static int exit_code = EXIT_OK;
|
||||
|
||||
#if (WITH_GUI)
|
||||
__acc_static_noinline void do_exit(void) { throw exit_code; }
|
||||
static noinline void do_exit(void) { throw exit_code; }
|
||||
#else
|
||||
#if defined(__GNUC__)
|
||||
static void do_exit(void) __attribute__((__noreturn__));
|
||||
@@ -105,14 +105,14 @@ static bool set_eec(int ec, int *eec) {
|
||||
|
||||
bool main_set_exit_code(int ec) { return set_eec(ec, &exit_code); }
|
||||
|
||||
__acc_static_noinline void e_exit(int ec) {
|
||||
static noinline void e_exit(int ec) {
|
||||
if (opt->debug.getopt_throw_instead_of_exit)
|
||||
throw ec;
|
||||
(void) main_set_exit_code(ec);
|
||||
do_exit();
|
||||
}
|
||||
|
||||
__acc_static_noinline void e_usage(void) {
|
||||
static noinline void e_usage(void) {
|
||||
if (opt->debug.getopt_throw_instead_of_exit)
|
||||
throw EXIT_USAGE;
|
||||
show_usage();
|
||||
@@ -220,7 +220,7 @@ static void e_help(void) {
|
||||
}
|
||||
|
||||
static void set_term(FILE *f) {
|
||||
if (f)
|
||||
if (f != nullptr)
|
||||
con_term = f;
|
||||
else
|
||||
con_term = acc_isatty(STDIN_FILENO) ? stderr : stdout;
|
||||
@@ -1327,7 +1327,7 @@ int _dowildcard = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int __acc_cdecl_main main(int argc, char *argv[]) {
|
||||
int __acc_cdecl_main main(int argc, char *argv[]) /*noexcept*/ {
|
||||
#if 0 && (ACC_OS_DOS32) && defined(__DJGPP__)
|
||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||
putenv("LFN=y");
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public:
|
||||
// getVersion() enables detecting forward incompatibility of unpack()
|
||||
// by old upx when newer upx changes the format of compressed output.
|
||||
virtual int getVersion() const = 0;
|
||||
// A unique integer ID for this executable format. See conf.h.
|
||||
// A unique integer ID for this executable format; see UPX_F_xxx in conf.h.
|
||||
virtual int getFormat() const = 0;
|
||||
virtual const char *getName() const = 0;
|
||||
virtual const char *getFullName(const Options *) const = 0;
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ unsigned Packer::unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P
|
||||
if (pc + 4 > image_size)
|
||||
throwCantUnpack("bad reloc[%#x] = %#x", i, pc);
|
||||
*relocs++ = pc;
|
||||
if (bswap && image != nullptr) {
|
||||
if (bswap) {
|
||||
if (bits == 32)
|
||||
set_be32(image + pc, get_le32(image + pc));
|
||||
else
|
||||
|
||||
+3
-3
@@ -95,7 +95,7 @@ int PackHeader::getPackHeaderSize() const {
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// see stub/header.ash
|
||||
// see stub/src/include/header.S
|
||||
**************************************************************************/
|
||||
|
||||
void PackHeader::putPackHeader(SPAN_S(byte) p) const {
|
||||
@@ -111,7 +111,7 @@ void PackHeader::putPackHeader(SPAN_S(byte) p) const {
|
||||
int old_chksum = 0;
|
||||
|
||||
// the new variable length header
|
||||
if (format < 128) {
|
||||
if (format < 128) { // little endian
|
||||
if (format == UPX_F_DOS_COM || format == UPX_F_DOS_SYS) {
|
||||
size = 22;
|
||||
old_chksum = get_packheader_checksum(p, size - 1);
|
||||
@@ -140,7 +140,7 @@ void PackHeader::putPackHeader(SPAN_S(byte) p) const {
|
||||
}
|
||||
set_le32(p + 8, u_adler);
|
||||
set_le32(p + 12, c_adler);
|
||||
} else {
|
||||
} else { // big endian
|
||||
size = 32;
|
||||
old_chksum = get_packheader_checksum(p, size - 1);
|
||||
set_be32(p + 8, u_len);
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
/* cxxlib.h --
|
||||
/* cxxlib.h -- C++ support library
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace upx {
|
||||
// type_traits
|
||||
**************************************************************************/
|
||||
|
||||
// <type_traits> is_bounded_array: same as C++20 std::is_bounded_array
|
||||
// is_bounded_array: identical to C++20 std::is_bounded_array
|
||||
template <class T>
|
||||
struct is_bounded_array : public std::false_type {};
|
||||
template <class T, size_t N>
|
||||
@@ -43,7 +43,7 @@ struct is_bounded_array<T[N]> : public std::true_type {};
|
||||
template <class T>
|
||||
inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
|
||||
|
||||
// <type_traits> util: is_same_all and is_same_any means std::is_same for multiple types
|
||||
// is_same_all and is_same_any: std::is_same for multiple types
|
||||
template <class T, class... Ts>
|
||||
struct is_same_all : public std::conjunction<std::is_same<T, Ts>...> {};
|
||||
template <class T, class... Ts>
|
||||
@@ -125,7 +125,7 @@ struct TriBool final {
|
||||
return value == TriBool(other).value;
|
||||
}
|
||||
|
||||
// "Third" can mean many things, depending on usage context, so provide some alternative names:
|
||||
// "Third" can mean many things - depending on usage context, so provide some alternate names:
|
||||
// constexpr bool isDefault() const noexcept { return isThird(); } // might be misleading
|
||||
constexpr bool isIndeterminate() const noexcept { return isThird(); }
|
||||
constexpr bool isOther() const noexcept { return isThird(); }
|
||||
|
||||
+1
-1
@@ -388,7 +388,7 @@ void upx_std_stable_sort(void *array, size_t n, upx_compare_func_t compare) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UPX_QSORT_IS_STABLE_SORT
|
||||
#if UPX_CONFIG_USE_STABLE_SORT
|
||||
// instantiate function templates for all element sizes we need
|
||||
// efficient, but code size bloat
|
||||
template void upx_std_stable_sort<1>(void *, size_t, upx_compare_func_t);
|
||||
|
||||
+5
-5
@@ -138,13 +138,13 @@ void upx_shellsort_memcpy(void *array, size_t n, size_t element_size, upx_compar
|
||||
template <size_t ElementSize>
|
||||
void upx_std_stable_sort(void *array, size_t n, upx_compare_func_t compare);
|
||||
|
||||
#if 1
|
||||
// #define UPX_CONFIG_USE_STABLE_SORT 1
|
||||
#if UPX_CONFIG_USE_STABLE_SORT
|
||||
// use std::stable_sort(); requires that "element_size" is constexpr!
|
||||
#define upx_qsort(a, n, element_size, compare) upx_std_stable_sort<(element_size)>(a, n, compare)
|
||||
#else
|
||||
// use libc qsort()
|
||||
#define upx_qsort qsort
|
||||
#else
|
||||
// use std::stable_sort()
|
||||
#define upx_qsort(a, b, c, d) upx_std_stable_sort<(c)>(a, b, d)
|
||||
#define UPX_QSORT_IS_STABLE_SORT 1
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@
|
||||
#include "xspan_impl.h"
|
||||
|
||||
#ifdef XSPAN_NAMESPACE_NAME
|
||||
// help constructor to distinguish between number of elements and bytes
|
||||
// types to help the constructor to distinguish between number of elements and bytes
|
||||
using XSPAN_NAMESPACE_NAME::XSpanCount;
|
||||
using XSPAN_NAMESPACE_NAME::XSpanSizeInBytes;
|
||||
// actual classes
|
||||
@@ -59,7 +59,7 @@ using XSPAN_NAMESPACE_NAME::Ptr;
|
||||
using XSPAN_NAMESPACE_NAME::PtrOrSpan;
|
||||
using XSPAN_NAMESPACE_NAME::PtrOrSpanOrNull;
|
||||
using XSPAN_NAMESPACE_NAME::Span;
|
||||
// util
|
||||
// support functions
|
||||
using XSPAN_NAMESPACE_NAME::raw_bytes; // overloaded for all classes
|
||||
using XSPAN_NAMESPACE_NAME::raw_index_bytes; // overloaded for all classes
|
||||
#endif
|
||||
|
||||
@@ -204,8 +204,6 @@ struct XSpanInternalDummyArg {
|
||||
#define XSpanInternalDummyArgInit (XSPAN_NS(XSpanInternalDummyArg)(0, nullptr))
|
||||
#endif
|
||||
|
||||
XSPAN_NAMESPACE_END
|
||||
|
||||
// poison a pointer: point to a non-null invalid address
|
||||
// - resulting pointer should crash on dereference
|
||||
// - this should be efficient (so no mmap() guard page etc.)
|
||||
@@ -216,6 +214,8 @@ static forceinline void *XSPAN_GET_POISON_VOID_PTR() {
|
||||
return (void *) 251;
|
||||
}
|
||||
|
||||
XSPAN_NAMESPACE_END
|
||||
|
||||
#ifndef XSPAN_DELETED_FUNCTION
|
||||
#define XSPAN_DELETED_FUNCTION = delete
|
||||
#endif
|
||||
|
||||
@@ -443,7 +443,7 @@ public: // raw access
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// like C++ std::span
|
||||
// like C++20 std::span
|
||||
pointer data() const noexcept { return ptr; }
|
||||
pointer data(size_t bytes) const { return raw_bytes(bytes); } // UPX extra
|
||||
// size_type size() const { return size_bytes() / sizeof(element_type); } // NOT USED
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#define UPX_VERSION_HEX 0x040200 /* 04.02.00 */
|
||||
#define UPX_VERSION_STRING "4.2.0"
|
||||
#define UPX_VERSION_STRING4 "4.20"
|
||||
#define UPX_VERSION_DATE "Aug 25th 2023"
|
||||
#define UPX_VERSION_DATE_ISO "2023-08-25"
|
||||
#define UPX_VERSION_DATE "Sep 12th 2023"
|
||||
#define UPX_VERSION_DATE_ISO "2023-09-12"
|
||||
#define UPX_VERSION_YEAR "2023"
|
||||
|
||||
Reference in New Issue
Block a user