The following program causes SIGSEGV after a few thousands of
iterations.
I compile with 'ghc test2.hs -o test2 -fglasgow-exts' by ghc-4.06 on
Linux, gcc-2.95.1, glibc-2.1.2. With ghc-4.04 it crashes too.
------------------------------------------------------------------------
import Addr
import Weak
kill:: Addr -> IO ()
kill a = do
w <- mkWeakPtr a Nothing
addFinalizer a $
deRefWeak w >> return ()
main:: IO ()
main = sequence_ . repeat $
malloc 100 >>= kill >> putStrLn "x"
foreign import malloc :: Int -> IO Addr
------------------------------------------------------------------------
(Am I using weak pointers and finalizers in a legal way?
I want the finalizer itself not to hold the reference.)
The program is extremely sensitive to details. Even altering the
message printed, or the amount of memory mallocated, or replacing
"a >> b" with "do a; b" changes the behavior. It sometimes crashes
only when I press Ctrl-C. Often it crashes in the function evacuate
trying to access memory at the pointer like 0x50052. I hope you will
be able to reproduce and fix it.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-