src: clang-format conf.h
This commit is contained in:
+1
-1
@@ -93,7 +93,7 @@ endif
|
|||||||
# automatically format some C++ source code files
|
# automatically format some C++ source code files
|
||||||
ifeq ($(shell uname),Linux)
|
ifeq ($(shell uname),Linux)
|
||||||
# Markus loves clang-format, but John hates it; find a compromise
|
# Markus loves clang-format, but John hates it; find a compromise
|
||||||
CLANG_FORMAT_EXCLUDE_FILES += conf.h miniacc.h stub/%.h
|
CLANG_FORMAT_EXCLUDE_FILES += miniacc.h stub/%.h
|
||||||
CLANG_FORMAT_EXCLUDE_FILES += p_elf.h p_elf_enum.h p_lx_% p_mach% p_unix% p_vmlin%
|
CLANG_FORMAT_EXCLUDE_FILES += p_elf.h p_elf_enum.h p_lx_% p_mach% p_unix% p_vmlin%
|
||||||
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
||||||
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
|
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
|
||||||
|
|||||||
+73
-42
@@ -58,7 +58,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0)
|
|||||||
ACC_COMPILE_TIME_ASSERT_HEADER(((int) (1u << 31)) >> 31 == -1) // arithmetic right shift
|
ACC_COMPILE_TIME_ASSERT_HEADER(((int) (1u << 31)) >> 31 == -1) // arithmetic right shift
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER((-1) >> 31 == -1) // arithmetic right shift
|
ACC_COMPILE_TIME_ASSERT_HEADER((-1) >> 31 == -1) // arithmetic right shift
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char
|
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) == 255) // -funsigned-char
|
ACC_COMPILE_TIME_ASSERT_HEADER((char) (-1) == 255)
|
||||||
|
|
||||||
// enable some more strict warnings for Git developer builds
|
// enable some more strict warnings for Git developer builds
|
||||||
#if defined(UPX_CONFIG_DISABLE_WSTRICT) && (UPX_CONFIG_DISABLE_WSTRICT + 0 == 0)
|
#if defined(UPX_CONFIG_DISABLE_WSTRICT) && (UPX_CONFIG_DISABLE_WSTRICT + 0 == 0)
|
||||||
@@ -94,7 +94,10 @@ ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) == 255) // -funsigned-char
|
|||||||
#define upx_std_once_flag upx_std_atomic(size_t)
|
#define upx_std_once_flag upx_std_atomic(size_t)
|
||||||
template <class NoexceptCallable>
|
template <class NoexceptCallable>
|
||||||
inline void upx_std_call_once(upx_std_once_flag &flag, NoexceptCallable &&f) {
|
inline void upx_std_call_once(upx_std_once_flag &flag, NoexceptCallable &&f) {
|
||||||
if (__acc_unlikely(!flag)) { flag = 1; f(); }
|
if (__acc_unlikely(!flag)) {
|
||||||
|
flag = 1;
|
||||||
|
f();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // WITH_THREADS
|
#endif // WITH_THREADS
|
||||||
|
|
||||||
@@ -118,7 +121,6 @@ inline constexpr bool upx_is_integral_v = upx_is_integral<T>::value;
|
|||||||
#define upx_alignas_max alignas(std::max_align_t)
|
#define upx_alignas_max alignas(std::max_align_t)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// core
|
// core
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -185,7 +187,6 @@ typedef upx_int64_t upx_off_t;
|
|||||||
#define DELETED_FUNCTION = delete
|
#define DELETED_FUNCTION = delete
|
||||||
#define UNUSED(var) ACC_UNUSED(var)
|
#define UNUSED(var) ACC_UNUSED(var)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// portab
|
// portab
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -205,7 +206,8 @@ typedef upx_int64_t upx_off_t;
|
|||||||
#if (ACC_OS_POSIX) && !defined(__unix__)
|
#if (ACC_OS_POSIX) && !defined(__unix__)
|
||||||
#define __unix__ 1
|
#define __unix__ 1
|
||||||
#endif
|
#endif
|
||||||
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || \
|
||||||
|
ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
#undef __unix
|
#undef __unix
|
||||||
#undef __unix__
|
#undef __unix__
|
||||||
#endif
|
#endif
|
||||||
@@ -288,7 +290,8 @@ typedef upx_int64_t upx_off_t;
|
|||||||
#undef PAGE_SIZE
|
#undef PAGE_SIZE
|
||||||
|
|
||||||
#if !defined(O_BINARY) || (O_BINARY + 0 == 0)
|
#if !defined(O_BINARY) || (O_BINARY + 0 == 0)
|
||||||
# if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || \
|
||||||
|
ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
#error "missing O_BINARY"
|
#error "missing O_BINARY"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -296,7 +299,6 @@ typedef upx_int64_t upx_off_t;
|
|||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -356,13 +358,24 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {}
|
|||||||
|
|
||||||
// TODO cleanup: we now require C++17, so remove all __packed_struct usage
|
// TODO cleanup: we now require C++17, so remove all __packed_struct usage
|
||||||
#define __packed_struct(s) struct alignas(1) s {
|
#define __packed_struct(s) struct alignas(1) s {
|
||||||
#define __packed_struct_end() };
|
#define __packed_struct_end() \
|
||||||
|
} \
|
||||||
|
;
|
||||||
|
|
||||||
#define COMPILE_TIME_ASSERT_ALIGNOF_USING_SIZEOF__(a,b) { \
|
#define COMPILE_TIME_ASSERT_ALIGNOF_USING_SIZEOF__(a, b) \
|
||||||
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
|
{ \
|
||||||
struct alignas(1) acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; }; \
|
typedef a acc_tmp_a_t; \
|
||||||
|
typedef b acc_tmp_b_t; \
|
||||||
|
struct alignas(1) acc_tmp_t { \
|
||||||
|
acc_tmp_b_t x; \
|
||||||
|
acc_tmp_a_t y; \
|
||||||
|
acc_tmp_b_t z; \
|
||||||
|
}; \
|
||||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2 * sizeof(b) + sizeof(a)) \
|
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2 * sizeof(b) + sizeof(a)) \
|
||||||
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)nullptr)->x)+sizeof(((acc_tmp_t*)nullptr)->y)+sizeof(((acc_tmp_t*)nullptr)->z) == 2*sizeof(b)+sizeof(a)) \
|
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t *) nullptr)->x) + \
|
||||||
|
sizeof(((acc_tmp_t *) nullptr)->y) + \
|
||||||
|
sizeof(((acc_tmp_t *) nullptr)->z) == \
|
||||||
|
2 * sizeof(b) + sizeof(a)) \
|
||||||
}
|
}
|
||||||
#define COMPILE_TIME_ASSERT_ALIGNOF__(a, b) \
|
#define COMPILE_TIME_ASSERT_ALIGNOF__(a, b) \
|
||||||
COMPILE_TIME_ASSERT_ALIGNOF_USING_SIZEOF__(a, b) \
|
COMPILE_TIME_ASSERT_ALIGNOF_USING_SIZEOF__(a, b) \
|
||||||
@@ -372,18 +385,37 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {}
|
|||||||
|
|
||||||
#define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0])))
|
#define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0])))
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline T ALIGN_DOWN(const T &a, const T &b) {
|
||||||
|
T r;
|
||||||
|
r = (a / b) * b;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
inline T ALIGN_UP(const T &a, const T &b) {
|
||||||
|
T r;
|
||||||
|
r = ((a + b - 1) / b) * b;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
inline T ALIGN_GAP(const T &a, const T &b) {
|
||||||
|
T r;
|
||||||
|
r = ALIGN_UP(a, b) - a;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T ALIGN_DOWN(const T& a, const T& b) { T r; r = (a / b) * b; return r; }
|
inline const T &UPX_MAX(const T &a, const T &b) {
|
||||||
|
if (a < b)
|
||||||
|
return b;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T ALIGN_UP (const T& a, const T& b) { T r; r = ((a + b - 1) / b) * b; return r; }
|
inline const T &UPX_MIN(const T &a, const T &b) {
|
||||||
template <class T>
|
if (a < b)
|
||||||
inline T ALIGN_GAP (const T& a, const T& b) { T r; r = ALIGN_UP(a, b) - a; return r; }
|
return a;
|
||||||
|
return b;
|
||||||
template <class T>
|
}
|
||||||
inline const T& UPX_MAX(const T& a, const T& b) { if (a < b) return b; return a; }
|
|
||||||
template <class T>
|
|
||||||
inline const T& UPX_MIN(const T& a, const T& b) { if (a < b) return a; return b; }
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void mem_clear(T *object) noexcept {
|
inline void mem_clear(T *object) noexcept {
|
||||||
@@ -416,12 +448,15 @@ noinline void throwAssertFailed(const char *expr, const char *file, int line, co
|
|||||||
#undef assert
|
#undef assert
|
||||||
#if DEBUG || 0
|
#if DEBUG || 0
|
||||||
// generate a warning if assert() is used inside a "noexcept" context
|
// generate a warning if assert() is used inside a "noexcept" context
|
||||||
#define assert(e) ((void)(__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
|
#define assert(e) \
|
||||||
|
((void) (__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
|
||||||
#else
|
#else
|
||||||
// turn assertion failures into exceptions
|
// turn assertion failures into exceptions
|
||||||
#define assert(e) ((void)(__acc_cte(e) || (throwAssertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
|
#define assert(e) \
|
||||||
|
((void) (__acc_cte(e) || (throwAssertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
|
||||||
#endif
|
#endif
|
||||||
#define assert_noexcept(e) ((void)(__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), 0)))
|
#define assert_noexcept(e) \
|
||||||
|
((void) (__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), 0)))
|
||||||
#else
|
#else
|
||||||
#define assert_noexcept assert
|
#define assert_noexcept assert
|
||||||
#endif
|
#endif
|
||||||
@@ -429,11 +464,10 @@ noinline void throwAssertFailed(const char *expr, const char *file, int line, co
|
|||||||
#include "util/cxxlib.h"
|
#include "util/cxxlib.h"
|
||||||
using upx::is_same_any_v;
|
using upx::is_same_any_v;
|
||||||
using upx::noncopyable;
|
using upx::noncopyable;
|
||||||
using upx::tribool;
|
|
||||||
using upx::OptVar;
|
using upx::OptVar;
|
||||||
|
using upx::tribool;
|
||||||
#define usizeof(expr) (upx::UnsignedSizeOf<sizeof(expr)>::value)
|
#define usizeof(expr) (upx::UnsignedSizeOf<sizeof(expr)>::value)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// constants
|
// constants
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -442,7 +476,7 @@ using upx::OptVar;
|
|||||||
#define EXIT_OK 0
|
#define EXIT_OK 0
|
||||||
#define EXIT_ERROR 1
|
#define EXIT_ERROR 1
|
||||||
#define EXIT_WARN 2
|
#define EXIT_WARN 2
|
||||||
|
//
|
||||||
#define EXIT_USAGE 1
|
#define EXIT_USAGE 1
|
||||||
#define EXIT_FILE_READ 1
|
#define EXIT_FILE_READ 1
|
||||||
#define EXIT_FILE_WRITE 1
|
#define EXIT_FILE_WRITE 1
|
||||||
@@ -451,12 +485,10 @@ using upx::OptVar;
|
|||||||
#define EXIT_INIT 1
|
#define EXIT_INIT 1
|
||||||
#define EXIT_INTERNAL 1
|
#define EXIT_INTERNAL 1
|
||||||
|
|
||||||
|
|
||||||
// magic constants for patching
|
// magic constants for patching
|
||||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||||
#define UPX_MAGIC2_LE32 0xD5D0D8A1
|
#define UPX_MAGIC2_LE32 0xD5D0D8A1
|
||||||
|
|
||||||
|
|
||||||
// upx_compress() error codes
|
// upx_compress() error codes
|
||||||
#define UPX_E_OK (0)
|
#define UPX_E_OK (0)
|
||||||
#define UPX_E_ERROR (-1)
|
#define UPX_E_ERROR (-1)
|
||||||
@@ -470,7 +502,6 @@ using upx::OptVar;
|
|||||||
#define UPX_E_NOT_YET_IMPLEMENTED (-9)
|
#define UPX_E_NOT_YET_IMPLEMENTED (-9)
|
||||||
#define UPX_E_INVALID_ARGUMENT (-10)
|
#define UPX_E_INVALID_ARGUMENT (-10)
|
||||||
|
|
||||||
|
|
||||||
// Executable formats (info: big endian types are >= 128); DO NOT CHANGE
|
// Executable formats (info: big endian types are >= 128); DO NOT CHANGE
|
||||||
#define UPX_F_DOS_COM 1
|
#define UPX_F_DOS_COM 1
|
||||||
#define UPX_F_DOS_SYS 2
|
#define UPX_F_DOS_SYS 2
|
||||||
@@ -563,14 +594,12 @@ using upx::OptVar;
|
|||||||
#define M_IS_DEFLATE(x) ((x) == M_DEFLATE)
|
#define M_IS_DEFLATE(x) ((x) == M_DEFLATE)
|
||||||
#define M_IS_ZSTD(x) ((x) == M_ZSTD)
|
#define M_IS_ZSTD(x) ((x) == M_ZSTD)
|
||||||
|
|
||||||
|
|
||||||
// filters internal usage
|
// filters internal usage
|
||||||
#define FT_END (-1)
|
#define FT_END (-1)
|
||||||
#define FT_NONE (-2)
|
#define FT_NONE (-2)
|
||||||
#define FT_SKIP (-3)
|
#define FT_SKIP (-3)
|
||||||
#define FT_ULTRA_BRUTE (-4)
|
#define FT_ULTRA_BRUTE (-4)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compression - setup and callback_t
|
// compression - setup and callback_t
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -588,8 +617,7 @@ using upx::OptVar;
|
|||||||
|
|
||||||
struct upx_callback_t;
|
struct upx_callback_t;
|
||||||
typedef upx_callback_t *upx_callback_p;
|
typedef upx_callback_t *upx_callback_p;
|
||||||
typedef void (__acc_cdecl *upx_progress_func_t)
|
typedef void(__acc_cdecl *upx_progress_func_t)(upx_callback_p, unsigned, unsigned);
|
||||||
(upx_callback_p, unsigned, unsigned);
|
|
||||||
|
|
||||||
struct upx_callback_t {
|
struct upx_callback_t {
|
||||||
upx_progress_func_t nprogress;
|
upx_progress_func_t nprogress;
|
||||||
@@ -598,7 +626,6 @@ struct upx_callback_t {
|
|||||||
void reset() noexcept { mem_clear(this); }
|
void reset() noexcept { mem_clear(this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compression - config_t
|
// compression - config_t
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -651,12 +678,16 @@ struct upx_compress_config_t {
|
|||||||
zlib_compress_config_t conf_zlib;
|
zlib_compress_config_t conf_zlib;
|
||||||
zstd_compress_config_t conf_zstd;
|
zstd_compress_config_t conf_zstd;
|
||||||
|
|
||||||
void reset() noexcept { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); conf_zstd.reset(); }
|
void reset() noexcept {
|
||||||
|
conf_lzma.reset();
|
||||||
|
conf_ucl.reset();
|
||||||
|
conf_zlib.reset();
|
||||||
|
conf_zstd.reset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NULL_cconf ((upx_compress_config_t *) nullptr)
|
#define NULL_cconf ((upx_compress_config_t *) nullptr)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compression - result_t
|
// compression - result_t
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -708,11 +739,13 @@ struct upx_compress_result_t {
|
|||||||
|
|
||||||
void reset() noexcept {
|
void reset() noexcept {
|
||||||
debug.reset();
|
debug.reset();
|
||||||
result_lzma.reset(); result_ucl.reset(); result_zlib.reset(); result_zstd.reset();
|
result_lzma.reset();
|
||||||
|
result_ucl.reset();
|
||||||
|
result_zlib.reset();
|
||||||
|
result_zstd.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// globals
|
// globals
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -767,10 +800,10 @@ void show_usage();
|
|||||||
void show_version(bool one_line = false);
|
void show_version(bool one_line = false);
|
||||||
|
|
||||||
// compress/compress.cpp
|
// compress/compress.cpp
|
||||||
|
// clang-format off
|
||||||
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler = 1);
|
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler = 1);
|
||||||
unsigned upx_crc32 (const void *buf, unsigned len, unsigned crc = 0);
|
unsigned upx_crc32 (const void *buf, unsigned len, unsigned crc = 0);
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
int upx_compress ( const upx_bytep src, unsigned src_len,
|
int upx_compress ( const upx_bytep src, unsigned src_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
upx_bytep dst, unsigned* dst_len,
|
||||||
upx_callback_p cb,
|
upx_callback_p cb,
|
||||||
@@ -789,7 +822,6 @@ int upx_test_overlap ( const upx_bytep buf,
|
|||||||
const upx_compress_result_t *cresult );
|
const upx_compress_result_t *cresult );
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
||||||
#include "util/snprintf.h" // must get included first!
|
#include "util/snprintf.h" // must get included first!
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
@@ -800,5 +832,4 @@ int upx_test_overlap ( const upx_bytep buf,
|
|||||||
#include "util/raw_bytes.h"
|
#include "util/raw_bytes.h"
|
||||||
#include "util/xspan.h"
|
#include "util/xspan.h"
|
||||||
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
Reference in New Issue
Block a user