Sven Panne writes:
> Compiling GreenCard generated programs does not always work on HP-UX.
> The following program (a short version of some GreenCard output)
> demonstrates the problem:
>
> -- Main.hs ----------------------------------------------------------
> import Addr
>
> main :: IO ()
> main = do gc_result <- _casm_ ``do {static struct {void *res1;} gc_result;
> gc_result.res1 = (void *)malloc(%0);
> %r = &gc_result;} while(0);'' (1234::Int)
>
> res1 <- _casm_ ``do {%r = ((struct {void *res1;}*) %0)->res1;} while(0);''
>(gc_result :: Addr)
> print (res1::Addr)
> ---------------------------------------------------------------------
>
Are the _casm_s above taken directly from green-card generated
Haskell? It shouldn't use structs if there's only one result being
returned.
> panne@rimatara: > ghc-3.01 -fglasgow-exts Main.hs
> ghc-3.01: module version changed to 1; reason: no old .hi file
> Funny global thing?: gc_result___30
> panne@rimatara: > ./a.out
> Bus error (core dumped)
>
>
> Note the warning from the mangler. If the "static struct" is changed to
> "struct" everything works fine, without a warning and without a core
> dump. Is this a bug in GreenCard or in the mangler? What is the intent
> of the "static" modifier? I can't see a reason for it, but I may be wrong.
>
Green Card passes multiple results back from C through a pointer to a
statically allocated result structure (which it then uses to copy out
result values one by one.) Removing the `static' storage class
modifier is not a good idea.
Try using the --no-inline option to green-card instead; it outputs all
the C stubs into a separate .c file, which you then can compile
separately from ghc (and its wondrous mangler :)
--Sigbjorn