"T.J. Brown" [EMAIL PROTECTED] writes:
>
> I'm trying to write a program (in C) that calls a
> function that is implemented in Haskell.
> ...
> The problem I'm seeing is that depending
> on the size of the buffer, the program segmentation
> faults. I don't see any obvious reason that this is
> happening so I'm wondering if something isn't going
> wrong during the compilation.
Hi,
your converttst.c contains the following decl:
extern void startupHaskell (int argc, char* argv[], void* rootMod);
void* __init_Main;
That won't work, as the root module argument needs to point to
something valid. Rewrite it to:
extern void startupHaskell (int argc, char* argv[], void* rootMod);
extern void* __init_Convert;
and substitute __init_Main with __init_Convert wherever it is used
in the C code.
However, if you recompile and link, I believe you'll see it crashing
even more regularly - I suspect this is due to a bug in the GHC
RTS (at least 4.08.1's, don't know if 4.08.2 has fixed this) Attached
is a simpler program that shows up the problem.
> Also, is there a better way of passing a buffer
> between C and Haskell? For instance, is there a way
> to convert the buffer into a list automatically?
Yes, you can simplify Convert.convert a little, but your
example highlights a dark corner that HaskellDirect doesn't
implement fully, i.e., dependent arguments in Haskell
server proxies. You *should* be able to just say
[pure]
void convert([in,length_is(len)] unsigned long *inBuf,
[in] int len,
[out,length_is(len*4)] unsigned char *outBuf);
and have the generated Haskell code expect Convert.convert
to have the signature ([Word32] -> [Word8]) - I'm working
on implementing this at this very moment.
--sigbjorn
test.tar.gz