summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-12-29 12:04:22 +0100
committerJulian Andres Klode <jak@debian.org>2026-01-05 21:20:24 +0000
commit6ceaa78088ebdaea6cb887a7e8066fc29e0f984d (patch)
treef6d883d3a3d7e798b580e8287302af5a17530dd3 /apt-pkg
parentd0643f993d3c6c42ea10d5ce3a02d964b7693a7f (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.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/macros.h8
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