<commit_before>-- Tests ForeignPtrEnv finalizers

import Text.Printf
import Foreign.ForeignPtr
import Foreign
import GHC.TopHandler
import Control.Concurrent
import Data.List
import System.Mem

foreign export ccall fin :: Ptr Int -> Ptr Int -> IO ()
foreign import ccall "&fin" finptr :: FinalizerEnvPtr Int Int

fin :: Ptr Int -> Ptr Int -> IO ()
fin envp ap = runIO $ do
  env <- peek envp
  a <- peek ap
  printf "%d %d\n" env a
  return ()

main = do
  a   <- new (55 :: Int)
  env <- new (66 :: Int)
  fp  <- newForeignPtrEnv finptr env a
  performGC
  threadDelay 100000
<commit_msg>Fix this test: it was using a C finalizer that called back into Haskell Which isn't allowed using the ordinary newForeignPtr any more, it has to be done with Foreign.Concurrent.newForeignPtr.<commit_after>-- Tests Foreign.Concurrent finalizers

import Text.Printf
import Foreign.Concurrent as Conc
import Foreign
import GHC.TopHandler
import Control.Concurrent
import Data.List
import System.Mem

-- This finalizer calls back into Haskell, so we can't use
-- the ordinary newForeignPtr.
foreign export ccall fin :: Ptr Int -> Ptr Int -> IO ()
foreign import ccall "fin" finptr :: Ptr Int -> Ptr Int -> IO ()

fin :: Ptr Int -> Ptr Int -> IO ()
fin envp ap = runIO $ do
  env <- peek envp
  a <- peek ap
  printf "%d %d\n" env a
  return ()

main = do
  a   <- new (55 :: Int)
  env <- new (66 :: Int)
  fp  <- Conc.newForeignPtr a (fin env a)
  performGC
  threadDelay 100000

{'fraction_non_alphanumeric': 0.09692832764505119, 'fraction_numerical': 0.013651877133105802, 'mean_word_length': 3.2740524781341107, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5007365', 'n_tokens_mistral': 499, 'n_tokens_neox': 460, 'n_words': 199}