On Mon, 2009-10-12 at 11:55 +0100, Duncan Coutts wrote: > I'm getting crazy values returned as the position from > editableInsertText. > > This is using the example from the Editable haddock documentation: > > idRef <- newIORef undefined > id <- onInsertText entry $ \str pos -> do > id <- readIORef idRef > signalBlock id > pos' <- editableInsertText entry (map toUpper str) pos > signalUnblock id > stopInsertText id > return pos' > writeIORef idRef id > > When I run it, the pos' returned is 129475190752018432, when inserting a > string of length 1 at position 1. Looking at the binding code I don't > see anything obviously wrong. This is on 64bit Linux. > > The fact the number is so large is suspicious. The C type is an int > which is still 32bit even on 64bit machines. That said, the types all > look right. c2hs generates the binding with the type Ptr CInt, and we > use with, so it should all be ok. I'm stumped.
Uuuh, funky one. The offending lines were: pos <- peek posPtr pos' <- handler str pos poke posPtr pos' which were located in the signal handler. The handler is actually called with a pointer containing the old position and expects the new position in the pointed-to int on return. However, posPtr is 'Ptr a' and becomes 'Ptr Int' because of the type of 'handler'. So this shows that Haskell Int and CInt are not the same, even though I don't understand how this garbage is produced. Fix: pos <- peek (posPtr :: Ptr {#type gint#}) pos' <- handler str (fromIntegral pos) poke (posPtr :: Ptr {#type gint#}) (fromIntegral pos') Now in darcs, Axel. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gtk2hs-devel mailing list Gtk2hs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel