LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
Assertions and helpers

Macros

#define JUNO_ASSERT_EXISTS(ptr)
 Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
 
#define JUNO_ASSERT_EXISTS_MODULE(ptr, ptMod, str)
 Like JUNO_ASSERT_EXISTS but also calls the module's failure handler.
 
#define JUNO_ASSERT_SUCCESS(tStatus, ...)
 Execute the provided failure operation(s) if status is not success.
 

Detailed Description

These macros provide lightweight, freestanding-friendly assertions and failure-notification hooks. They are designed to return error codes rather than aborting, in line with LibJuno's deterministic error handling.

Macro Definition Documentation

◆ JUNO_ASSERT_EXISTS

#define JUNO_ASSERT_EXISTS (   ptr)
Value:
if(!(ptr)) \
{ \
}
#define JUNO_STATUS_NULLPTR_ERROR
A required pointer argument was NULL or invalid.
Definition status.h:60

Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.

Use to validate required pointers or expressions. Typical usage within a function that returns JUNO_STATUS_T:

JUNO_STATUS_T f(void *p) {
// safe to use p
}
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:50
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:56
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
Parameters
ptrPointer/expression to validate (may combine with &&).

◆ JUNO_ASSERT_EXISTS_MODULE

#define JUNO_ASSERT_EXISTS_MODULE (   ptr,
  ptMod,
  str 
)
Value:
if(!(ptr)) \
{ \
JUNO_FAIL_MODULE(JUNO_STATUS_NULLPTR_ERROR, ptMod, str); \
}

Like JUNO_ASSERT_EXISTS but also calls the module's failure handler.

Invokes JUNO_FAIL_MODULE(JUNO_STATUS_NULLPTR_ERROR, ptMod, str) before returning JUNO_STATUS_NULLPTR_ERROR.

Parameters
ptrThe dependency expression to validate.
ptModThe module instance providing the failure handler.
strMessage passed to the failure handler upon failure.

◆ JUNO_ASSERT_SUCCESS

#define JUNO_ASSERT_SUCCESS (   tStatus,
  ... 
)
Value:
if(tStatus != JUNO_STATUS_SUCCESS) \
{ \
__VA_ARGS__; \
}

Execute the provided failure operation(s) if status is not success.

Intended for early-returns and cleanup in error paths:

JUNO_STATUS_T t = do_something();
JUNO_ASSERT_SUCCESS(t, return t);
#define JUNO_ASSERT_SUCCESS(tStatus,...)
Execute the provided failure operation(s) if status is not success.
Definition macros.h:87

The variadic statements are emitted verbatim inside the error branch; ensure they are valid in the enclosing scope.

Parameters
tStatusStatus value to check.
...Statements to execute when tStatus != JUNO_STATUS_SUCCESS.