Commit 3b4572b7 authored by Ian Lynagh's avatar Ian Lynagh

Add another test for CAPI / CTYPE

This tests that the header given in the CTYPE pragma is handled.
parent baf18818
{-# LANGUAGE CApiFFI #-}
module Main (main) where
import Capi_Ctype_A_002
import Foreign
import Foreign.C
main :: IO ()
main = alloca $ \p ->
do poke p (Foo 5 6 7)
r1 <- f p
print r1
foreign import capi unsafe "capi_ctype_002_B.h f"
f :: Ptr Foo -> IO CInt
{-# LANGUAGE CApiFFI #-}
module Capi_Ctype_A_002 (Foo(..)) where
#include "capi_ctype_002_A.h"
import Foreign
import Foreign.C
data {-# CTYPE "capi_ctype_002_A.h" "Foo" #-}
Foo = Foo {
i :: CInt,
j :: CInt,
k :: CInt
}
instance Storable Foo where
sizeOf _ = #size Foo
alignment = sizeOf
peek p = do i <- (# peek Foo, i) p
j <- (# peek Foo, j) p
k <- (# peek Foo, k) p
return $ Foo i j k
poke p foo = do (# poke Foo, i) p (i foo)
(# poke Foo, j) p (j foo)
(# poke Foo, k) p (k foo)
......@@ -30,3 +30,11 @@ Capi_Ctype_001:
'$(TEST_HC)' $(TEST_HC_OPTS) capi_ctype_001.o Capi_Ctype_A_001.o Capi_Ctype_001.o -o Capi_Ctype_001
./Capi_Ctype_001
.PHONY: Capi_Ctype_002
Capi_Ctype_002:
'$(HSC2HS)' Capi_Ctype_A_002.hsc
'$(TEST_HC)' $(TEST_HC_OPTS) -c Capi_Ctype_A_002.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -c Capi_Ctype_002.hs
'$(TEST_HC)' $(TEST_HC_OPTS) Capi_Ctype_A_002.o Capi_Ctype_002.o -o Capi_Ctype_002
./Capi_Ctype_002
......@@ -195,3 +195,9 @@ test('Capi_Ctype_001',
run_command,
['$MAKE -s --no-print-directory Capi_Ctype_001'])
test('Capi_Ctype_002',
extra_clean(['Capi_Ctype_A_002.o', 'Capi_Ctype_A_002.hi',
'Capi_Ctype_A_002.hs']),
run_command,
['$MAKE -s --no-print-directory Capi_Ctype_002'])
#ifndef __capi_ctype_002_A_H__
#define __capi_ctype_002_A_H__
typedef struct {
int i;
int j;
int k;
} Foo;
#endif
#ifndef __capi_ctype_002_B_H__
#define __capi_ctype_002_B_H__
#define f(p) p->j
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment