diff options
Diffstat (limited to 'testsuite/tests/lib/should_run/stableptr001.hs')
-rw-r--r-- | testsuite/tests/lib/should_run/stableptr001.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/testsuite/tests/lib/should_run/stableptr001.hs b/testsuite/tests/lib/should_run/stableptr001.hs new file mode 100644 index 0000000000..1bc857aba6 --- /dev/null +++ b/testsuite/tests/lib/should_run/stableptr001.hs @@ -0,0 +1,19 @@ + +module Main where + +import Foreign + +-- simple test for building/dereferencing stable ptrs + +main + = do l <- mapM newStablePtr [1..100000] + sum <- stable_sum l + print sum + +stable_sum :: [StablePtr Integer] -> IO Integer +stable_sum [] = return 0 +stable_sum (x:xs) + = do x' <- deRefStablePtr x + freeStablePtr x + xs' <- stable_sum xs + return (x' + xs') |