Вопрос

My C function looks like this:

void *c_shm_create(char*, int);

My .chs file looks like this:

{-# 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 ()' #}

This is the error I get:

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 ())

I can't find any mention for void pointer (Ptr ()) in the c2hs documentation. How do I marshal this?

Это было полезно?

Решение

Making the following change:

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

I'm unsure if this is a bug or is intentional. A Haskell data type and C struct may be considered 'equal' in that they represent the same data, but are not represented the same (the struct is pure bytes on the heap while the datatype is pointers and such) so you will need a marshaling function that isn't just id.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top