我想从C
调用以下Haskell
函数:
void read_params_for (property_list_t *props);
该函数应该接收一些property_list_t
并在其中填充一些值,因此调用者具有更新的结构。
我拥有property_list_t
所有必需的包装器(如Storable
等),但我无法弄清楚如何将此函数包装成类似
readParamsFor :: ForeignPtr PropertyListT -> IO (ForeignPtr PropertyListT)
我尝试使用C2HS
,我也尝试手动编写FFI绑定,如:
foreign import ccall "read_params_for"
readParamsFor' :: Ptr PropertyListT -> IO ()
readParamsFor :: ForeignPtr PropertyListT -> IO (ForeignPtr PropertyListT)
readParamsFor ps = do
withForeignPtr ps $ \ps' -> do
res <- readParamsFor' ps'
pl <- newForeignPtr propertyListDestroy ps'
return pl
但在这两种情况下,我都会找回原来“人口稀少”的名单。
如何将更新的结构返回给Haskell?
答案 0 :(得分:0)
我意识到我想要使用的C库中存在一个错误,如果错误不存在,那么简单的withForeignPtr
就足够了。