[C2hs] Marshal Haskell list into monolithic arrays

zhu Jun lilozhu at hotmail.com
Thu Aug 17 17:49:08 EDT 2006


I freed 'mfs' and 'fsP2' before return also.

>lowPassFilter :: [CFloat] -> CFloat
>lowPassFilter fs =  (unsafePerformIO (lowPassFilterWrap fs))
>    where lowPassFilterWrap :: [CFloat] -> IO CFloat
>	  lowPassFilterWrap fs = do
>	        mfs <- newArray fs
>                fsP2 <- malloc
>                r <- f_lowPassFilter mfs fsP2
>                returnF <- peek fsP2
>                free mfs
>                free fsP2
>                return returnF


Best wishes,

Yours,
  Jun

Direct:   +46 8 790 4150 
Fax:      +46 8 751 1793

Post Address: KTH/IMIT/ LECS, Electrum 229, SE-164 40 Kista, Stockholm, 
Sweden
Visiting address: Forum-Building, Isafjordsgatan 39, 8th floor, elevator C





>From: "zhu Jun" <lilozhu at hotmail.com>
>To: u.stenzel at web.de
>CC: C2hs at haskell.org
>Subject: Re: [C2hs] Marshal Haskell list into monolithic arrays
>Date: Thu, 17 Aug 2006 21:39:27 +0000
>
>Hi Udo and Duncan,
>
>Yes, I made a mistake in C syntax. Now, I call the function in 
>Haskell like this:
>-------------------------
>lowPassFilter :: [CFloat] -> CFloat
>lowPassFilter fs =  (unsafePerformIO (lowPassFilterWrap fs))
>    where lowPassFilterWrap :: [CFloat] -> IO CFloat
>	  lowPassFilterWrap fs = do
>	        mfs <- newArray fs
>                fsP2 <- malloc
>                r <- f_lowPassFilter mfs fsP2
>                returnF <- peek fsP2
>                return returnF
>
>foreign import ccall "static fmr.h lowPassFilter"
>  f_lowPassFilter :: Ptr (CFloat) -> Ptr (CFloat) -> IO (())
>
>---------------------------
>and the C function is defined as:
>////////////////////////
>void lowPassFilter(float *buff, float *sum)
>{
>
>// Work part
>  for (i = 0; i < NUM_TAPS; i++)
>  {
>    printf("buff %d = %f \n", i, *(buff++));
>    *sum += *(buff++) * coeff[i];
>  }
>}
>////////////////////////
>
>It works well! Thank you so much!
>
>Best wishes,
>
>Yours,
>  Jun
>
>>From: Udo Stenzel <u.stenzel at web.de>
>>To: zhu Jun <lilozhu at hotmail.com>
>>Subject: Re: [C2hs] Marshal Haskell list into monolithic arrays
>>Date: Thu, 17 Aug 2006 17:17:21 +0200
>>
>>zhu Jun wrote:
>> > There is a 'newArray' operation in MarshallArray to marshal 
>>Haskell
>list,
>> >
>> > The C function looks like:
>> > ////////////////////
>> > void lowPassFilter(float *fs[10], float *sum)
>>
>>This function doesn't take (a pointer to) an array of floats, but 
>>(a
>>pointer to) an array of pointers to floats, which I doubt was your
>>intention.  You need help programming in C, not help using C2HS.  
>>Try a
>>book or ask in news:comp.lang.c
>>
>>
>>Udo.
>>
>
>
>><< signature.asc >>
>
>
>_______________________________________________
>C2hs mailing list
>C2hs at haskell.org
>http://www.haskell.org/mailman/listinfo/c2hs




More information about the C2hs mailing list