Eric Y. Kow wrote: > Here's my implementation of it. Does it look sane to you? Any comments > from wxhaskell developers? > > withImageData :: Image a -> (Ptr () -> IO b) -> IO b > withImageData image f = do > pixels <- imageGetData image > x <- f pixels > x `seq` image `seq` return x > > The seqs are there out of pure superstition (i.e. Eric doesn't know how > Haskell works); basically, I want to make sure we're holding on to image > as long as we need to, so at least until we know what 'x' is.
The x `seq` is likely pointless. "x" is a pure value and unless someone's cheating with unsafePerformIO, merely forcing a pure value can't cause any Ptr access to happen. the image `seq` looks like a reasonable hack to keep image alive. The canonical way would be "touchForeignPtr image" or to use "withForeignPtr image", except that image isn't a ForeignPtr exactly. I don't know if there is a good way to access the ForeignPtr inside image because I haven't grokked enough of wx yet. See http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-ForeignPtr.html for these and related issues. > > If this is indeed sane, we could stick it in wxcore and put a big > warning on the Haddocks for imageGetData (without removing it just > yet). And fix imageGetPixels to use the new safe withImageData. Which would have made my bug go away. Jules ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ wxhaskell-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wxhaskell-users
