Skip to content

Commit

Permalink
Small imporvement in MOD_ASSERT macro. Updated TODO.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Nov 23, 2018
1 parent c6ac395 commit 3397a53
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Lib/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions Lib/module_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Lib/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3397a53

Please sign in to comment.