Skip to content

v5.0.0

Compare
Choose a tag to compare
@FedeDP FedeDP released this 07 Sep 07:41
· 360 commits to master since this release

Libmodule 5.0.0

I am proud to present you a new major version of libmodule.
There has been lots of work to any area of the library to provide an elegant, simple and beautiful API, while being more effective.
This release breaks API thus version was bumped.

Highlights

Module

Module API has seen quite lots of improvements in nearly every aspects.
It now spots more coherent namings, uses less resources and it always trusts user pointers, now as core principle.

New APIs

  • self() macro is now exposed in module_easy API to retrieve _self variable
  • module_poisonpill() is a new function to enqueue a system message in a module's message queue that will stop it. This is useful to avoid stopping a module right away (like module_stop()), instead waiting for it to receive other enqueued pubsub messages
  • module_dump() will dump various informations about a module using module_log(), eg: its fds, its subscriptions...
  • module_load() will runtime link an externally compiled module
  • module_unload() will unload a module previously loaded

New Features

  • Added regex topic subscriptions support
  • Added 2 new system messages: MODULE_STARTED/STOPPED
  • System messages will now have valued sender whenever possible
  • Avoid telling system messages like MODULE_STARTED to module which generated these messages
  • A default (weak symbol) main() that just runs modules_ctx_loop() on any found ctx is now provided by libmodule
  • Automatically stop looping on context when there are no RUNNING modules in it

API breaks

  • module_tell()/module_publish()/module_broadcast() take an additional parameter: bool autofree -> whether to automatically free message data after last recipient receives it
  • Avoid strdupping module's name and ctx's name
  • module_subscribe()/module_unsubscribe() now avoids checking if topic is registered in context
  • module_register_topic()/module_deregister_topic() have been dropped
  • pubsub interface now takes const void* instead of const unsigned char* as data
  • Added a new parameter to module_broadcast(): bool global. It will broadcast a message to every module in every context
  • Renamed pubsub_msg field to ps_msg inside msg_t
  • Renamed pubsub_msg_t type to ps_msg_t
  • Topic is no more strdupped when publishing/broadcasting a message
  • Renamed MODULE_DEFAULT_CTX and MODULE_MODULE_MAX_EVENTS to MODULES_*
  • Actually call init() callback only first time module is started, even without passing from evaluate_module (thus when started explicitly through module_start())
  • module_get_name()/module_get_ctx() return a strdup string
  • Renamed modules_set_memalloc_hook() to modules_set_memhook()
  • Renamed memalloc_hook to memhook_t
  • Renamed userhook to userhook_t
  • Avoid exposing in modules.h main() and modules_pre_start() functions: they're not part of libmodule's API and cannot be called as functions

Fixes

  • When stop looping on a context, flush all pubsub messages to RUNNING modules only. Destroy messages for non-running modules
  • When deregistering, remove module from context before stopping it

Map

Map API has undergone a full rewrite, and it is now based on work by David Leeds: https://github.com/DavidLeeds/hashmap. (thanks!)
Moreover, it is now properly tested too, with a stress test that will insert 1000000 keys and iterate on them.

New APIs

  • Added map_itr_t type and its functions: map_itr_new(), map_itr_next(), map_itr_get_key(), map_itr_get_data(), map_itr_set_data(), map_itr_remove()

API breaks

  • map_new() takes 2 new parameters whether to duplicate key, and a dtor function for values
  • Dropped map_set_dtor()
  • map_put takes 2 parameters less: bool dupkey and bool autofree value

Fixes

  • Avoid incrementing map size on value update
  • Destroy old value upon val update, if any dtor is set

Stack

New APIs

  • Added stack_itr_t type and its functions: stack_itr_new(), stack_itr_next(), stack_itr_get_data(), stack_itr_set_data()

API breaks

  • stack_new() takes a new parameter: bool autofree
  • stack_set_dtor() has been dropped

Queue

Libmodule now offers a queue implementation, in <module/queue.h>.
It is very similar to stack API.

Obviously documentation, tests and examples were all updated accordingly.
Happy developing!