From 67548a4d9a424c1921f92d3914a0ce16af9c51e9 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 22 Oct 2023 00:45:06 +0200 Subject: [PATCH] src: minor cleanups --- src/p_wince_arm.cpp | 2 +- src/stub/i386-dos32.djgpp2-stubify.h | 2 + src/stub/scripts/bin2h.py | 6 +-- src/ui.cpp | 2 +- src/util/xspan_fwd.h | 64 ++++++++++++++-------------- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/p_wince_arm.cpp b/src/p_wince_arm.cpp index 0cbb360e..c4b95664 100644 --- a/src/p_wince_arm.cpp +++ b/src/p_wince_arm.cpp @@ -118,7 +118,7 @@ tribool PackWinCeArm::canPack() { if (ih.cpu != IMAGE_FILE_MACHINE_ARM && ih.cpu != IMAGE_FILE_MACHINE_THUMB) return false; use_thumb_stub |= ih.cpu == IMAGE_FILE_MACHINE_THUMB || (ih.entry & 1) == 1; - // FIXME later: don't misuse opt->cpu_x86, need an extra option for thumb + // HACK FIXME later: don't misuse opt->cpu_x86, need an extra option to force thumb stub use_thumb_stub |= (opt->cpu_x86 == opt->CPU_8086); return true; } diff --git a/src/stub/i386-dos32.djgpp2-stubify.h b/src/stub/i386-dos32.djgpp2-stubify.h index 549806f8..c2714f85 100644 --- a/src/stub/i386-dos32.djgpp2-stubify.h +++ b/src/stub/i386-dos32.djgpp2-stubify.h @@ -1,3 +1,5 @@ +/* clang-format off */ + #define STUB_I386_DOS32_DJGPP2_STUBIFY_SIZE 2048 #define STUB_I386_DOS32_DJGPP2_STUBIFY_ADLER32 0xbf689ba8 #define STUB_I386_DOS32_DJGPP2_STUBIFY_CRC32 0x2ae982b2 diff --git a/src/stub/scripts/bin2h.py b/src/stub/scripts/bin2h.py index a2433371..14b09385 100644 --- a/src/stub/scripts/bin2h.py +++ b/src/stub/scripts/bin2h.py @@ -75,7 +75,6 @@ def w_header_c(w, ifile, ofile, n): John F. Reiser */\n\n""") - w("/* clang" + "-format off */\n\n") # /*********************************************************************** @@ -347,9 +346,10 @@ def main(argv): else: ofp = open(ofile, "wb") w = ofp.write - if opts.verbose >= 0: - if opts.mode == "c": + if opts.mode == "c": + if opts.verbose >= 0: w_header_c(w, ifile, ofile, len(idata)) + w("/* clang" + "-format off */\n\n") for i in range(len(mdata)): write_stub(w, mdata_odata[mdata[i]], i, mdata) if ofp: diff --git a/src/ui.cpp b/src/ui.cpp index 8be81896..8cd008ec 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -128,7 +128,7 @@ static void init_global_constants(void) noexcept { static const char *mkline(upx_uint64_t fu_len, upx_uint64_t fc_len, upx_uint64_t u_len, upx_uint64_t c_len, const char *format_name, const char *filename, bool decompress = false) { - static char buf[2048]; // static! + static char buf[2048]; // static! // TODO later: check if affected by WITH_THREADS char r[7 + 1]; char fn[15 + 1]; const char *f; diff --git a/src/util/xspan_fwd.h b/src/util/xspan_fwd.h index 87d7081c..2b8c238f 100644 --- a/src/util/xspan_fwd.h +++ b/src/util/xspan_fwd.h @@ -34,11 +34,11 @@ // #define XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(A, B, RType) // std::enable_if_t || std::is_convertible_v, RType> -// requires convertible T to U, or U to T +// requires convertible T* to U* or U* to T* #define XSPAN_FWD_TU_CONVERTIBLE(RType) \ template \ inline XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(T, U, RType) -// any pointer type, matching automatic conversion to "void *" +// requires convertible to void* (i.e. any pointer type matches) #define XSPAN_FWD_TU_VOIDPTR(RType) \ template \ inline RType @@ -54,10 +54,8 @@ template inline typename std::enable_if::value, void *>::type operator+(U, const C &) XSPAN_DELETED_FUNCTION; -#if 0 // handled by member functions -XSPAN_FWD_TU_CONVERTIBLE(bool) operator==(const C &a, const U *b) { - return a.raw_bytes(0) == b; -} +#if 0 // already handled by member functions +XSPAN_FWD_TU_CONVERTIBLE(bool) operator==(const C &a, const U *b) { return a.raw_bytes(0) == b; } XSPAN_FWD_TU_CONVERTIBLE(bool) operator==(const C &a, const C &b) { return a.raw_bytes(0) == b.raw_bytes(0); } @@ -72,9 +70,7 @@ XSPAN_FWD_TU_CONVERTIBLE(bool) operator==(const C &a, const E &b) { } #endif -XSPAN_FWD_TU_CONVERTIBLE(bool) operator!=(const C &a, const U *b) { - return a.raw_bytes(0) != b; -} +XSPAN_FWD_TU_CONVERTIBLE(bool) operator!=(const C &a, const U *b) { return a.raw_bytes(0) != b; } XSPAN_FWD_TU_CONVERTIBLE(bool) operator!=(const C &a, const C &b) { return a.raw_bytes(0) != b.raw_bytes(0); } @@ -88,7 +84,7 @@ XSPAN_FWD_TU_CONVERTIBLE(bool) operator!=(const C &a, const E &b) { return a.raw_bytes(0) != b.raw_bytes(0); } #endif -#endif // if 0 // handled by member functions +#endif // if 0 // already handled by member functions #endif // XSPAN_FWD_C_IS_MEMBUFFER @@ -177,7 +173,7 @@ inline void *memset(const C &a, int v, size_t n) { } /************************************************************************* -// overloads for UPX extras +// overloads for UPX extras 1 **************************************************************************/ template @@ -224,96 +220,100 @@ XSPAN_FWD_TU_VOIDPTR(unsigned) ptr_udiff_bytes(const C &a, const E &b) { } #endif +/************************************************************************* +// overloads for UPX extras 2 +**************************************************************************/ + #ifdef UPX_VERSION_HEX template -unsigned upx_adler32(const C &a, unsigned n, unsigned adler = 1) { +inline unsigned upx_adler32(const C &a, unsigned n, unsigned adler = 1) { return upx_adler32(a.raw_bytes(n), n, adler); } template -unsigned get_ne16(const C &a) { +inline unsigned get_ne16(const C &a) { return get_ne16(a.raw_bytes(2)); } template -unsigned get_ne32(const C &a) { +inline unsigned get_ne32(const C &a) { return get_ne32(a.raw_bytes(4)); } template -upx_uint64_t get_ne64(const C &a) { +inline upx_uint64_t get_ne64(const C &a) { return get_ne64(a.raw_bytes(8)); } template -unsigned get_be16(const C &a) { +inline unsigned get_be16(const C &a) { return get_be16(a.raw_bytes(2)); } template -unsigned get_be32(const C &a) { +inline unsigned get_be32(const C &a) { return get_be32(a.raw_bytes(4)); } template -upx_uint64_t get_be64(const C &a) { +inline upx_uint64_t get_be64(const C &a) { return get_be64(a.raw_bytes(8)); } template -unsigned get_le16(const C &a) { +inline unsigned get_le16(const C &a) { return get_le16(a.raw_bytes(2)); } template -unsigned get_le24(const C &a) { +inline unsigned get_le24(const C &a) { return get_le24(a.raw_bytes(3)); } template -unsigned get_le32(const C &a) { +inline unsigned get_le32(const C &a) { return get_le32(a.raw_bytes(4)); } template -upx_uint64_t get_le64(const C &a) { +inline upx_uint64_t get_le64(const C &a) { return get_le64(a.raw_bytes(8)); } template -void set_ne16(const C &a, unsigned v) { +inline void set_ne16(const C &a, unsigned v) { return set_ne16(a.raw_bytes(2), v); } template -void set_ne32(const C &a, unsigned v) { +inline void set_ne32(const C &a, unsigned v) { return set_ne32(a.raw_bytes(4), v); } template -void set_ne64(const C &a, upx_uint64_t v) { +inline void set_ne64(const C &a, upx_uint64_t v) { return set_ne64(a.raw_bytes(8), v); } template -void set_be16(const C &a, unsigned v) { +inline void set_be16(const C &a, unsigned v) { return set_be16(a.raw_bytes(2), v); } template -void set_be32(const C &a, unsigned v) { +inline void set_be32(const C &a, unsigned v) { return set_be32(a.raw_bytes(4), v); } template -void set_be64(const C &a, upx_uint64_t v) { +inline void set_be64(const C &a, upx_uint64_t v) { return set_be64(a.raw_bytes(8), v); } template -void set_le16(const C &a, unsigned v) { +inline void set_le16(const C &a, unsigned v) { return set_le16(a.raw_bytes(2), v); } template -void set_le24(const C &a, unsigned v) { +inline void set_le24(const C &a, unsigned v) { return set_le24(a.raw_bytes(3), v); } template -void set_le32(const C &a, unsigned v) { +inline void set_le32(const C &a, unsigned v) { return set_le32(a.raw_bytes(4), v); } template -void set_le64(const C &a, upx_uint64_t v) { +inline void set_le64(const C &a, upx_uint64_t v) { return set_le64(a.raw_bytes(8), v); }