mirror of https://github.com/upx/upx.git
src: rename ptr_reinterpret_cast to ptr_static_cast; misc cleanups
This commit is contained in:
parent
3326c86e91
commit
51a6a5cca5
|
@ -456,7 +456,7 @@ if(Threads_FOUND)
|
|||
OUTPUT_VARIABLE output)
|
||||
if(NOT result)
|
||||
# failed; under MinGW be sure to use the posix-threads and NOT the win32-threads version
|
||||
#message(STATUS "${output}") # debug output from try_compile
|
||||
#message(STATUS "Threads FAILED: ${output}") # debug output from try_compile
|
||||
set(Threads_FOUND OFF)
|
||||
break()
|
||||
endif()
|
||||
|
|
4
Makefile
4
Makefile
|
@ -66,7 +66,9 @@ endif
|
|||
CTEST = ctest
|
||||
test:: $(.DEFAULT_GOAL) PHONY
|
||||
cd $(.DEFAULT_GOAL) && $(CTEST)
|
||||
ifneq ($(wildcard /usr/bin/env),) # needs Unix utils like bash, perl, sed, xargs, etc.
|
||||
ifneq ($(wildcard /usr/bin/env),) # need Unix utils like bash, perl, sed, xargs, etc.
|
||||
ifneq ($(wildcard ./misc/scripts/.),)
|
||||
check-whitespace clang-format run-testsuite run-testsuite-debug run-testsuite-release: src/Makefile PHONY
|
||||
$(MAKE) -C src $@
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -257,7 +257,7 @@ def main():
|
|||
parser.add_argument(
|
||||
"-allow-enabling-alpha-checkers",
|
||||
action="store_true",
|
||||
help="allow alpha checkers from " "clang-analyzer.",
|
||||
help="allow alpha checkers from clang-analyzer.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-clang-tidy-binary", metavar="PATH", help="path to clang-tidy binary"
|
||||
|
@ -270,7 +270,7 @@ def main():
|
|||
parser.add_argument(
|
||||
"-checks",
|
||||
default=None,
|
||||
help="checks filter, when not specified, use clang-tidy " "default",
|
||||
help="checks filter, when not specified, use clang-tidy default",
|
||||
)
|
||||
config_group = parser.add_mutually_exclusive_group()
|
||||
config_group.add_argument(
|
||||
|
@ -303,7 +303,7 @@ def main():
|
|||
parser.add_argument(
|
||||
"-line-filter",
|
||||
default=None,
|
||||
help="List of files with line ranges to filter the" "warnings.",
|
||||
help="List of files with line ranges to filter the warnings.",
|
||||
)
|
||||
if yaml:
|
||||
parser.add_argument(
|
||||
|
@ -335,12 +335,12 @@ def main():
|
|||
)
|
||||
parser.add_argument("-fix", action="store_true", help="apply fix-its")
|
||||
parser.add_argument(
|
||||
"-format", action="store_true", help="Reformat code " "after applying fixes"
|
||||
"-format", action="store_true", help="Reformat code after applying fixes"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-style",
|
||||
default="file",
|
||||
help="The style of reformat " "code after applying fixes",
|
||||
help="The style of reformat code after applying fixes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-use-color",
|
||||
|
@ -359,14 +359,14 @@ def main():
|
|||
dest="extra_arg",
|
||||
action="append",
|
||||
default=[],
|
||||
help="Additional argument to append to the compiler " "command line.",
|
||||
help="Additional argument to append to the compiler command line.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-extra-arg-before",
|
||||
dest="extra_arg_before",
|
||||
action="append",
|
||||
default=[],
|
||||
help="Additional argument to prepend to the compiler " "command line.",
|
||||
help="Additional argument to prepend to the compiler command line.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-quiet", action="store_true", help="Run clang-tidy in quiet mode"
|
||||
|
@ -381,7 +381,7 @@ def main():
|
|||
parser.add_argument(
|
||||
"-warnings-as-errors",
|
||||
default=None,
|
||||
help="Upgrades warnings to errors. Same format as " "'-checks'",
|
||||
help="Upgrades warnings to errors. Same format as '-checks'",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
12
src/Makefile
12
src/Makefile
|
@ -44,10 +44,10 @@ test:: $(top_srcdir)/build/release PHONY; cd $< && $(CTEST)
|
|||
|
||||
#
|
||||
# "make run-testsuite"
|
||||
# see https://github.com/upx/upx-testsuite.git
|
||||
# git clone https://github.com/upx/upx-testsuite.git
|
||||
#
|
||||
|
||||
# search for the UPX testsuite -- git clone https://github.com/upx/upx-testsuite.git
|
||||
# search for the UPX testsuite
|
||||
# you also can override upx_testsuite_SRCDIR
|
||||
ifndef upx_testsuite_SRCDIR
|
||||
# search standard locations below $(top_srcdir)
|
||||
|
@ -62,15 +62,16 @@ endif
|
|||
|
||||
# run the UPX testsuite
|
||||
# The expected (old) checksums are in $(top_srcdir)/misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
|
||||
# The actual (new) checksums are in ./tmp-upx-testsuite/testsuite_1/.sha256sums.recreate
|
||||
# The actual (new) checksums are in ./tmp-upx-testsuite-*/testsuite_1/.sha256sums.recreate
|
||||
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
||||
ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),)
|
||||
run-testsuite: run-testsuite-release
|
||||
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
||||
run-testsuite-%: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite
|
||||
run-testsuite-debug: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-debug
|
||||
run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx
|
||||
run-testsuite-debug: $(top_srcdir)/build/debug PHONY
|
||||
time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh
|
||||
run-testsuite-release: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-release
|
||||
run-testsuite-release: export upx_exe := $(top_srcdir)/build/release/upx
|
||||
run-testsuite-release: $(top_srcdir)/build/release PHONY
|
||||
time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh
|
||||
|
@ -81,7 +82,7 @@ endif
|
|||
# "make check-whitespace"
|
||||
#
|
||||
|
||||
ifneq ($(wildcard /usr/bin/env),) # needs Unix utils like bash, perl, sed, xargs, etc.
|
||||
ifneq ($(wildcard /usr/bin/env),) # need Unix utils like bash, perl, sed, xargs, etc.
|
||||
CHECK_WHITESPACE = bash $(top_srcdir)/misc/scripts/check_whitespace.sh $(top_srcdir)
|
||||
ifneq ($(wildcard $(top_srcdir)/.git/.),)
|
||||
CHECK_WHITESPACE = bash $(top_srcdir)/misc/scripts/check_whitespace_git.sh $(top_srcdir)
|
||||
|
@ -100,6 +101,7 @@ 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_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
||||
CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*))
|
||||
CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*))
|
||||
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
|
||||
clang-format: $(CLANG_FORMAT_FILES) PHONY
|
||||
@echo "running upx-clang-format"
|
||||
|
|
|
@ -101,44 +101,44 @@ ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_le("abc", "abz"))
|
|||
// util
|
||||
**************************************************************************/
|
||||
|
||||
TEST_CASE("ptr_reinterpret_cast") {
|
||||
TEST_CASE("ptr_static_cast") {
|
||||
// check that we don't trigger any -Wcast-align warnings
|
||||
using upx::ptr_reinterpret_cast;
|
||||
using upx::ptr_static_cast;
|
||||
void *vp = nullptr;
|
||||
byte *bp = nullptr;
|
||||
int *ip = nullptr;
|
||||
double *dp = nullptr;
|
||||
|
||||
assert((vp == ptr_reinterpret_cast<void *>(vp)));
|
||||
assert((vp == ptr_reinterpret_cast<void *>(bp)));
|
||||
assert((vp == ptr_reinterpret_cast<void *>(ip)));
|
||||
assert((vp == ptr_reinterpret_cast<void *>(dp)));
|
||||
assert((vp == ptr_static_cast<void *>(vp)));
|
||||
assert((vp == ptr_static_cast<void *>(bp)));
|
||||
assert((vp == ptr_static_cast<void *>(ip)));
|
||||
assert((vp == ptr_static_cast<void *>(dp)));
|
||||
|
||||
assert((bp == ptr_reinterpret_cast<byte *>(vp)));
|
||||
assert((bp == ptr_reinterpret_cast<byte *>(bp)));
|
||||
assert((bp == ptr_reinterpret_cast<byte *>(ip)));
|
||||
assert((bp == ptr_reinterpret_cast<byte *>(dp)));
|
||||
assert((bp == ptr_static_cast<byte *>(vp)));
|
||||
assert((bp == ptr_static_cast<byte *>(bp)));
|
||||
assert((bp == ptr_static_cast<byte *>(ip)));
|
||||
assert((bp == ptr_static_cast<byte *>(dp)));
|
||||
|
||||
assert((ip == ptr_reinterpret_cast<int *>(vp)));
|
||||
assert((ip == ptr_reinterpret_cast<int *>(bp)));
|
||||
assert((ip == ptr_reinterpret_cast<int *>(ip)));
|
||||
assert((ip == ptr_reinterpret_cast<int *>(dp)));
|
||||
assert((ip == ptr_static_cast<int *>(vp)));
|
||||
assert((ip == ptr_static_cast<int *>(bp)));
|
||||
assert((ip == ptr_static_cast<int *>(ip)));
|
||||
assert((ip == ptr_static_cast<int *>(dp)));
|
||||
|
||||
assert((dp == ptr_reinterpret_cast<double *>(vp)));
|
||||
assert((dp == ptr_reinterpret_cast<double *>(bp)));
|
||||
assert((dp == ptr_reinterpret_cast<double *>(ip)));
|
||||
assert((dp == ptr_reinterpret_cast<double *>(dp)));
|
||||
assert((dp == ptr_static_cast<double *>(vp)));
|
||||
assert((dp == ptr_static_cast<double *>(bp)));
|
||||
assert((dp == ptr_static_cast<double *>(ip)));
|
||||
assert((dp == ptr_static_cast<double *>(dp)));
|
||||
|
||||
const byte *bc = nullptr;
|
||||
const int *ic = nullptr;
|
||||
assert((bc == ptr_reinterpret_cast<byte *>(bp)));
|
||||
assert((bc == ptr_reinterpret_cast<const byte *>(bc)));
|
||||
assert((bc == ptr_reinterpret_cast<byte *>(ip)));
|
||||
assert((bc == ptr_reinterpret_cast<const byte *>(ic)));
|
||||
assert((ic == ptr_reinterpret_cast<int *>(bp)));
|
||||
assert((ic == ptr_reinterpret_cast<const int *>(bc)));
|
||||
assert((ic == ptr_reinterpret_cast<int *>(ip)));
|
||||
assert((ic == ptr_reinterpret_cast<const int *>(ic)));
|
||||
assert((bc == ptr_static_cast<byte *>(bp)));
|
||||
assert((bc == ptr_static_cast<const byte *>(bc)));
|
||||
assert((bc == ptr_static_cast<byte *>(ip)));
|
||||
assert((bc == ptr_static_cast<const byte *>(ic)));
|
||||
assert((ic == ptr_static_cast<int *>(bp)));
|
||||
assert((ic == ptr_static_cast<const int *>(bc)));
|
||||
assert((ic == ptr_static_cast<int *>(ip)));
|
||||
assert((ic == ptr_static_cast<const int *>(ic)));
|
||||
}
|
||||
|
||||
TEST_CASE("noncopyable") {
|
||||
|
|
|
@ -63,18 +63,18 @@ struct UnsignedSizeOf {
|
|||
static constexpr unsigned value = unsigned(Size);
|
||||
};
|
||||
|
||||
// a reinterpret_cast that does not trigger -Wcast-align warnings
|
||||
// a static_cast that does not trigger -Wcast-align warnings
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(From *ptr) noexcept {
|
||||
forceinline Result ptr_static_cast(From *ptr) noexcept {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
|
||||
return reinterpret_cast<Result>(reinterpret_cast<void *>(ptr));
|
||||
return static_cast<Result>(static_cast<void *>(ptr));
|
||||
}
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(const From *ptr) noexcept {
|
||||
forceinline Result ptr_static_cast(const From *ptr) noexcept {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
|
||||
return reinterpret_cast<Result>(reinterpret_cast<const void *>(ptr));
|
||||
return static_cast<Result>(static_cast<const void *>(ptr));
|
||||
}
|
||||
|
||||
class noncopyable {
|
||||
|
|
|
@ -159,7 +159,7 @@ inline R *xspan_make_helper__(MemBuffer &mb) noexcept {
|
|||
#define XSPAN_S_VAR(type, var, first, ...) type *var = XSPAN_S_MAKE(type, (first))
|
||||
|
||||
// cast to a different type (creates a new value)
|
||||
#define XSPAN_TYPE_CAST(type, x) (upx::ptr_reinterpret_cast<type *>(x))
|
||||
#define XSPAN_TYPE_CAST(type, x) (upx::ptr_static_cast<type *>(x))
|
||||
// poison a pointer: point to a non-null invalid address
|
||||
#define XSPAN_INVALIDATE(x) ptr_invalidate_and_poison(x)
|
||||
|
||||
|
|
|
@ -284,8 +284,8 @@ public:
|
|||
inline CSelf<U> type_cast() const {
|
||||
typedef CSelf<U> R;
|
||||
typedef typename R::pointer rpointer;
|
||||
return R(R::Unchecked, upx::ptr_reinterpret_cast<rpointer>(ptr), size_in_bytes,
|
||||
upx::ptr_reinterpret_cast<rpointer>(base));
|
||||
return R(R::Unchecked, upx::ptr_static_cast<rpointer>(ptr), size_in_bytes,
|
||||
upx::ptr_static_cast<rpointer>(base));
|
||||
}
|
||||
|
||||
bool operator==(pointer other) const noexcept { return ptr == other; }
|
||||
|
|
|
@ -127,7 +127,7 @@ public:
|
|||
inline CSelf<U> type_cast() const {
|
||||
typedef CSelf<U> R;
|
||||
typedef typename R::pointer rpointer;
|
||||
return R(upx::ptr_reinterpret_cast<rpointer>(ptr));
|
||||
return R(upx::ptr_static_cast<rpointer>(ptr));
|
||||
}
|
||||
|
||||
// comparison
|
||||
|
|
Loading…
Reference in New Issue