diff options
-rw-r--r-- | testsuite/tests/ffi/should_run/Capi_Ctype_002.hs | 19 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/Capi_Ctype_002.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/Capi_Ctype_A_002.hsc | 28 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/Makefile | 8 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/all.T | 6 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/capi_ctype_002_A.h | 12 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/capi_ctype_002_B.h | 8 |
7 files changed, 82 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/Capi_Ctype_002.hs b/testsuite/tests/ffi/should_run/Capi_Ctype_002.hs new file mode 100644 index 0000000000..4868ee28b7 --- /dev/null +++ b/testsuite/tests/ffi/should_run/Capi_Ctype_002.hs @@ -0,0 +1,19 @@ + +{-# 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 + diff --git a/testsuite/tests/ffi/should_run/Capi_Ctype_002.stdout b/testsuite/tests/ffi/should_run/Capi_Ctype_002.stdout new file mode 100644 index 0000000000..1e8b314962 --- /dev/null +++ b/testsuite/tests/ffi/should_run/Capi_Ctype_002.stdout @@ -0,0 +1 @@ +6 diff --git a/testsuite/tests/ffi/should_run/Capi_Ctype_A_002.hsc b/testsuite/tests/ffi/should_run/Capi_Ctype_A_002.hsc new file mode 100644 index 0000000000..14da1144b6 --- /dev/null +++ b/testsuite/tests/ffi/should_run/Capi_Ctype_A_002.hsc @@ -0,0 +1,28 @@ + +{-# 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) + diff --git a/testsuite/tests/ffi/should_run/Makefile b/testsuite/tests/ffi/should_run/Makefile index 8b5a9a556d..25a8db902c 100644 --- a/testsuite/tests/ffi/should_run/Makefile +++ b/testsuite/tests/ffi/should_run/Makefile @@ -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 + diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T index 1b61b345bc..e24472c027 100644 --- a/testsuite/tests/ffi/should_run/all.T +++ b/testsuite/tests/ffi/should_run/all.T @@ -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']) + diff --git a/testsuite/tests/ffi/should_run/capi_ctype_002_A.h b/testsuite/tests/ffi/should_run/capi_ctype_002_A.h new file mode 100644 index 0000000000..26928a3436 --- /dev/null +++ b/testsuite/tests/ffi/should_run/capi_ctype_002_A.h @@ -0,0 +1,12 @@ + +#ifndef __capi_ctype_002_A_H__ +#define __capi_ctype_002_A_H__ + +typedef struct { + int i; + int j; + int k; +} Foo; + +#endif + diff --git a/testsuite/tests/ffi/should_run/capi_ctype_002_B.h b/testsuite/tests/ffi/should_run/capi_ctype_002_B.h new file mode 100644 index 0000000000..6928290f47 --- /dev/null +++ b/testsuite/tests/ffi/should_run/capi_ctype_002_B.h @@ -0,0 +1,8 @@ + +#ifndef __capi_ctype_002_B_H__ +#define __capi_ctype_002_B_H__ + +#define f(p) p->j + +#endif + |