Idris2/support/c/idris_util.h
Stiopa Koltsov d910677d74 IDRIS2_VERIFY macro
```
IDRIS2_VERIFY(cond, message_format, ...)
```

When condition is false, crash.

Used in native functions where correct error handling is hard or
not impossible.

For example, `malloc` rarely fails, but if it fails, better crash
with clear error message than spend time debugging null pointer
dereference.
2021-07-13 13:57:24 +01:00

21 lines
528 B
C

#pragma once
#include <stdnoreturn.h>
// Utilities used by FFI code.
// Crash is the condition is false.
#define IDRIS2_VERIFY(cond, ...) \
do { \
if (!(cond)) { \
idris2_verify_failed(__FILE__, __LINE__, #cond, __VA_ARGS__); \
} \
} while (0)
// Used by `IDRIS2_VERIFY`, do not use directly.
noreturn void idris2_verify_failed(const char* file, int line, const char* cond, const char* fmt, ...)
#if defined(__clang__) || defined(__GNUC__)
__attribute__ ((format(printf, 4, 5)))
#endif
;