Ticket #3252 (closed feature request: fixed)
having to call hs_add_root(__stginit_Foo) is a bit of a pain
|Reported by:||duncan||Owned by:||simonmar|
|Type of failure:||None/Unknown||Difficulty:||Unknown|
|Test Case:||Blocked By:|
For C code calling C functions exported from Haskell code, it has to jump through a couple hoops first. The call to hs_init() is fair enough and is specified by the FFI, however GHC also makes us call:
for the top level Haskell module that exports the function we're interested in. If there are multiple such modules and they don't depend on each other then presumably we have to call them all.
Doing this is a bit annoying. It's not just that we have to call it, but we have to work out which symbols we need exactly. Are there any ways we could automate it? If the __stginit_* functions are really cheap then can we just have them called as constructor functions using gcc's __attribute__ ((constructor)) system. If they're slightly more expensive then perhaps they could be registered in a constructor and called by hs_init(). Or can we have them run lazily, eg have the exported C functions check that the module they're in has been initialised.