src: minor cleanups
This commit is contained in:
@@ -12,8 +12,8 @@ env:
|
|||||||
CMAKE_REQUIRED_QUIET: OFF
|
CMAKE_REQUIRED_QUIET: OFF
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
UPX_CMAKE_BUILD_FLAGS: --verbose
|
UPX_CMAKE_BUILD_FLAGS: --verbose
|
||||||
# 2023-08-15
|
# 2023-08-20
|
||||||
ZIG_DIST_VERSION: 0.12.0-dev.89+913511557
|
ZIG_DIST_VERSION: 0.12.0-dev.146+020105d0d
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
job-rebuild-and-verify-stubs:
|
job-rebuild-and-verify-stubs:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ on:
|
|||||||
env:
|
env:
|
||||||
CMAKE_REQUIRED_QUIET: OFF
|
CMAKE_REQUIRED_QUIET: OFF
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
UPX_TESTSUITE_LEVEL: 2
|
UPX_TESTSUITE_LEVEL: 4
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
job-alpine-cmake: # uses cmake + make
|
job-alpine-cmake: # uses cmake + make
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ on:
|
|||||||
env:
|
env:
|
||||||
CMAKE_REQUIRED_QUIET: OFF
|
CMAKE_REQUIRED_QUIET: OFF
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
# 2023-08-15
|
# 2023-08-20
|
||||||
ZIG_DIST_VERSION: 0.12.0-dev.89+913511557
|
ZIG_DIST_VERSION: 0.12.0-dev.146+020105d0d
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
job-linux-zigcc: # uses cmake + make
|
job-linux-zigcc: # uses cmake + make
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ jobs:
|
|||||||
export upx_exe_runner="${{ matrix.qemu }}"
|
export upx_exe_runner="${{ matrix.qemu }}"
|
||||||
env -C build/xtarget/clang-static/$release "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
env -C build/xtarget/clang-static/$release "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
- name: 'Run testsuite clang-static - Valgrind'
|
- name: 'Run testsuite clang-static - Valgrind'
|
||||||
if: ${{ true }} # very slow (takes about 30 minutes on current GitHub CI)
|
if: ${{ true }} # very slow
|
||||||
run: |
|
run: |
|
||||||
export upx_exe_runner="valgrind --error-exitcode=1 --quiet"
|
export upx_exe_runner="valgrind --error-exitcode=1 --quiet"
|
||||||
|
# on current GitHub CI, takes about 30 minutes for release and 80 mins for debug
|
||||||
|
# reduce time for debug builds
|
||||||
|
test $release = debug && export UPX_TESTSUITE_LEVEL=4
|
||||||
env -C build/xtarget/clang-static/$release "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
env -C build/xtarget/clang-static/$release "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ build/xtarget/$(UPX_XTARGET)/release: PHONY; $(call run_config_and_build,$@,Rele
|
|||||||
build/xtarget/$(UPX_XTARGET)/%: export CC
|
build/xtarget/$(UPX_XTARGET)/%: export CC
|
||||||
build/xtarget/$(UPX_XTARGET)/%: export CXX
|
build/xtarget/$(UPX_XTARGET)/%: export CXX
|
||||||
# shortcuts
|
# shortcuts
|
||||||
|
xtarget/all: xtarget/debug xtarget/release
|
||||||
xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
|
xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
|
||||||
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
||||||
# set new default
|
# set new default
|
||||||
|
|||||||
@@ -114,6 +114,14 @@ struct TestTriBool {
|
|||||||
static_assert(std::is_nothrow_destructible<T>::value);
|
static_assert(std::is_nothrow_destructible<T>::value);
|
||||||
static_assert(std::is_standard_layout<T>::value);
|
static_assert(std::is_standard_layout<T>::value);
|
||||||
static_assert(std::is_trivially_copyable<T>::value);
|
static_assert(std::is_trivially_copyable<T>::value);
|
||||||
|
static_assert(sizeof(typename T::value_type) == sizeof(typename T::underlying_type));
|
||||||
|
static_assert(alignof(typename T::value_type) == alignof(typename T::underlying_type));
|
||||||
|
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
|
||||||
|
// broken compiler
|
||||||
|
#else
|
||||||
|
static_assert(sizeof(T) == sizeof(typename T::underlying_type));
|
||||||
|
static_assert(alignof(T) == alignof(typename T::underlying_type));
|
||||||
|
#endif
|
||||||
static_assert(T(false) == T::False);
|
static_assert(T(false) == T::False);
|
||||||
static_assert(T(true) == T::True);
|
static_assert(T(true) == T::True);
|
||||||
static_assert(T(T::False) == T::False);
|
static_assert(T(T::False) == T::False);
|
||||||
@@ -123,6 +131,7 @@ struct TestTriBool {
|
|||||||
static_assert(array[0].isStrictFalse());
|
static_assert(array[0].isStrictFalse());
|
||||||
static_assert(array[1].isStrictTrue());
|
static_assert(array[1].isStrictTrue());
|
||||||
static_assert(array[2].isThird());
|
static_assert(array[2].isThird());
|
||||||
|
static_assert(sizeof(array) == 3 * sizeof(T));
|
||||||
T a;
|
T a;
|
||||||
CHECK(!a);
|
CHECK(!a);
|
||||||
CHECK(a.isStrictFalse());
|
CHECK(a.isStrictFalse());
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
|
|||||||
cresult->debug.c_len = 0;
|
cresult->debug.c_len = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const unsigned orig_dst_len = *dst_len;
|
||||||
if (__acc_cte(false)) {
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
@@ -118,6 +119,7 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
|
|||||||
// debugging aid
|
// debugging aid
|
||||||
cresult->debug.c_len = *dst_len;
|
cresult->debug.c_len = *dst_len;
|
||||||
#endif
|
#endif
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +137,7 @@ int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigne
|
|||||||
if (cresult && cresult->debug.method == 0)
|
if (cresult && cresult->debug.method == 0)
|
||||||
cresult = nullptr;
|
cresult = nullptr;
|
||||||
|
|
||||||
|
const unsigned orig_dst_len = *dst_len;
|
||||||
if (__acc_cte(false)) {
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
@@ -161,6 +164,7 @@ int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigne
|
|||||||
throwInternalError("unknown decompression method");
|
throwInternalError("unknown decompression method");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +184,7 @@ int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off
|
|||||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||||
assert((int) overlap_overhead > 0);
|
assert((int) overlap_overhead > 0);
|
||||||
|
|
||||||
|
const unsigned orig_dst_len = *dst_len;
|
||||||
if (__acc_cte(false)) {
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
@@ -202,6 +207,7 @@ int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off
|
|||||||
throwInternalError("unknown decompression method");
|
throwInternalError("unknown decompression method");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -66,9 +66,10 @@ FileBase::~FileBase() may_throw {
|
|||||||
fprintf(stderr,"%s: %s\n", _name, __PRETTY_FUNCTION__);
|
fprintf(stderr,"%s: %s\n", _name, __PRETTY_FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FIXME: we should use close() during exception unwinding but
|
if (std::uncaught_exceptions() == 0)
|
||||||
// closex() otherwise
|
closex(); // may_throw
|
||||||
closex();
|
else
|
||||||
|
close_noexcept(); // currently in exception unwinding, use noexcept variant
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileBase::do_sopen() {
|
bool FileBase::do_sopen() {
|
||||||
@@ -93,7 +94,7 @@ bool FileBase::do_sopen() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileBase::close() noexcept {
|
bool FileBase::close_noexcept() noexcept {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
|
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
|
||||||
if (::close(_fd) == -1)
|
if (::close(_fd) == -1)
|
||||||
@@ -108,7 +109,7 @@ bool FileBase::close() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileBase::closex() may_throw {
|
void FileBase::closex() may_throw {
|
||||||
if (!close())
|
if (!close_noexcept())
|
||||||
throwIOException("close failed", errno);
|
throwIOException("close failed", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ upx_off_t FileBase::st_size() const { return _length; }
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void InputFile::sopen(const char *name, int flags, int shflags) {
|
void InputFile::sopen(const char *name, int flags, int shflags) {
|
||||||
close();
|
closex();
|
||||||
_name = name;
|
_name = name;
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_shflags = shflags;
|
_shflags = shflags;
|
||||||
@@ -206,7 +207,7 @@ upx_off_t InputFile::st_size_orig() const { return _length_orig; }
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
||||||
close();
|
closex();
|
||||||
_name = name;
|
_name = name;
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_shflags = shflags;
|
_shflags = shflags;
|
||||||
@@ -228,7 +229,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OutputFile::openStdout(int flags, bool force) {
|
bool OutputFile::openStdout(int flags, bool force) {
|
||||||
close();
|
closex();
|
||||||
int fd = STDOUT_FILENO;
|
int fd = STDOUT_FILENO;
|
||||||
if (!force && acc_isatty(fd))
|
if (!force && acc_isatty(fd))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+4
-4
@@ -37,11 +37,11 @@ protected:
|
|||||||
virtual ~FileBase() may_throw;
|
virtual ~FileBase() may_throw;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool close() noexcept;
|
bool close_noexcept() noexcept;
|
||||||
void closex() may_throw;
|
void closex() may_throw;
|
||||||
bool isOpen() const { return _fd >= 0; }
|
bool isOpen() const noexcept { return _fd >= 0; }
|
||||||
int getFd() const { return _fd; }
|
int getFd() const noexcept { return _fd; }
|
||||||
const char *getName() const { return _name; }
|
const char *getName() const noexcept { return _name; }
|
||||||
|
|
||||||
virtual upx_off_t seek(upx_off_t off, int whence);
|
virtual upx_off_t seek(upx_off_t off, int whence);
|
||||||
upx_off_t tell() const;
|
upx_off_t tell() const;
|
||||||
|
|||||||
@@ -205,6 +205,10 @@ void MemBuffer::dealloc() noexcept {
|
|||||||
debug_set(debug.last_return_address_dealloc, upx_return_address());
|
debug_set(debug.last_return_address_dealloc, upx_return_address());
|
||||||
#if DEBUG || 1
|
#if DEBUG || 1
|
||||||
// info: calling checkState() here violates "noexcept", so we need a try block
|
// info: calling checkState() here violates "noexcept", so we need a try block
|
||||||
|
bool shall_check = true;
|
||||||
|
// bool shall_check = (std::uncaught_exceptions() == 0); // only if not unwinding
|
||||||
|
// TODO later: add a priority() method to class Throwable
|
||||||
|
if (shall_check) {
|
||||||
try {
|
try {
|
||||||
checkState();
|
checkState();
|
||||||
} catch (const Throwable &e) {
|
} catch (const Throwable &e) {
|
||||||
@@ -213,6 +217,7 @@ void MemBuffer::dealloc() noexcept {
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::terminate();
|
std::terminate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
stats.global_dealloc_counter += 1;
|
stats.global_dealloc_counter += 1;
|
||||||
stats.global_total_active_bytes -= size_in_bytes;
|
stats.global_total_active_bytes -= size_in_bytes;
|
||||||
|
|||||||
Reference in New Issue
Block a user