Re: [Haskell-cafe] peekCString free memory

2009-11-30 Thread El Barto
Ok, I used this advice: http://www.haskell.org/haskellwiki/GHC/Using_the_FFI#Importing_C_functions_that_turn_out_to_be_CPP_macros to make 'xmlFree' callable from Haskell. I was completly wrong in my first post... I do apologize. On Sun, Nov 29, 2009 at 8:56 PM, El Barto elbart...@gmail.com wrote:

[Haskell-cafe] peekCString free memory

2009-11-29 Thread El Barto
Hello, I get a segfault when I do str - peekCString ptr free ptr return (Just str) But not when I don't free the C pointer. I also get the same behaviour with ByteString.packCString... Could you please tell me if the memory is correctly freed by GHC when I don't do it myself? And how can I

Re: [Haskell-cafe] peekCString free memory

2009-11-29 Thread Thomas DuBuisson
Could you expand on this fragment of code? Perhaps a fullying compilable example? It depends how you are getting the pointer, not how you are reading data out of the pointer. For example, if you use withCString to get ptr then the memory will be freed automatically. Thomas On Sun, Nov 29,

Re: [Haskell-cafe] peekCString free memory

2009-11-29 Thread Bulat Ziganshin
Hello El, Sunday, November 29, 2009, 8:00:02 PM, you wrote: segfault is due to free, you may omit peekCString call. you should free only memory that was malloced and not freed other way Hello, I get a segfault when I do str - peekCString ptr free ptr return (Just str) But not when I

Re: [Haskell-cafe] peekCString free memory

2009-11-29 Thread Duncan Coutts
On Sun, 2009-11-29 at 18:00 +0100, El Barto wrote: Hello, I get a segfault when I do str - peekCString ptr free ptr return (Just str) As Thomas says, you've not really given us enough info here. I'll make some guesses and observations anyway :-) But not when I don't free the C pointer.

Re: [Haskell-cafe] peekCString free memory

2009-11-29 Thread El Barto
Thanks for your help time, I checked the C API documentation: http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderValue The result must be deallocated with xmlFree() I pushed the sources here: http://github.com/gwenn/libxml-reader My problem is with the function at line 249 in