From 3397a53fae89eb4d87e923daf4b9915488d7f83d Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 23 Nov 2018 16:44:16 +0100 Subject: [PATCH] Small imporvement in MOD_ASSERT macro. Updated TODO. --- Lib/module.c | 2 +- Lib/module_priv.h | 6 +++--- Lib/modules.c | 2 +- TODO.md | 3 --- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Lib/module.c b/Lib/module.c index 7456df5..7b7a104 100644 --- a/Lib/module.c +++ b/Lib/module.c @@ -25,7 +25,7 @@ static module_ret_code init_ctx(const char *ctx_name, m_context **context) { **context = (m_context) {0}; (*context)->fd = poll_create(); - MOD_ASSERT(((*context)->fd >= 0), "Failed to create context fd.", MOD_ERR); + MOD_ASSERT((*context)->fd >= 0, "Failed to create context fd.", MOD_ERR); (*context)->logger = default_logger; diff --git a/Lib/module_priv.h b/Lib/module_priv.h index 963b2f4..ca25149 100644 --- a/Lib/module_priv.h +++ b/Lib/module_priv.h @@ -2,13 +2,13 @@ #include "map.h" #ifndef NDEBUG - #define MOD_ASSERT(cond, msg, ret) if (!cond) { fprintf(stderr, "%s\n", msg); return ret; } + #define MOD_ASSERT(cond, msg, ret) if (!(cond)) { fprintf(stderr, "%s\n", msg); return ret; } #else - #define MOD_ASSERT(cond, msg, ret) if (!cond) { return ret; } + #define MOD_ASSERT(cond, msg, ret) if (!(cond)) { return ret; } #endif #define MOD_ALLOC_ASSERT(cond) MOD_ASSERT(cond, "Failed to malloc.", MOD_NO_MEM); -#define MOD_PARAM_ASSERT(cond) MOD_ASSERT((cond), #cond, MOD_WRONG_PARAM); +#define MOD_PARAM_ASSERT(cond) MOD_ASSERT(cond, #cond, MOD_WRONG_PARAM); #ifndef NDEBUG #define MODULE_DEBUG printf("Libmodule: "); printf diff --git a/Lib/modules.c b/Lib/modules.c index 2521a00..cfdd79d 100644 --- a/Lib/modules.c +++ b/Lib/modules.c @@ -50,7 +50,7 @@ module_ret_code modules_ctx_set_logger(const char *ctx_name, const log_cb logger module_ret_code modules_ctx_loop_events(const char *ctx_name, const int max_events) { MOD_PARAM_ASSERT(max_events > 0); FIND_CTX(ctx_name); - MOD_ASSERT((c->num_fds > 0), "No fds to loop on.", MOD_ERR); + MOD_ASSERT(c->num_fds > 0, "No fds to loop on.", MOD_ERR); MOD_ASSERT(!c->looping, "Context already looping.", MOD_ERR); if (poll_init_pevents(&c->pevents, max_events) == MOD_OK) { diff --git a/TODO.md b/TODO.md index df435d1..6ebc2e4 100644 --- a/TODO.md +++ b/TODO.md @@ -6,8 +6,6 @@ - [x] Store context name in m_context (strdup'd) - [x] Use them as hashmap key without strudpping again -- [ ] Remove cycle between self and module: module shouldn't have a pointer to self. - ### Api improvements - [x] Add new MOD_NO_MEM error code - [x] Add new MOD_WRONG_PARAM error code @@ -21,7 +19,6 @@ ## 3.2.0 - [ ] Actually implement a stack for module_become/unbecome - [ ] Expose stack through a stack.h public header -- [ ] Expose a list.h too? And use it for module's fds? ## 4.0.0 (?) - [ ] Prevent other modules from using a module's self_t (as received eg from a PubSub message)