diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7cb6c5..3d948f7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,7 +286,7 @@ jobs: set s=%H%\src cat .GITREV.txt set /p GITREV=<.GITREV.txt - cl -std:c++17 -Zc:__cplusplus -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\vendor -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj + cl -std:c++17 -Zc:__cplusplus -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\vendor -I%H%\vendor\boost-pfr\include -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj - name: 'Make artifact' shell: bash run: | diff --git a/src/conf.h b/src/conf.h index e78406c0..4fe9188f 100644 --- a/src/conf.h +++ b/src/conf.h @@ -743,8 +743,6 @@ struct upx_compress_result_t // globals **************************************************************************/ -#include "util/snprintf.h" // must get included first! - #include #include #include @@ -757,7 +755,11 @@ struct upx_compress_result_t #include #define upx_std_atomic(Type) std::atomic #endif +#if WITH_BOOST_PFR +#include +#endif +#include "util/snprintf.h" // must get included first! #include "options.h" #include "except.h" #include "bele.h" @@ -775,37 +777,6 @@ unsigned membuffer_get_size(MemBuffer &mb); #include "util/xspan.h" -//#define DOCTEST_CONFIG_DISABLE 1 -#include - -#if WITH_BOOST_PFR -#include -template -__acc_noinline std::string pfr_str(const A &a) { - std::ostringstream ss; - ss << boost::pfr::io(a); - return ss.str(); -} -template -__acc_noinline std::string pfr_str(const A &a, const B &b) { - std::ostringstream ss; - ss << boost::pfr::io(a); - ss << ' '; - ss << boost::pfr::io(b); - return ss.str(); -} -template -__acc_noinline std::string pfr_str(const A &a, const B &b, const C &c) { - std::ostringstream ss; - ss << boost::pfr::io(a); - ss << ' '; - ss << boost::pfr::io(b); - ss << ' '; - ss << boost::pfr::io(c); - return ss.str(); -} -#endif // WITH_BOOST_PFR - // util/dt_check.cpp void upx_compiler_sanity_check(); int upx_doctest_check(); @@ -865,6 +836,57 @@ int upx_test_overlap ( const upx_bytep buf, int method, const upx_compress_result_t *cresult ); + +/************************************************************************* +// +**************************************************************************/ + +//#define DOCTEST_CONFIG_DISABLE 1 +#include + +#if WITH_BOOST_PFR +#include +template +__acc_noinline std::string pfr_string(const A &a) { + std::ostringstream ss; + ss << boost::pfr::io(a); + return ss.str(); +} +template +__acc_noinline std::string pfr_string(const A &a, const B &b) { + std::ostringstream ss; + ss << boost::pfr::io(a); + ss << ' '; + ss << boost::pfr::io(b); + return ss.str(); +} +template +__acc_noinline std::string pfr_string(const A &a, const B &b, const C &c) { + std::ostringstream ss; + ss << boost::pfr::io(a); + ss << ' '; + ss << boost::pfr::io(b); + ss << ' '; + ss << boost::pfr::io(c); + return ss.str(); +} +template +__acc_noinline std::string pfr_string(const A &a, const B &b, const C &c, const D &d) { + std::ostringstream ss; + ss << boost::pfr::io(a); + ss << ' '; + ss << boost::pfr::io(b); + ss << ' '; + ss << boost::pfr::io(c); + ss << ' '; + ss << boost::pfr::io(d); + return ss.str(); +} +// note: this MUST be a macro and not a function because of implicit temporary variable +#define pfr_str(a,...) (pfr_string(a, ##__VA_ARGS__).c_str()) +#endif // WITH_BOOST_PFR + + /************************************************************************* // raw_bytes() - get underlying memory from checked buffers/pointers. // This is overloaded by various utility classes like BoundedPtr, diff --git a/src/util/dt_check.cpp b/src/util/dt_check.cpp index ac31bb92..1fefbb9c 100644 --- a/src/util/dt_check.cpp +++ b/src/util/dt_check.cpp @@ -456,13 +456,13 @@ TEST_CASE("libc snprintf") { #if WITH_BOOST_PFR TEST_CASE("Boost.PFR") { int i = -1; - CHECK_EQ(strcmp(pfr_str(i).c_str(), "-1"), 0); + CHECK_EQ(strcmp(pfr_str(i), "-1"), 0); BE32 b32; b32 = 1; LE32 l32; l32 = 2; - CHECK_EQ(strcmp(pfr_str(b32).c_str(), "1"), 0); - CHECK_EQ(strcmp(pfr_str(l32).c_str(), "2"), 0); + CHECK_EQ(strcmp(pfr_str(b32), "1"), 0); + CHECK_EQ(strcmp(pfr_str(l32), "2"), 0); struct Foo { BE16 b16; BE32 b32; @@ -478,7 +478,7 @@ TEST_CASE("Boost.PFR") { foo.l16 = 4; foo.l32 = 5; foo.l64 = 6; - CHECK_EQ(strcmp(pfr_str("foo", "=", foo).c_str(), "foo = {1, 2, 3, 4, 5, 6}"), 0); + CHECK_EQ(strcmp(pfr_str("foo", "=", foo), "foo = {1, 2, 3, 4, 5, 6}"), 0); } #endif // WITH_BOOST_PFR