[Haskell-cafe] How can I pass IOUArrays to FFI functions?

Donald Bruce Stewart dons at cse.unsw.edu.au
Mon Aug 20 08:56:45 EDT 2007


ryani.spam:
> 
>    I have a C function of type
> 
>       void f ( HsWord32* p0, HsWord32* p1, HsWord32 size );
> 
> 
> 
>    along with the FFI declaration:
> 
>       foreign import ccall unsafe f :: Ptr Word32 -> Ptr Word32
>    -> Word32 -> IO ()
> 
> 
> 
>    In my Haskell code I have an unboxed IO array of Word32;
>    IOUArray Int Word32.
> 
>    I want to pass the pointer to this array to f().  How can I
>    get the pointer out of the array?  Or, is there a better way
>    to declare f() to do this?
> 
> 
> 
>    I'm open to using GHC hackery; using v6.6.1 right now.
> 
> 

Perhaps you want to use Foreign.Array instead (they are unboxed, and
can be used as a Ptr over to C land)?

-- Don


More information about the Haskell-Cafe mailing list