使用 c2hs 封送空隙*



我的C函数看起来像这样:

void *c_shm_create(char*, int);

我的.chs文件如下所示:

{-# LANGUAGE ForeignFunctionInterface #-}
module System.Shm.Internal.Bindings
    ( c_shmCreate
    )
where
#include "hs_shm.h"
import C2HS
{#fun unsafe c_shm_create as c_shmCreate
    { `String'
    , `Int' } -> `Ptr ()' #}

这是我得到的错误:

srcSystemShmInternalBindings.chs:12: (column 18) [ERROR]  >>> Missing "out" marshaller!
  There is no default marshaller for this combination of Haskell and C type:
  Haskell type: Ptr ()
  C type      : (Ptr ())

我在 c2hs 文档中找不到任何关于空指针 ( Ptr ()) 的提及。我该如何编组?

进行以下更改:

{#fun c_shm_create as c_shmCreate { `String' , `Int' } -> `Ptr ()' id #}

我不确定这是一个错误还是故意的。Haskell数据类型和C结构可能被认为是"相等的",因为它们表示相同的数据,但表示的不一样(结构是堆上的纯字节,而数据类型是指针等),因此您将需要一个不仅仅是id的封送函数。

最新更新