From 54f4cd7cd1a27cc3a2522f920d2baf9f986ffe04 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 9 Oct 2024 21:58:59 +0200 Subject: [PATCH 1/3] sys/matstat: fix compilation with newlib newlib (nano) does not support 64 bit types (neither in stdio nor with corresponding `PRI*64` macros). With GCC 13.2.1 (as shipped in Ubuntu 24.04.1 LTS), this triggers the following compilation error (even with `ENABLE_DEBUG == 0`): sys/matstat/matstat.c:57:21: error: expected ')' before 'PRIu64' 57 | DEBUG("Var: (%" PRIu64 " / (%" PRId32 " - 1)) = %" PRIu64 "\n", | ^~~~~~ This fixes the issue by falling back to printing 32 bit values when the `PRIu64` macro is not defined. A `!trunc` is appended when the 64 bit exceeds the range of [0:UINT32_MAX]. --- sys/matstat/matstat.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/matstat/matstat.c b/sys/matstat/matstat.c index a39aee19cc..55f344b778 100644 --- a/sys/matstat/matstat.c +++ b/sys/matstat/matstat.c @@ -53,8 +53,15 @@ uint64_t matstat_variance(const matstat_state_t *state) return 0; } uint64_t variance = state->sum_sq / (state->count - 1); +#ifdef PRIu64 DEBUG("Var: (%" PRIu64 " / (%" PRId32 " - 1)) = %" PRIu64 "\n", state->sum_sq, state->count, variance); +#else + DEBUG("Var: (%" PRIu32 "%s / (%" PRId32 " - 1)) = %" PRIu32 "%s\n", + (uint32_t)state->sum_sq, (state->sum_sq > UINT32_MAX) ? "!trunc " : "", + state->count, + (uint32_t)variance, (variance > UINT32_MAX) ? "!trunc " : ""); +#endif return variance; } From 18036a8326bea6c02576c08511e04509109e3325 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 9 Oct 2024 22:22:16 +0200 Subject: [PATCH 2/3] pkg/tinycbor: fix compilation with newlib and GCC 13.2.1 newlib (nano) is missing 64 bit support in stdio and inttypes.h. This works around the issue. --- ...x-compilation-with-newlib-and-GCC-13.2..patch | Bin 0 -> 3161 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 pkg/tinycbor/patches/0001-fix-pretty-fix-compilation-with-newlib-and-GCC-13.2..patch diff --git a/pkg/tinycbor/patches/0001-fix-pretty-fix-compilation-with-newlib-and-GCC-13.2..patch b/pkg/tinycbor/patches/0001-fix-pretty-fix-compilation-with-newlib-and-GCC-13.2..patch new file mode 100644 index 0000000000000000000000000000000000000000..03f82a669178c65f7a3f755ceec592e247893f4e GIT binary patch literal 3161 zcmd5;ZBOGy5dQ98F}ULDB(|{~Cn4eJafIWFbm&fywkK6py0O>Emc)*B*93Iszjwxt zi38!_ z4I%}lW04gABE^lCT)8tBMl+#|RVHr~Fq!2DuV);ARL)()aU27bj1HnnCQJL=2>ynk z3$2$f)bP=TIfrP*(kTTZ=-~c}OY%lpt%i*fF`sjKx15Gy#3D(+ai(Z6J9xI=g;WiU7G_zdWh5oOkX+U*REXO6x#C8P?)Om7_oHV5}Q! zgi4L>WcVKGzj*`JmL%*Q7h4ua*H!3w$BuhiV&L~ovav4yKqjYHQX5|%fPBDU)a59? z!_&`K=zk`;D(XJvQ%w6UhcsVIxP-636gWOO@O4`knqcV}!-J)462OyJz{I5B;Zi^k zesSDX1__?QS)<5d-2@6ot3^?QZ}oM0M(e7SLUzk#GS619VD~U%%Oy_<>wBpsh#f(5 z{!@PcMfv}kWHNepqUj5Uvx;K+B$f2JiT~bRg4dthKhVM~9vegwVaKz3&u+1hfRnLy9c`O<*_mySZ zw7m_q6%w(C7#^Tv!(`5;srOithYLRB~ElVRl#&*qPbRXR&x#FrYh~*@Ya;d2Ged393l%>=! zN~z;}_G@<=+*ea8me5prg2vX&jI(@#jT#B4wus~n^2l&1Ux>}S;TWl|l-u?)VaTjR z*_C*4N3ue0OpXd?JArTeA+$Q7XZ!uvJ2-U{PDnP$zk2W+8F%Kou+Jaw}|qf|y& ziVUnr*)K&bEDQuTYKlkEVk^<&jzptzrh-jubB^#~Ji_v)Oe9RqbTE z`wCAs`UG#mqeJDG<#8$!kCqnIQ?K$zwtd!cDH2s6)~%F6!V{4S&FA-!X6WyeU_5J& zyDWB1I6M6`KKn4dxO|WIi;v^$(G{4}%KDn2Pg4DurX3T)1V^Bob){gHlrs;Gkw$>S IrRy2SKQW?gtpET3 literal 0 HcmV?d00001 From 8c9105c60ca8894f21b90baf34ce9d7464732b86 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 9 Oct 2024 22:32:43 +0200 Subject: [PATCH 3/3] tests/unittests: fix compilation with newlib and GCC 13.2.1 newlib (nano) is missing 64 bit support in stdio and inttypes.h. This works around the issue. --- tests/unittests/tests-div/tests-div.c | 17 +++++++++++++++++ tests/unittests/tests-frac/tests-frac.c | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/unittests/tests-div/tests-div.c b/tests/unittests/tests-div/tests-div.c index 699de4874a..30e4e908ed 100644 --- a/tests/unittests/tests-div/tests-div.c +++ b/tests/unittests/tests-div/tests-div.c @@ -7,6 +7,7 @@ */ #include +#include #include "embUnit.h" #include "tests-div.h" @@ -78,7 +79,13 @@ static void test_div_u64_by_15625(void) } for (unsigned i = 0; i < N_U64_VALS; i++) { +#ifdef PRIu64 DEBUG("Dividing %12"PRIu64" by 15625...\n", u64_test_values[i]); +#else + DEBUG("Dividing %12"PRIu32"%s by 15625...\n", (uint32_t)u64_test_values[i], + ((uint32_t)u64_test_values[i] != u64_test_values[i]) ? "!trunc" : ""); +#endif + TEST_ASSERT_EQUAL_INT( (uint64_t)u64_test_values[i] / 15625, div_u64_by_15625(u64_test_values[i])); @@ -105,7 +112,12 @@ static void test_div_u64_by_1000000(void) } for (unsigned i = 0; i < N_U64_VALS; i++) { +#ifdef PRIu64 DEBUG("Dividing %"PRIu64" by 1000000...\n", u64_test_values[i]); +#else + DEBUG("Dividing %"PRIu32"%s by 1000000...\n", (uint32_t)u64_test_values[i], + ((uint32_t)u64_test_values[i] != u64_test_values[i]) ? "!trunc" : ""); +#endif TEST_ASSERT_EQUAL_INT( u64_test_values[i] / 1000000lu, div_u64_by_1000000(u64_test_values[i])); @@ -122,7 +134,12 @@ static void test_div_u64_by_15625div512(void) } for (unsigned i = 0; i < N_U64_VALS; i++) { +#ifdef PRIu64 DEBUG("Dividing %"PRIu64" by (15625/512)...\n", u64_test_values[i]); +#else + DEBUG("Dividing %"PRIu32"%s by (15625/512)...\n", (uint32_t)u64_test_values[i], + ((uint32_t)u64_test_values[i] != u64_test_values[i]) ? "!trunc" : ""); +#endif TEST_ASSERT_EQUAL_INT( u64_15625_512_expected_values[i], div_u64_by_15625div512(u64_test_values[i])); diff --git a/tests/unittests/tests-frac/tests-frac.c b/tests/unittests/tests-frac/tests-frac.c index 7236ac61e4..df362b1726 100644 --- a/tests/unittests/tests-frac/tests-frac.c +++ b/tests/unittests/tests-frac/tests-frac.c @@ -6,13 +6,12 @@ * directory for more details. */ +#include #include #include "embUnit.h" #include "tests-frac.h" -#include "kernel_defines.h" #include "frac.h" -#include "div.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -120,11 +119,21 @@ static void test_frac_scale32(void) uint32_t actual = frac_scale(&frac, u32_test_values[i]); if ((uint32_t)expected != actual) { int32_t diff = actual - expected; +#ifdef PRIu64 DEBUG("%" PRIu32 " * (%" PRIu32 " / %" PRIu32 ")" " tmp %" PRIu64 " expect %" PRIu32 ", actual %" PRIu32 ", diff = %" PRId32 " shift=%u\n", u32_test_values[i], num, den, tmp, (uint32_t)expected, actual, diff, frac.shift); +#else + DEBUG("%" PRIu32 " * (%" PRIu32 " / %" PRIu32 ")" + " tmp %" PRIu32"%s expect %" PRIu32 ", actual %" PRIu32 + ", diff = %" PRId32 " shift=%u\n", + u32_test_values[i], num, den, + (uint32_t)tmp, ((uint32_t)tmp != tmp) ? "!trunc" : "", + (uint32_t)expected, + actual, diff, frac.shift); +#endif /* The frac algorithm sacrifices accuracy for speed, * some large numbers will be incorrectly rounded,