我正在尝试绑定到返回结构(按值)的 C 函数。我知道我可以使用 FFI 手动包装它,但不知道如何哄 c2hs 生成正确的代码。似乎认为我的函数正在返回一个指针。
这是一个简单的例子:
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'#}
错误:
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 ())