From 6c4b80ee576d2153f8b9bad9ebbbe9eb3fe22116 Mon Sep 17 00:00:00 2001 From: simonmar <unknown> Date: Tue, 5 Sep 2000 12:35:09 +0000 Subject: [PATCH] [project @ 2000-09-05 12:35:09 by simonmar] Use newtype Ptr instead of just Addr, test newtypes in foreign decls. --- ghc/tests/ccall/should_run/fed001.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ghc/tests/ccall/should_run/fed001.hs b/ghc/tests/ccall/should_run/fed001.hs index 22a43521eb8e..be0852c3b901 100644 --- a/ghc/tests/ccall/should_run/fed001.hs +++ b/ghc/tests/ccall/should_run/fed001.hs @@ -1,16 +1,24 @@ import Foreign import Monad +newtype Ptr a = Ptr Addr +unPtr (Ptr x) = x + type CInt = Int32 type CSize = Word32 -foreign export dynamic mkComparator :: (Addr -> Addr -> IO CInt) -> IO Addr -foreign import qsort :: Addr -> CSize -> CSize -> Addr -> IO () +foreign export dynamic + mkComparator :: (Ptr Int -> Ptr Int -> IO CInt) + -> IO (Ptr (Ptr Int -> Ptr Int -> IO CInt)) + +foreign import + qsort :: Addr -> CSize -> CSize -> Ptr (Ptr Int -> Ptr Int -> IO CInt) + -> IO () -compareInts :: Addr -> Addr -> IO CInt +compareInts :: Ptr Int -> Ptr Int -> IO CInt compareInts a1 a2 = do - i1 <- peek a1 - i2 <- peek a2 + i1 <- peek (unPtr a1) + i2 <- peek (unPtr a2) return (fromIntegral (i1 - i2 :: Int)) main :: IO () -- GitLab