I'm trying to bind to a C function that returns a struct (by value). I know I can wrap it manually using the FFI, but can't figure out how to coax c2hs into generating the correct code. It seems to think my function is returning a pointer.
Here's a simple example:
module Point where
#c
struct point {
int x;
int y;
};
struct point get_zero(void);
#endc
data Point = Point { x :: Int, y :: Int }
instance Storable Point where
sizeOf _ = {#sizeof point#}
alignment _ = {#alignof point#}
peek p = point <$> liftA fromIntegral ({#get point.x #} p)
<*> liftA fromIntegral ({#get point.y #} p)
poke p s = do {#set point.x #} p (fromIntegral $ x s)
{#set point.y #} p (fromIntegral $ y s)
{#pointer *point as PointPtr -> Point#}
-- Causes error:
{#fun get_zero as ^ { } -> `Point'#}
The error:
c2hs: Errors during expansion of binding hooks:
Point.chs:25: (column 28) [ERROR] >>> Missing "out" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: Point
C type : (Ptr ())