我有以下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?