From: Chris K. <ha...@li...> - 2010-06-04 19:04:59
|
Any ideas why this could be dying? I have tracked down where the Segmentation Fault is being emitted from. The new test case has a traced version of layoutGetDrawWindow and makeNewGObject' showing the problem is triggered in objectRef: > -- The Graphics.UI.Gtk.Types is usually hidden, I modified gtk.cabal to expose it > import Graphics.UI.Gtk.Types(objectRef,objectUnrefFromMainloop,unLayout > ,DrawWindow(DrawWindow)) > import Graphics.UI.Gtk(initGUI,windowNew,layoutNew,layoutGetDrawWindow,containerAdd,widgetShowAll,mainIteration > ,GObjectClass,Layout) > import Foreign(newForeignPtr,withForeignPtr,nullPtr,peekByteOff,castPtr > ,FinalizerPtr,ForeignPtr,Ptr) > import Control.Exception(evaluate) > import Control.Monad(when) > import Debug.Trace(trace) > > makeNewGObject' :: GObjectClass obj > => (ForeignPtr obj -> obj, FinalizerPtr obj) -- ^ constructor for the Haskell object and finalizer C function > -> IO (Ptr obj) -- ^ action which yields a pointer to the C object > -> IO obj > makeNewGObject' (constr, objectUnref) generator = trace "makeNewGObject' evaluated" $ do > trace "makeNewGObject' running" $ do > objPtr <- generator > trace ("generator returned "++show objPtr) $ do > when (objPtr == nullPtr) (fail "makeNewGObject: object is NULL") > trace ("before objectRef "++show objPtr) $ do > objectRef objPtr > -- obj <- newForeignPtr objPtr objectUnref > trace ("before newForeignPtr "++show objPtr) $ do > obj <- flip newForeignPtr objPtr objectUnref > trace ("before constr"++show obj) $ do > thing <- evaluate (constr obj) > trace ("made thing") $ do > return thing > > mkDrawWindow' = trace "mkDrawWindow'" (dw'', o') > where dw' x = trace ("my DrawWindow "++show x) $ DrawWindow x > dw''= trace ("trace dw'") dw' > o' = trace ("trace objectUnrefFromMainloop") objectUnrefFromMainloop > > layoutGetDrawWindow' :: Layout -> IO DrawWindow > layoutGetDrawWindow' lay = makeNewGObject' (trace "hi" mkDrawWindow') $ trace "operate" $ > withForeignPtr (unLayout lay) $ \lay' -> do > trace (show lay') $ do > bin_window <- peekByteOff lay' 144 > trace (show bin_window) $ do > return (castPtr bin_window) > > main = do > initGUI > window <- windowNew > layout <- layoutNew Nothing Nothing > containerAdd window layout > widgetShowAll window > b <- mainIteration > trace (show b) $ do > dw <- layoutGetDrawWindow' layout > return () The output produced is > shell> ghc --make trim2.hs && ./trim2 > [1 of 1] Compiling Main ( trim2.hs, trim2.o ) > Linking trim2 ... > Xlib: extension "RANDR" missing on display "/tmp/launch-UrBjlu/org.x:0". > True > hi > mkDrawWindow' > makeNewGObject' evaluated > makeNewGObject' running > operate > 0x02061818 > 0x0145a80d > generator returned 0x0145a80d > before objectRef 0x0145a80d > Segmentation fault The glib-0.11.0/dist/build/System/Glib/GObject.hs contains objectRef as: > -- | Increase the reference counter of an object > -- > objectRef :: GObjectClass obj => Ptr obj -> IO () > objectRef obj = do > g_object_ref (castPtr obj) > return () > > foreign import ccall unsafe "g_object_ref" > g_object_ref :: ((Ptr ()) -> (IO (Ptr ()))) Any ideas why this could be dying? |