all: minor cleanups

This commit is contained in:
Markus F.X.J. Oberhumer
2023-05-14 09:36:10 +02:00
parent b3e4efbabe
commit 40653e40a4
7 changed files with 39 additions and 21 deletions
+7 -2
View File
@@ -384,8 +384,8 @@ jobs:
- { zig_target: x86_64-macos.13-none } - { zig_target: x86_64-macos.13-none }
- { zig_target: x86_64-windows-gnu } - { zig_target: x86_64-windows-gnu }
env: env:
# 2023-05-12 # 2023-05-14
ZIG_DIST_VERSION: 0.11.0-dev.3097+7f7bd206d ZIG_DIST_VERSION: 0.11.0-dev.3123+6f418c11e
# for zig-cc wrapper scripts (see below): # for zig-cc wrapper scripts (see below):
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
ZIG_FLAGS: ${{ matrix.zig_flags }} ZIG_FLAGS: ${{ matrix.zig_flags }}
@@ -459,5 +459,10 @@ jobs:
with: with:
name: ${{ env.artifact_name }} name: ${{ env.artifact_name }}
path: tmp/artifact path: tmp/artifact
- name: 'Run install tests'
if: ${{ contains(matrix.zig_target, '-linux-') }}
run: |
(cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-cmake cmake --install .)
(cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-make make install)
# vim:set ts=2 sw=2 et: # vim:set ts=2 sw=2 et:
+14 -10
View File
@@ -190,17 +190,21 @@ else()
endif() endif()
# compile a target with -O2 even in Debug build # compile a target with -O2 even in Debug build
function(upx_compile_target_debug_with_O2 t) function(upx_compile_target_debug_with_O2)
if(MSVC_FRONTEND) foreach(t ${ARGV})
# MSVC uses some Debug compile options like -RTC1 that are incompatible with -O2 if(MSVC_FRONTEND)
else() # MSVC uses some Debug compilation options like -RTC1 that are incompatible with -O2
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-O2>) else()
endif() target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-O2>)
endif()
endforeach()
endfunction() endfunction()
function(upx_sanitize_target t) function(upx_sanitize_target)
if(NOT UPX_CONFIG_DISABLE_SANITIZE) foreach(t ${ARGV})
if(MSVC_FRONTEND) if(UPX_CONFIG_DISABLE_SANITIZE)
# no-op
elseif(MSVC_FRONTEND)
# MSVC uses -GS (similar to -fstack-protector) by default # MSVC uses -GS (similar to -fstack-protector) by default
elseif(CMAKE_C_PLATFORM_ID MATCHES "^MinGW" OR MINGW OR CYGWIN) elseif(CMAKE_C_PLATFORM_ID MATCHES "^MinGW" OR MINGW OR CYGWIN)
# avoid link errors with current MinGW-w64 versions # avoid link errors with current MinGW-w64 versions
@@ -211,7 +215,7 @@ function(upx_sanitize_target t)
# default sanitizer for Release builds # default sanitizer for Release builds
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:-fstack-protector>) target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:-fstack-protector>)
endif() endif()
endif() endforeach()
endfunction() endfunction()
set(t upx_vendor_ucl) set(t upx_vendor_ucl)
+8
View File
@@ -49,6 +49,8 @@ int upx_doctest_check(int argc, char **argv) {
if (e && e[0]) { if (e && e[0]) {
if (strcmp(e, "0") == 0) { if (strcmp(e, "0") == 0) {
minimal = true; minimal = true;
} else if (strcmp(e, "1") == 0) {
minimal = false;
} else if (strcmp(e, "2") == 0) { } else if (strcmp(e, "2") == 0) {
minimal = false; minimal = false;
duration = true; duration = true;
@@ -185,6 +187,12 @@ struct CheckIntegral {
COMPILE_TIME_ASSERT(upx_is_integral_v<U>) COMPILE_TIME_ASSERT(upx_is_integral_v<U>)
} }
static void check(void) { static void check(void) {
T a = {};
const T b = {};
constexpr T c = {};
assert(a == 0);
assert(b == 0);
assert(c == 0);
checkU<T>(); checkU<T>();
checkU<typename std::add_const<T>::type>(); checkU<typename std::add_const<T>::type>();
#if !defined(__GNUC__) #if !defined(__GNUC__)
+2 -2
View File
@@ -112,7 +112,7 @@ inline constexpr bool upx_is_integral_v = upx_is_integral<T>::value;
// horrible hack for broken compiler // horrible hack for broken compiler
#define upx_fake_alignas_1 __attribute__((__aligned__(1),__packed__)) #define upx_fake_alignas_1 __attribute__((__aligned__(1),__packed__))
#define upx_fake_alignas_16 __attribute__((__aligned__(2))) // object file maximum 2 ??? #define upx_fake_alignas_16 __attribute__((__aligned__(2))) // object file maximum 2 ???
#define upx_fake_alignas__(a) upx_fake_alignas_ ## a #define upx_fake_alignas__(x) upx_fake_alignas_ ## x
#define alignas(x) upx_fake_alignas__(x) #define alignas(x) upx_fake_alignas__(x)
#endif #endif
@@ -555,7 +555,7 @@ constexpr bool string_ge(const char *a, const char *b) {
#define M_IS_ZSTD(x) ((x) == M_ZSTD) #define M_IS_ZSTD(x) ((x) == M_ZSTD)
// filters // 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)
+4 -1
View File
@@ -25,6 +25,9 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
// A MemBuffer allocates memory on the heap, and automatically
// gets destructed when leaving scope or on exceptions.
#include "../conf.h" #include "../conf.h"
#include "membuffer.h" #include "membuffer.h"
@@ -256,7 +259,7 @@ void MemBuffer::dealloc() noexcept {
// //
**************************************************************************/ **************************************************************************/
TEST_CASE("MemBuffer") { TEST_CASE("MemBuffer core") {
MemBuffer mb; MemBuffer mb;
CHECK_THROWS(mb.checkState()); CHECK_THROWS(mb.checkState());
CHECK_THROWS(mb.alloc(0x30000000 + 1)); CHECK_THROWS(mb.alloc(0x30000000 + 1));
+2 -4
View File
@@ -119,17 +119,15 @@ inline typename MemBufferBase<T>::pointer raw_index_bytes(const MemBufferBase<T>
return mbb.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index; return mbb.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index;
} }
#if 1
// some more global overloads using a checked raw_bytes() call // some more global overloads using a checked raw_bytes() call
#define XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(A, B, RType) \ #define XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(A, B, RType) \
typename std::enable_if<std::is_same<A, B>::value, RType>::type typename std::enable_if<std::is_same<A, B>::value, RType>::type
#define XSPAN_FWD_C_IS_MEMBUFFER 1
#define C MemBufferBase #define C MemBufferBase
#define XSPAN_FWD_C_IS_MEMBUFFER 1
#include "xspan_fwd.h" #include "xspan_fwd.h"
#undef C
#undef XSPAN_FWD_C_IS_MEMBUFFER #undef XSPAN_FWD_C_IS_MEMBUFFER
#undef C
#undef XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION #undef XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION
#endif
/************************************************************************* /*************************************************************************
// //
+2 -2
View File
@@ -76,10 +76,10 @@ void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes)
if very_unlikely (base == nullptr) if very_unlikely (base == nullptr)
xspan_fail_range_nullbase(); xspan_fail_range_nullbase();
ptrdiff_t off = (const charptr) p - (const charptr) base; ptrdiff_t off = (const charptr) p - (const charptr) base;
if very_unlikely (off < 0 || off > size_in_bytes) if very_unlikely (off < 0 || off > size_in_bytes || size_in_bytes > UPX_RSIZE_MAX)
xspan_fail_range_range(); xspan_fail_range_range();
xspan_stats.check_range_counter += 1; xspan_stats.check_range_counter += 1;
// fprintf(stderr, "xspan_check_range done\n"); NO_fprintf(stderr, "xspan_check_range done\n");
} }
XSPAN_NAMESPACE_END XSPAN_NAMESPACE_END