#3236: Would be nice if rts_lock (or similar) would fail when the RTS is not
started
-----------------------------+----------------------------------------------
Reporter: duncan | Owner:
Type: feature request | Status: new
Priority: normal | Component: Runtime System
Version: 6.11 | Severity: minor
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-----------------------------+----------------------------------------------
If you export a Haskell function and then call it from C code you have got
to remember to start up the RTS before calling the exported C function,
otherwise it segfaults.
As a slightly nicer way of reminding people to initialise the RTS, perhaps
one of the functions on the code path for calling exported functions (ie
the calls in the _stub.c files) could check if the RTS is started and if
not do something a little nicer than segfault.
The code typically looks like
{{{
cap=rts_lock();
cap=rts_evalIO(cap,
rts_apply(cap,(HaskellObj)runIO_closure,
rts_apply(cap,&Foo_zdffoozuads_closure,
rts_mkInt(cap,a1))) ,&ret);
rts_checkSchedStatus("foo",cap);
cret=rts_getInt(ret);
}}}
The first bit to segfault is `allocateLocal`, probably inside `rts_mkInt`.
Note that `rts_lock` succeeds and returns a non-null capability.
On similar lines, we might want to think about the use case of building
Haskell libs that export C functions to be used by other projects and ways
to make initialising that library either nicer or automatic. We all
complain when we use C libs that require a global initialiser (implying
some global state) and yet that's exactly what we impose on callers.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3236>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs