#3252: having to call hs_add_root(__stginit_Foo) is a bit of a pain
-----------------------------+----------------------------------------------
Reporter: duncan | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler (FFI)
Version: 6.10.2 | Severity: normal
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-----------------------------+----------------------------------------------
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:
{{{
hs_add_root(__stginit_Foo);
}}}
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.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3252>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs