Open tudor opened 3 years ago
we already have this (to some degree), it is called a wasi reactor and it uses _initialize
: https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md#current-unstable-abi
Nice, thank you. There should probably also be a finalization API (that would call, e.g. destructors of global C++ objects)
Right now,
_start
initializes global state, callsmain()
, and then tears down global state.This is fine for executable modules, but not for modules designed to be used as libraries.
For a library, I would like to initialize global state right after the library is loaded, and then tear down global state right before shutting the library down.
I am proposing separating the initialization part into a separate exported function (call it
_init
) and, similarly, splitting the finalization into a separate exported function (call it_fini
).Then
_start
becomes (pseudocode):but people who intend to use the module as a library have the option to call
_init()
and_fini()
directly.