Haskell 使用c2hs封送一个void*
我的C函数如下所示:Haskell 使用c2hs封送一个void*,haskell,ffi,c2hs,Haskell,Ffi,C2hs,我的C函数如下所示: void *c_shm_create(char*, int); {-# 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' , `I
void *c_shm_create(char*, int);
{-# 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 ()' #}
我的.chs
文件如下所示:
void *c_shm_create(char*, int);
{-# 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 ()' #}
这是我得到的错误:
src\System\Shm\Internal\Bindings.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文档中找不到关于void指针(
Ptr()
)的任何提及。如何封送此信息?进行以下更改:
{#fun c_shm_create as c_shmCreate { `String' , `Int' } -> `Ptr ()' id #}
我不确定这是一个bug还是故意的。Haskell数据类型和C结构可能被视为“相等”,因为它们表示相同的数据,但不表示相同的数据(结构是堆上的纯字节,而数据类型是指针等),因此您将需要一个封送处理函数,而不仅仅是id