Skip to content

Commit 85427bb

Browse files
committed
cleanup(core,docs): drop m_on_boot() global weak function; it is useless now.
Easy API enforces default memhook (or, one can override it by writing its own constructor to run before libmodule's easy api ones). Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
1 parent e0383a7 commit 85427bb

File tree

6 files changed

+11
-34
lines changed

6 files changed

+11
-34
lines changed

Lib/core/main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
* Code related to main library ctor/dtor + main() symbol. *
88
***********************************************************/
99

10-
_public_ _m_ctor0_ _weak_ void m_on_boot(void) {
11-
M_DEBUG("Booting libmodule.\n");
12-
}
13-
1410
_public_ _weak_ void m_ctx_pre_loop(m_ctx_t *c, int argc, char *argv[]) {
1511
M_DEBUG("Pre-looping libmodule easy API.\n");
1612
}

Lib/core/public/module/mod_easy.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88

99
/*
1010
* ctors order:
11-
* 0) global m_on_boot(), useful to set your own memhook if desired
12-
* 1) each m_mod_on_boot() (only mod_easy API)
13-
* 2) each m_mod_ctor() (only mod_easy API)
11+
* 0) each m_mod_on_boot() (only mod_easy API)
12+
* 1) each m_mod_ctor() (only mod_easy API)
1413
*
1514
* dtors order:
1615
* 0) each m_mod_dtor() (only mod_easy API)
1716
*/
18-
#define _m_ctor0_ __attribute__((constructor (110)))
19-
#define _m_ctor1_ __attribute__((constructor (113)))
20-
#define _m_ctor2_ __attribute__((constructor (114)))
17+
#define _m_ctor0_ __attribute__((constructor (113)))
18+
#define _m_ctor1_ __attribute__((constructor (114)))
2119
#define _m_dtor0_ __attribute__((destructor (111)))
2220

2321
/* Simple macro to automatically manage module lifecycle and callbacks */
@@ -27,7 +25,7 @@
2725
static void m_mod_on_evt(m_mod_t *mod, const m_queue_t *const evts); \
2826
static void m_mod_on_stop(m_mod_t *mod); \
2927
static m_ctx_t *_m_ctx; \
30-
static void _m_ctor2_ m_m_ctor(void) { \
28+
static void _m_ctor1_ m_m_ctor(void) { \
3129
_m_ctx = m_ctx(); \
3230
if (!_m_ctx) { \
3331
m_ctx_register(M_CTX_DEFAULT, &_m_ctx, 0, NULL); \
@@ -38,4 +36,4 @@
3836
static void _m_dtor0_ m_mod_dtor(void) { \
3937
m_mem_unrefp((void **)&_m_ctx); \
4038
} \
41-
static void _m_ctor1_ m_mod_on_boot(void)
39+
static void _m_ctor0_ m_mod_on_boot(void)

TODO.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
- - [ ] drop m_ctx_t param from funtion calls
1515
- - [x] drop libmodule_init() and deinit() constructors
1616
- - [x] move ctor defines into mod_easy.h
17-
- - [ ] Specify that m_set_memhook should be called before allocating any libmodule related resource (ie: m_on_boot() for mod_easy, or before allocating first ctx, when manually)
17+
- - [x] drop m_on_boot(); specify that mod_easy API force-uses malloc,calloc and free by default.
18+
- - [x] Specify that m_set_memhook should be called before allocating any libmodule related resource
1819
- [x] and just add an m_ctx() API that returns ctx associated with current thread
19-
- [x] store in ctx a `void **curr_mod` that points to the module whose callback is currently being processed, if any, or NULL; when NULL; we are outside a module callback, therefore we can return it; else, we must guarantee that module has permissions to access its ctx
20+
- [x] store in ctx a `curr_mod` that points to the module whose callback is currently being processed, if any, or NULL; when NULL; we are outside a module callback, therefore we can return it; else, we must guarantee that module has permissions to access its ctx
2021
- [ ] Downside: how could we guarantee that 2 ctx with same name do not exist? We cannot; is this a limitation, actually?
2122

2223
#### DOC

docs/concepts/concepts.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ Ctor order is specified in each namespace doc.
4444
### Memhook
4545

4646
Moreover, libmodule allows users to override default memhook used, by calling `m_set_memhook()`.
47-
This function must be called from `m_on_boot()` function, because it has to be called before any internal ctor is run, ie: before any allocation takes place.
47+
This function must be called before any libmodule's allocation takes place, ie: before calling the first `m_ctx_register`.
4848
A memhook is just a wrapper around 3 main memory related functions:
4949

5050
* `malloc`
5151
* `calloc`
5252
* `free`
53-

docs/core/core.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ For the sake of readiness, function params where an output value will be stored,
1414

1515
> **All the libmodule core API returns an errno-style negative error code, where left unspecified.**
1616
17-
## Constructors
18-
19-
Libmodule makes heavy usage of gcc `__attribute__((constructor))` (and destructor) to inizialize itself.
20-
The order is the following:
21-
22-
**Ctors**
23-
24-
* `m_on_boot()`
25-
* internal `libmodule_init()`
26-
* each `m_mod_on_boot()` (only mod_easy API)
27-
* each `m_mod_ctor()` (only mod_easy API)
28-
29-
**Dtors**
30-
31-
* each `m_mod_dtor()` (only mod_easy API)
32-
* internal `libmodule_deinit()`
33-
3417
## Memory
3518

3619
### Ref counted

docs/core/mod.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Mod API denotes libmodule interface functions to manage modules.
44
It can be found in `<module/mod.h>` header.
55

6-
> **All the ctx API expects a non-NULL ctx handler**, except for ... functions.
6+
> **All the mod API expects a non-NULL mod handler**, except for ... functions.
77

0 commit comments

Comments
 (0)