Skip to content

Commit

Permalink
lib: Add MODULE_CONTEXT_REQUIRE
Browse files Browse the repository at this point in the history
This will panic instead of return NULL. Should satisfy static
analyzers when used.
  • Loading branch information
cmouse authored and mrannanj committed Feb 20, 2018
1 parent 4d90f3f commit bf055b4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/module-context.h
Expand Up @@ -50,6 +50,15 @@
module_get_context_id(&(id_ctx).id)) + \
OBJ_REGISTER_COMPATIBLE(obj, id_ctx)))

/* Will crash if context is missing. This is mainly used to simplify code and
keep static analyzers happy. This syntax discards result of i_panic and
returns NULL instead to keep compilers happy. */
#define MODULE_CONTEXT_REQUIRE(obj, id_ctx) \
(module_get_context_id(&(id_ctx).id) < array_count(&(obj)->module_contexts) ? \
(*((void **)array_idx_modifiable(&(obj)->module_contexts, \
module_get_context_id(&(id_ctx).id)) + \
OBJ_REGISTER_COMPATIBLE(obj, id_ctx))) : (i_panic("Module context " #id_ctx " missing"), NULL))

#ifdef HAVE_TYPEOF
# define MODULE_CONTEXT_DEFINE(_name, _reg) \
struct _name { \
Expand Down

0 comments on commit bf055b4

Please sign in to comment.