#1364: Finalizers not guaranteed to run before the program exits
-----------------------------------+----------------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.6.1
Severity: normal | Keywords:
Difficulty: Unknown | Os: Unknown
Testcase: | Architecture: Unknown
-----------------------------------+----------------------------------------
In the following code (compiled with compiled with ghc --make -fffi
-fvia-c Test.hs) the finalizer never gets called, even after replacing
printf with something else:
Test.hs:
{{{
module Main where
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Marshal.Utils
foreign import ccall safe "ctest.h &ctest" ctestPtr :: FunPtr (Ptr Int ->
IO ())
test :: Int -> IO ()
test i = with i test'
where
test' ptr = do fptr <- newForeignPtr ctestPtr ptr
putStrLn "test"
main = do putStrLn "before test..."
test 33
putStrLn "after test..."
}}}
ctest.h:
{{{
#include <stdio.h>
static inline void ctest( int *i )
{
printf( "finalizer called with: %d\n", *i );
}
}}}
I've asked about this on IRC and the Haskell Cafe mailing list and
received confirmation that in GHC there is no guarantee that finalizers
will run before the program exits:
http://www.haskell.org/pipermail/haskell-cafe/2007-May/025458.html
The FFI addendum to the Haskell 98 report states in section 5.5 that "The
only guarantee [for finalizers] is that the finalizer runs before the
program terminates".
The same statement is made in GHC documentation for newForeignPtr.
This could be a bug or merely a documentation issue but something should
probably be done about it.
I suspect it's a bug considering the guarantee specified in the FFI
addendum isn't met.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1364>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs