FW: Segmentation fault in program
Sorry to take so long to get around to this, but I finally have. I used Simon's modified version of your code (passing __init_ConvertProxy rather than __init_Convert as the third argument to startupHaskell), and it works fine, on large files with large and small buffers. Did you have particular test data for which it failed? [Sigbjorn has since sent me such data, which still work fine for me.] -Original Message- From: T.J. Brown [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 08, 2001 11:06 PM To: [EMAIL PROTECTED] Subject: Segmentation fault in program Hi, I'm trying to write a program (in C) that calls a function that is implemented in Haskell. The inputs to the function is: a pointer to a buffer of unsigned longs, the length of the input buffer, and a pointer to a buffer of unsigned chars. The function is to convert the buffer of unsigned longs into a [Word32], then convert that list into [Word8] (there will be some sort of processing on this list eventually) and then copy it to the output buffer. I'm using HaskellDirect to assist with this interface between C and 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. System info: linux 2.2.12-20 gcc version: egcs-2.91.66 Attached are the source files and the compile output. 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? Thanks for your help, T.J. __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
RE: Segmentation fault in program
The problem is indeed that the wrong __init_Foo is being passed to startupHaskell. The Haskell part of your program consists of two modules, Convert and ConvertProxy (the latter is generated by H/Direct). ConvertProxy imports Convert, and is therefore the "topmost" module in the program. To fix the GC problems, you must pass __init_ConvertProxy rather than __initConvert to startupHaskell. Sorry about the lack of documentation about this, hopefully we'll rectify that before the next release. Cheers, Simon -Original Message- From: T.J. Brown [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 13, 2001 4:10 PM To: Simon Marlow Subject: RE: Segmentation fault in program I believe I'm passing the correct __init_Foo unless I'm confused. Attached is the code. My ultimate goal here is to be able to pass streams of data from a C program to a Haskell function for processing. If there is a better way to do this than what I'm doing, please let me know. Thanks, T.J. --- Simon Marlow [EMAIL PROTECTED] wrote: GC problems sometimes result from the wrong __init_Foo being passed to startupHaskell. The symbol you pass in must relate to the topmost module in your program; all other modules must be directly or indirectly imported by the topmost module. If you're sure this is the case, could you send me the code and I'll take a look. Cheers, Simon -Original Message- From: Sigbjorn Finne [mailto:[EMAIL PROTECTED]] Sent: Monday, February 12, 2001 8:07 PM To: T.J. Brown Cc: [EMAIL PROTECTED] Subject: Re: Segmentation fault in program I'm able to reproduce this here too -- forwarded to glasgow-haskell-bugs; I'm no longer involved debugging GHC bits. --sigbjorn - Original Message - From: "T.J. Brown" [EMAIL PROTECTED] To: "Sigbjorn Finne" [EMAIL PROTECTED] Sent: Monday, February 12, 2001 19:21 Subject: Re: Segmentation fault in program After making the changes suggested below and updating the GHC driver script to fix the -no-hs-main bug, my program will successfully complete when processing a small amount of data. When processing larger amounts of data, however, it will crash with a segmentation fault or print "EVACUATED object entered". If I increase the size of the heap with "+RTS -Hsize" the program will complete successfully. It doesn't seem like the garbage collector is doing the right thing. Is there something I need to do to enable the garbage collector to free memory between subsequent calls to the my Haskell function (Convert)? Thanks, T.J. --- Sigbjorn Finne [EMAIL PROTECTED] wrote: 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. __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: Segmentation fault in program
The problem is indeed that the wrong __init_Foo is being passed to startupHaskell. No, that's not it. I've been able to repro this with __init_ConvertProxy too - did you test it? (This is with 4.08.1 on a Win2k box.) --sigbjorn ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
RE: Segmentation fault in program
The problem is indeed that the wrong __init_Foo is being passed to startupHaskell. No, that's not it. I've been able to repro this with __init_ConvertProxy too - did you test it? (This is with 4.08.1 on a Win2k box.) Yes, I did, and was able to demonstrate a crash which went away when I changed __init_Convert to __init_ConvertProxy (with 4.08.2, but not on a Win2k box). Perhaps there's something else going on, I'll take a look on Win2k. Cheers, Simon ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: Segmentation fault in program
I'm able to reproduce this here too -- forwarded to glasgow-haskell-bugs; I'm no longer involved debugging GHC bits. --sigbjorn - Original Message - From: "T.J. Brown" [EMAIL PROTECTED] To: "Sigbjorn Finne" [EMAIL PROTECTED] Sent: Monday, February 12, 2001 19:21 Subject: Re: Segmentation fault in program After making the changes suggested below and updating the GHC driver script to fix the -no-hs-main bug, my program will successfully complete when processing a small amount of data. When processing larger amounts of data, however, it will crash with a segmentation fault or print "EVACUATED object entered". If I increase the size of the heap with "+RTS -Hsize" the program will complete successfully. It doesn't seem like the garbage collector is doing the right thing. Is there something I need to do to enable the garbage collector to free memory between subsequent calls to the my Haskell function (Convert)? Thanks, T.J. --- Sigbjorn Finne [EMAIL PROTECTED] wrote: 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. __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ ___ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: Segmentation fault in program
"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
Segmentation fault in program
Hi, I'm trying to write a program (in C) that calls a function that is implemented in Haskell. The inputs to the function is: a pointer to a buffer of unsigned longs, the length of the input buffer, and a pointer to a buffer of unsigned chars. The function is to convert the buffer of unsigned longs into a [Word32], then convert that list into [Word8] (there will be some sort of processing on this list eventually) and then copy it to the output buffer. I'm using HaskellDirect to assist with this interface between C and 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. System info: linux 2.2.12-20 gcc version: egcs-2.91.66 Attached are the source files and the compile output. 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? Thanks for your help, T.J. __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ convert.tar.gz