File: Issue93.chs

package info (click to toggle)
c2hs 0.28.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,788 kB
  • sloc: haskell: 6,882; ansic: 1,857; xml: 1,411; makefile: 111
file content (35 lines) | stat: -rwxr-xr-x 777 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE EmptyDataDecls, ForeignFunctionInterface #-}
module Main where

import Control.Applicative

import Foreign.C.Types
import Foreign.Marshal.Utils
import Foreign.Storable
import Foreign.Ptr

#include "issue93.h"

data Foo
data Bar = Bar Int Int

instance Storable Bar where
    sizeOf _ = {#sizeof bar_t #}
    alignment _ = {#alignof bar_t #}
    peek p = Bar
      <$> (fromIntegral <$> {#get bar_t.y #} p)
      <*> (fromIntegral <$> {#get bar_t.z #} p)
    poke p (Bar y z) =
         ({#set bar_t.y #} p $ fromIntegral y)
      *> ({#set bar_t.z #} p $ fromIntegral z)

{#pointer *foo_t as FooPtr -> Foo #}
{#pointer *bar_t as BarPtr -> Bar #}

{#fun unsafe mutate_foo as mutateFoo
  { `FooPtr'
  , with* `Bar'
  } -> `()' #}

main :: IO ()
main = putStrLn "OK"