> > ForeignObjs are unnecessary! Long live addFinalizer! > > Um, there's a problem with addFinalizer. So we stick with addFinalizer for now. As I need to reimplement GdkGC for the Gtk+HS binding right now, I have a question concering if the following code is what the 'touch' function should look like: newtype GC = GC ForeignObj mkGC :: Addr -> IO GC mkGC addr = liftM GC $ newForeignObj (gcUnref addr) addr unGC :: GC -> Addr unGC (GC fObj) = foreignObjToAddr fObj touchGC GC -> IO () touchGC (GC fObj) = seq fObj (return ()) A GC is a structure in C land which should be freed when the GC data type is garbage collected in Haskell. If we use unGC, we need to touchGC the GC to make sure it will still be there: gcCopy :: Window -> GC -> IO GC gcCopy win source = do dest <- gcNew win {#call unsafe gc_copy#} (unGC dest) (unGC source) touchGC source return dest A general touch function could be touch :: a -> IO () touch a = seq a (return ()) if 'a' is some kind of newtype (like above) or touch :: (Eq a) => a -> IO () touch a = seq (a==a) (return ()) otherwise (though this is slow and probably not necessary). Wasn't there some talk about a primitive? Why? Cheers, Axel.
- RE: Accessing ForeignObj contents from Haskell Simon Marlow
- Re: Accessing ForeignObj contents from Hask... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj contents from ... Manuel M. T. Chakravarty
- RE: Accessing ForeignObj contents from Haskell Simon Marlow
- Re: Accessing ForeignObj contents from Hask... Keith Wansbrough
- Re: Accessing ForeignObj contents from ... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj contents from Hask... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj contents from ... Manuel M. T. Chakravarty
- Re: Accessing ForeignObj contents f... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj conten... Manuel M. T. Chakravarty
- Re: Accessing ForeignObj contents from Hask... Axel Simon
- Re: Accessing ForeignObj contents from ... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj contents from ... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj contents f... Manuel M. T. Chakravarty
- Re: Accessing ForeignObj conten... Marcin 'Qrczak' Kowalczyk
- Re: Accessing ForeignObj c... Manuel M. T. Chakravarty
- Re: Accessing ForeignO... Marcin 'Qrczak' Kowalczyk
- RE: Accessing ForeignObj contents from ... Manuel M. T. Chakravarty
- RE: Accessing ForeignObj contents from Haskell Simon Marlow
- RE: Accessing ForeignObj contents from Hask... Manuel M. T. Chakravarty
- Re: Accessing ForeignObj contents from ... Marcin 'Qrczak' Kowalczyk