From 1d238887e145ccf3a026576dfe65a77bf1019f5d Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:01:55 +0100 Subject: [PATCH 1/8] ASE: internal.hh: simplify compiler errors by avoiding macro indirections Signed-off-by: Tim Janik --- ase/internal.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ase/internal.hh b/ase/internal.hh index f3460618..f5b32f86 100644 --- a/ase/internal.hh +++ b/ase/internal.hh @@ -26,13 +26,13 @@ using Ase::String; #define ARRAY_SIZE(array) ASE_ARRAY_SIZE (array) /// Return from the current function if `expr` is unmet and issue an assertion warning. -#define assert_return(expr, ...) ASE_ASSERT_RETURN (expr, __VA_ARGS__) +#define assert_return(expr, ...) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); return __VA_ARGS__; } while (0) /// Return from the current function and issue an assertion warning. -#define assert_return_unreached(...) ASE_ASSERT_RETURN_UNREACHED (__VA_ARGS__) +#define assert_return_unreached(...) do { ::Ase::assertion_failed (""); return __VA_ARGS__; } while (0) /// Issue an assertion warning if `expr` evaluates to false. -#define assert_warn(expr) ASE_ASSERT_WARN (expr) +#define assert_warn(expr) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); } while (0) /// Issue an assertion warning if `expr` evaluates to false, check might be disabled in production. -#define assert_paranoid(expr) ASE_ASSERT_PARANOID (expr) +#define assert_paranoid(expr) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); } while (0) /// Explicitely mark unreachable code locations. #define assert_unreached() __builtin_unreachable() From 7cc334c9d707886e667a904a50d9758ad7462f8c Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:02:21 +0100 Subject: [PATCH 2/8] ASE: cxxaux.hh: simplify compiler errors by avoiding macro indirections Signed-off-by: Tim Janik --- ase/cxxaux.hh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ase/cxxaux.hh b/ase/cxxaux.hh index c4feca0d..b2fc655d 100644 --- a/ase/cxxaux.hh +++ b/ase/cxxaux.hh @@ -79,19 +79,16 @@ using VoidF = std::function; #define ASE_RETURN_UNLESS(cond, ...) do { if (ASE_UNLIKELY (!bool (cond))) return __VA_ARGS__; } while (0) /// Return from the current function if `expr` evaluates to false and issue an assertion warning. -#define ASE_ASSERT_RETURN(expr, ...) do { if (ASE_ISLIKELY (expr)) break; ::Ase::assertion_failed (#expr); return __VA_ARGS__; } while (0) +#define ASE_ASSERT_RETURN(expr, ...) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); return __VA_ARGS__; } while (0) /// Return from the current function and issue an assertion warning. #define ASE_ASSERT_RETURN_UNREACHED(...) do { ::Ase::assertion_failed (""); return __VA_ARGS__; } while (0) /// Issue an assertion warning if `expr` evaluates to false. -#define ASE_ASSERT_WARN(expr) do { if (ASE_ISLIKELY (expr)) break; ::Ase::assertion_failed (#expr); } while (0) +#define ASE_ASSERT_WARN(expr) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); } while (0) /// Like ASE_ASSERT_WARN(), enabled if expensive `expr` are allowed. -#define ASE_ASSERT_PARANOID(expr) do { if (ASE_ISLIKELY (expr)) break; ::Ase::assertion_failed (#expr); } while (0) - -/// Return from the current function if `expr` evaluates to false and issue an assertion warning. -#define ASE_ASSERT_ALWAYS(expr, ...) do { if (ASE_ISLIKELY (expr)) break; ::Ase::assertion_failed (#expr); __builtin_trap(); } while (0) +#define ASE_ASSERT_PARANOID(expr) do { if (expr) [[likely]] break; ::Ase::assertion_failed (#expr); } while (0) /// Delete copy ctor and assignment operator. #define ASE_CLASS_NON_COPYABLE(ClassName) \ From f8b375a3f68f9faee2d5be59c65f1a75cfdccd64 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:04:12 +0100 Subject: [PATCH 3/8] ASE: cxxaux: assertion_failed: simplify many call sites by using char* Signed-off-by: Tim Janik --- ase/cxxaux.cc | 8 ++++---- ase/cxxaux.hh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ase/cxxaux.cc b/ase/cxxaux.cc index 43ee1c66..3a702e73 100644 --- a/ase/cxxaux.cc +++ b/ase/cxxaux.cc @@ -23,7 +23,7 @@ string_demangle_cxx (const char *mangled_identifier) } void -assertion_failed (const std::string &msg, const char *file, int line, const char *func) +assertion_failed (const char *msg, const char *file, int line, const char *func) { if (file && line > 0 && func) fprintf (stderr, "%s:%u:%s: ", file, line, func); @@ -31,13 +31,13 @@ assertion_failed (const std::string &msg, const char *file, int line, const char fprintf (stderr, "%s:%u: ", file, line); else if (file) fprintf (stderr, "%s: ", file); - if (msg.empty()) + if (!msg || !msg[0]) fputs ("state unreachable\n", stderr); else { fputs ("assertion failed: ", stderr); - fputs (msg.c_str(), stderr); - if (msg.size() && msg[msg.size() - 1] != '\n') + fputs (msg, stderr); + if (msg[0] && msg[strlen (msg) - 1] != '\n') fputc ('\n', stderr); } fflush (stderr); diff --git a/ase/cxxaux.hh b/ase/cxxaux.hh index b2fc655d..f7709ff5 100644 --- a/ase/cxxaux.hh +++ b/ase/cxxaux.hh @@ -206,7 +206,7 @@ protected: using VirtualBaseP = std::shared_ptr; /// Issue a warning about an assertion error. -void assertion_failed (const std::string &msg = "", const char *file = __builtin_FILE(), +void assertion_failed (const char *msg = nullptr, const char *file = __builtin_FILE(), int line = __builtin_LINE(), const char *func = __builtin_FUNCTION()); /// Test string equality at compile time. From eccaaf8066d1060db33cb893b544ff10df3f6c3a Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:05:28 +0100 Subject: [PATCH 4/8] ASE: engine.cc: use ASE_ASSERT_WARN() instead of one-off special macro Signed-off-by: Tim Janik --- ase/engine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ase/engine.cc b/ase/engine.cc index ad4c2707..763c4c79 100644 --- a/ase/engine.cc +++ b/ase/engine.cc @@ -556,8 +556,8 @@ AudioEngineThread::AudioEngineThread (const VoidF &owner_wakeup, uint sample_rat AudioEngine& make_audio_engine (const VoidF &owner_wakeup, uint sample_rate, SpeakerArrangement speakerarrangement) { - ASE_ASSERT_ALWAYS (sample_rate == FIXED_SAMPLE_RATE); - ASE_ASSERT_ALWAYS (speaker_arrangement_count_channels (speakerarrangement) == FIXED_N_CHANNELS); + ASE_ASSERT_WARN (sample_rate == FIXED_SAMPLE_RATE); + ASE_ASSERT_WARN (speaker_arrangement_count_channels (speakerarrangement) == FIXED_N_CHANNELS); FastMemory::Block transport_block = ServerImpl::instancep()->telemem_allocate (sizeof (AudioTransport)); return *new AudioEngineThread (owner_wakeup, sample_rate, speakerarrangement, transport_block); } From 92daa34e5b0da79e739bc91a121a9ec2e7d8ede1 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:05:47 +0100 Subject: [PATCH 5/8] ASE: platform.cc: fix up assertion_failed() call Signed-off-by: Tim Janik --- ase/platform.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ase/platform.cc b/ase/platform.cc index 9f6b18ce..cd59c980 100644 --- a/ase/platform.cc +++ b/ase/platform.cc @@ -1118,7 +1118,7 @@ void this_thread_set_name (const String &name16chars) { if (name16chars.find (" ") != name16chars.npos) - ::Ase::assertion_failed (string_format ("new thread name contains spaces: \"%s\"", name16chars)); + ::Ase::assertion_failed (string_format ("new thread name contains spaces: \"%s\"", name16chars).c_str()); pthread_setname_np (pthread_self(), name16chars.c_str()); } From b5f92939320301b87539290fb06dd53bbcb778e8 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:06:05 +0100 Subject: [PATCH 6/8] ASE: queuemux.hh: simplify impls by adding noexcept Signed-off-by: Tim Janik --- ase/queuemux.hh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ase/queuemux.hh b/ase/queuemux.hh index 26f16462..0f0f6f04 100644 --- a/ase/queuemux.hh +++ b/ase/queuemux.hh @@ -39,7 +39,7 @@ struct QueueMultiplexer { return more(); } size_t - count_pending() const + count_pending() const noexcept { size_t c = 0; for (ssize_t i = 0; i < n_queues; i++) @@ -47,19 +47,19 @@ struct QueueMultiplexer { return c; } bool - more() const + more() const noexcept { return n_queues > 0; } const ValueType& - peek () + peek () noexcept { if (!more()) [[unlikely]] return empty(); return *ptrs[current].it; } const ValueType& - pop () + pop () noexcept { ASE_ASSERT_RETURN (more(), empty()); const ValueType &result = *ptrs[current].it++; @@ -104,7 +104,7 @@ struct QueueMultiplexer { iterator end () { return {}; } private: void - seek() + seek() noexcept { if (n_queues == 0) [[likely]] return; @@ -126,7 +126,7 @@ private: // dprintf (2, "%s: n_queues=%zd current=%zd first=%ld next=%ld\n", __func__, n_queues, current, long (first), long (next)); } static const ValueType& - empty() + empty() noexcept { static const ValueType empty_ {}; return empty_; From 7502da6747abdf8afe9726038d0586487a1b8a1d Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:17:55 +0100 Subject: [PATCH 7/8] ASE: cxxaux: assertion_failed: simplify many call sites by adding noexcept Signed-off-by: Tim Janik --- ase/cxxaux.cc | 2 +- ase/cxxaux.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ase/cxxaux.cc b/ase/cxxaux.cc index 3a702e73..19a1ba34 100644 --- a/ase/cxxaux.cc +++ b/ase/cxxaux.cc @@ -23,7 +23,7 @@ string_demangle_cxx (const char *mangled_identifier) } void -assertion_failed (const char *msg, const char *file, int line, const char *func) +assertion_failed (const char *msg, const char *file, int line, const char *func) noexcept { if (file && line > 0 && func) fprintf (stderr, "%s:%u:%s: ", file, line, func); diff --git a/ase/cxxaux.hh b/ase/cxxaux.hh index f7709ff5..7f54f7e4 100644 --- a/ase/cxxaux.hh +++ b/ase/cxxaux.hh @@ -207,7 +207,7 @@ using VirtualBaseP = std::shared_ptr; /// Issue a warning about an assertion error. void assertion_failed (const char *msg = nullptr, const char *file = __builtin_FILE(), - int line = __builtin_LINE(), const char *func = __builtin_FUNCTION()); + int line = __builtin_LINE(), const char *func = __builtin_FUNCTION()) noexcept; /// Test string equality at compile time. extern inline constexpr bool From d4da12eb184b59a3bf325984172bc0d7c71e2390 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 17 Nov 2023 16:30:45 +0100 Subject: [PATCH 8/8] ASE: queuemux.hh: avoid inlining fallback method `empty()` Signed-off-by: Tim Janik --- ase/queuemux.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ase/queuemux.hh b/ase/queuemux.hh index 0f0f6f04..41929974 100644 --- a/ase/queuemux.hh +++ b/ase/queuemux.hh @@ -126,7 +126,7 @@ private: // dprintf (2, "%s: n_queues=%zd current=%zd first=%ld next=%ld\n", __func__, n_queues, current, long (first), long (next)); } static const ValueType& - empty() noexcept + empty() noexcept ASE_NOINLINE { static const ValueType empty_ {}; return empty_;