diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-12-29 12:04:22 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2026-01-05 21:20:24 +0000 |
| commit | 6ceaa78088ebdaea6cb887a7e8066fc29e0f984d (patch) | |
| tree | f6d883d3a3d7e798b580e8287302af5a17530dd3 | |
| parent | d0643f993d3c6c42ea10d5ce3a02d964b7693a7f (diff) | |
macros: Introduce must_succeed() macro
This is like assert() but never compiled out so can be used with
function calls that have side effects.
| -rw-r--r-- | apt-pkg/contrib/macros.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index 08e7aeb72..1a76ef60a 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -33,6 +33,14 @@ #define likely(x) (x) #define unlikely(x) (x) #endif + +// Asserts that the result of expr is true +#define must_succeed(expr) ({ \ + auto result = (expr); \ + if (unlikely(not result)) \ + fprintf(stderr, "%s:%d: %s: Assertion `%s` failed.\n", __FILE__, __LINE__, __FUNCTION__, #expr), abort(); \ + result; \ +}) #endif #if APT_GCC_VERSION >= 0x0300 |
