i try to understand the difference between c2hs
and gtk2hsC2hs
(modified version of c2hs
for use in gtk2hs
). Consider the following coding:
module Matrix where
data Matrix = Matrix { xx :: !Double, yx :: !Double,
xy :: !Double, yy :: !Double,
x0 :: !Double, y0 :: !Double }
deriving (Show, Eq)
{#pointer *cairo_matrix_t as MatrixPtr -> Matrix#}
instance Storable Matrix where
sizeOf _ = {#sizeof cairo_matrix_t#}
alignment _ = alignment (undefined :: CDouble)
peek p = do
xx <- {#get cairo_matrix_t->xx#} p
yx <- {#get cairo_matrix_t->yx#} p
xy <- {#get cairo_matrix_t->xy#} p
yy <- {#get cairo_matrix_t->yy#} p
x0 <- {#get cairo_matrix_t->x0#} p
y0 <- {#get cairo_matrix_t->y0#} p
return $ Matrix (realToFrac xx) (realToFrac yx)
(realToFrac xy) (realToFrac yy)
(realToFrac x0) (realToFrac y0)
poke p (Matrix xx yx xy yy x0 y0) = do
{#set cairo_matrix_t->xx#} p (realToFrac xx)
{#set cairo_matrix_t->yx#} p (realToFrac yx)
{#set cairo_matrix_t->xy#} p (realToFrac xy)
{#set cairo_matrix_t->yy#} p (realToFrac yy)
{#set cairo_matrix_t->x0#} p (realToFrac x0)
{#set cairo_matrix_t->y0#} p (realToFrac y0)
return ()
{#context lib="cairo" #}
{#fun cairo_pattern_set_matrix as patternSetMatrix { unPattern `Pattern', `Matrix'} -> `()'#}
{#fun cairo_pattern_get_matrix as patternGetMatrix { unPattern `Pattern', alloca- `Matrix' peek*} -> `()'#}
The second fun
line (e.g. cairo_pattern_get_matrix
) works for both tools (although the generated code is different), while the first (e.g. cairo_pattern_set_matrix
) works only for gtk2hsC2hs
.
The error message when using c2hs
is:
Test.chs:35: (column 75) [ERROR] >>> Missing "in" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: Matrix
C type : (MatrixPtr)
I don't understand the problem here clearly, but from my point of view, this should be valid.
I use for c2hs
:
C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017
build platform is "x86_64-linux" <1, True, True, 1>
and gtk2hsC2hs
:
C->Haskell Compiler, version 0.13.13 (gtk2hs branch) "Bin IO", 27 May 2012
Thanks in advance