From: <as...@us...> - 2003-07-09 22:42:51
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/multiline In directory sc8-pr-cvs1:/tmp/cvs-serv25460/gtk/multiline Modified Files: TextBuffer.chs TextIter.chs TextMark.chs TextTag.chs TextTagTable.chs TextView.chs Log Message: Make compile with GHC 6.00. There are two major changes in the FFI which made me separate everything that has to do with Foreign and Foreign.C into a new file called general/FFI.hs. The file UTFCForeign.hs is now obsolete as its string conversion functions are now in FFI.hs. The nullForeignPtr function is also located here. All files now import FFI instead of Foreign and UTFCForeign. The major changes are: newForeignPtr now takes a pointer to a C function as finalizer. Every destructor function is now defined differently depending on whether the new GHC is used or not. In particular there is now a function called free :: Ptr a -> IO () imported from the Foreign library. In addition to that I defined a function foreignFree which can be used as finalizer to a C data structure. It is equivalent to free if GHC version <=5.04 is used. The second change is that ForeignPtr are no longer accepted as arguments to foreign calls. This change is mainly reflected in c2hs, but also in some files which directly called functions. Index: TextBuffer.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextBuffer.chs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- TextBuffer.chs 8 May 2003 07:25:32 -0000 1.7 +++ TextBuffer.chs 9 Jul 2003 22:42:45 -0000 1.8 @@ -128,13 +128,12 @@ import Monad (liftM) import Maybe (fromMaybe) -import Foreign -import UTFCForeign +import FFI + import GObject (makeNewGObject) {#import Hierarchy#} {#import Signal#} {#import TextIter#} -import Structs (nullForeignPtr) import TextMark (TextMark, MarkName) import TextTag (TextTag, TagName) @@ -177,13 +176,13 @@ -- @ref type TextIter@. -- textBufferInsert :: TextBuffer -> TextIter -> String -> IO () -textBufferInsert tb iter str = withCStringLen str $ \(cStr, len) -> +textBufferInsert tb iter str = withUTFStringLen str $ \(cStr, len) -> {#call text_buffer_insert#} tb iter cStr (fromIntegral len) -- @method textBufferInsertAtCursor@ Insert text at the cursor. -- textBufferInsertAtCursor :: TextBuffer -> String -> IO () -textBufferInsertAtCursor tb str = withCStringLen str $ \(cStr, len) -> +textBufferInsertAtCursor tb str = withUTFStringLen str $ \(cStr, len) -> {#call text_buffer_insert_at_cursor#} tb cStr (fromIntegral len) -- @method textBufferInsertInteractive@ Insert text at the @ref type TextIter@ @@ -197,7 +196,7 @@ -- textBufferInsertInteractive :: TextBuffer -> TextIter -> String -> Bool -> IO Bool -textBufferInsertInteractive tb iter str def = withCStringLen str $ +textBufferInsertInteractive tb iter str def = withUTFStringLen str $ \(cStr, len) -> liftM toBool $ {#call text_buffer_insert_interactive#} tb iter cStr (fromIntegral len) (fromBool def) @@ -205,7 +204,7 @@ -- a normal user would be able to do so as well. -- textBufferInsertInteractiveAtCursor :: TextBuffer -> String -> Bool -> IO Bool -textBufferInsertInteractiveAtCursor tb str def = withCStringLen str $ +textBufferInsertInteractiveAtCursor tb str def = withUTFStringLen str $ \(cStr, len) -> liftM toBool $ {#call text_buffer_insert_interactive_at_cursor #} tb cStr (fromIntegral len) (fromBool def) @@ -256,7 +255,7 @@ -- @ref type TextBuffer@. -- textBufferSetText :: TextBuffer -> String -> IO () -textBufferSetText tb str = withCStringLen str $ \(cStr, len) -> +textBufferSetText tb str = withUTFStringLen str $ \(cStr, len) -> {#call text_buffer_set_text#} tb cStr (fromIntegral len) -- @method textBufferGetText@ Extract all the text between @ref arg start@ and @@ -272,7 +271,7 @@ -- textBufferGetText :: TextBuffer -> TextIter -> TextIter -> Bool -> IO String textBufferGetText tb start end incl = {#call unsafe text_buffer_get_text#} - tb start end (fromBool incl) >>= peekCString + tb start end (fromBool incl) >>= peekUTFString -- @method textBufferGetSlice@ Extract text and special characters between -- @ref arg start@ and @ref arg end@. @@ -284,7 +283,7 @@ -- textBufferGetSlice :: TextBuffer -> TextIter -> TextIter -> Bool -> IO String textBufferGetSlice tb start end incl = {#call unsafe text_buffer_get_slice#} - tb start end (fromBool incl) >>= peekCString + tb start end (fromBool incl) >>= peekUTFString -- @method textBufferInsertPixbuf@ Insert an image into the -- @ref type TextBuffer@. @@ -308,7 +307,7 @@ textBufferCreateMark tb Nothing iter gravity = makeNewGObject mkTextMark $ {#call unsafe text_buffer_create_mark#} tb nullPtr iter (fromBool gravity) textBufferCreateMark tb (Just name) iter gravity = - makeNewGObject mkTextMark $ withCString name $ \cStr -> + makeNewGObject mkTextMark $ withUTFString name $ \cStr -> {#call unsafe text_buffer_create_mark#} tb cStr iter (fromBool gravity) -- @method textBufferMoveMark@ Move a mark. @@ -323,7 +322,7 @@ -- * The mark should exist (otherwise a nasty warning is generated). -- textBufferMoveMarkByName :: TextBuffer -> MarkName -> TextIter -> IO () -textBufferMoveMarkByName tb name iter = withCString name $ \cStr -> +textBufferMoveMarkByName tb name iter = withUTFString name $ \cStr -> {#call text_buffer_move_mark_by_name#} tb cStr iter -- @method textBufferDeleteMark@ Delete a mark. @@ -338,14 +337,14 @@ -- * The mark should exist (otherwise a nasty warning is generated). -- textBufferDeleteMarkByName :: TextBuffer -> MarkName -> IO () -textBufferDeleteMarkByName tb name = withCString name $ \cStr -> +textBufferDeleteMarkByName tb name = withUTFString name $ \cStr -> {#call text_buffer_delete_mark_by_name#} tb cStr -- @method textBufferGetMark@ Retrieve a @ref type TextMark@ by name. -- textBufferGetMark :: TextBuffer -> MarkName -> IO (Maybe TextMark) textBufferGetMark tb name = do - tm <- withCString name $ \cStr -> + tm <- withUTFString name $ \cStr -> {#call unsafe text_buffer_get_mark#} tb cStr if tm==nullPtr then return Nothing else liftM Just $ makeNewGObject mkTextMark (return tm) @@ -389,14 +388,14 @@ -- textBufferApplyTagByName :: TextBuffer -> TagName -> TextIter -> TextIter -> IO () -textBufferApplyTagByName tb tname start end = withCString tname $ \cStr -> +textBufferApplyTagByName tb tname start end = withUTFString tname $ \cStr -> {#call text_buffer_apply_tag_by_name#} tb cStr start end -- @method textBufferRemoveTagByName@ Remove a tag from a range of text. -- textBufferRemoveTagByName :: TextBuffer -> TagName -> TextIter -> TextIter -> IO () -textBufferRemoveTagByName tb tname start end = withCString tname $ \cStr -> +textBufferRemoveTagByName tb tname start end = withUTFString tname $ \cStr -> {#call text_buffer_remove_tag_by_name#} tb cStr start end -- @method textBufferRemoveAllTags@ Remove all tags within a range. @@ -619,12 +618,12 @@ onInsertText tb user = connect_BOXED_PTR_INT__NONE "insert_text" mkTextIter False tb $ \iter strP strLen -> do - str <- peekCStringLen (strP,strLen) + str <- peekUTFStringLen (strP,strLen) user iter str afterInsertText tb user = connect_BOXED_PTR_INT__NONE "insert_text" mkTextIter True tb $ \iter strP strLen -> do - str <- peekCStringLen (strP,strLen) + str <- peekUTFStringLen (strP,strLen) user iter str -- @signal connectToMarkDeleted@ A @ref data TextMark@ within the buffer was Index: TextIter.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextIter.chs,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- TextIter.chs 8 Nov 2002 10:39:21 -0000 1.8 +++ TextIter.chs 9 Jul 2003 22:42:45 -0000 1.9 @@ -1,3 +1,4 @@ +{-# OPTIONS -cpp #-} -- -*-haskell-*- -- GIMP Toolkit (GTK) @entry TextIter TextBuffer@ -- @@ -127,12 +128,11 @@ import Monad (liftM) import Maybe (fromMaybe) import Char (chr) -import Foreign -import UTFCForeign +import FFI import GObject (makeNewGObject) {#import Hierarchy#} {#import Signal#} -import Structs (nullForeignPtr, textIterSize) +import Structs (textIterSize) import Enums (TextSearchFlags, Flags(fromFlags)) {# context lib="gtk" prefix="gtk" #} @@ -145,20 +145,34 @@ -- mkTextIter :: Ptr TextIter -> IO TextIter mkTextIter iterPtr = liftM TextIter $ - newForeignPtr iterPtr (textIterFree iterPtr) + newForeignPtr iterPtr (text_iter_free iterPtr) + +#if __GLASGOW_HASKELL__>=600 + +foreign import ccall unsafe ">k_text_iter_free" + text_iter_free' :: FinalizerPtr TextIter + +text_iter_free :: Ptr TextIter -> FinalizerPtr TextIter +text_iter_free _ = text_iter_free' + +#elif __GLASGOW_HASKELL__>=504 + +foreign import ccall unsafe "gtk_text_iter_free" + text_iter_free :: Ptr TextIter -> IO () + +#else + +foreign import ccall "gtk_text_iter_free" unsafe + text_iter_free :: Ptr TextIter -> IO () + +#endif -- Allocate memory to be filled with a TextIter. -- makeEmptyTextIter :: IO TextIter makeEmptyTextIter = do iterPtr <- mallocBytes textIterSize - liftM TextIter $ newForeignPtr iterPtr (textIterFree iterPtr) - --- Free a TextIter pointer. --- -foreign import ccall "gtk_text_iter_free" unsafe - textIterFree :: Ptr TextIter -> IO () - + liftM TextIter $ newForeignPtr iterPtr (text_iter_free iterPtr) -- @method textIterGetBuffer@ Return the @ref type TextBuffer@ this iterator -- is associated with. @@ -172,7 +186,7 @@ textIterCopy :: TextIter -> IO TextIter textIterCopy ti = do iterPtr <- {#call unsafe text_iter_copy#} ti - liftM TextIter $ newForeignPtr iterPtr (textIterFree iterPtr) + liftM TextIter $ newForeignPtr iterPtr (text_iter_free iterPtr) -- @method textIterGetOffset@ Extract the offset relative to the beginning of -- the buffer. @@ -215,7 +229,7 @@ textIterGetSlice :: TextIter -> TextIter -> IO String textIterGetSlice end start = do cStr <- {#call text_iter_get_slice#} start end - str <- peekCString cStr + str <- peekUTFString cStr {#call unsafe g_free#} (castPtr cStr) return str @@ -226,7 +240,7 @@ textIterGetText :: TextIter -> TextIter -> IO String textIterGetText start end = do cStr <- {#call text_iter_get_text#} start end - str <- peekCString cStr + str <- peekUTFString cStr {#call unsafe g_free#} (castPtr cStr) return str @@ -237,7 +251,7 @@ textIterGetVisibleSlice :: TextIter -> TextIter -> IO String textIterGetVisibleSlice start end = do cStr <- {#call text_iter_get_visible_slice#} start end - str <- peekCString cStr + str <- peekUTFString cStr {#call unsafe g_free#} (castPtr cStr) return str @@ -248,7 +262,7 @@ textIterGetVisibleText :: TextIter -> TextIter -> IO String textIterGetVisibleText start end = do cStr <- {#call text_iter_get_visible_text#} start end - str <- peekCString cStr + str <- peekUTFString cStr {#call unsafe g_free#} (castPtr cStr) return str @@ -742,7 +756,7 @@ textIterForwardSearch ti str flags limit = do start <- makeEmptyTextIter end <- makeEmptyTextIter - found <- liftM toBool $ withCString str $ \cStr -> + found <- liftM toBool $ withUTFString str $ \cStr -> {#call unsafe text_iter_forward_search#} ti cStr ((fromIntegral.fromFlags) flags) start end (fromMaybe (TextIter nullForeignPtr) limit) @@ -762,7 +776,7 @@ textIterBackwardSearch ti str flags limit = do start <- makeEmptyTextIter end <- makeEmptyTextIter - found <- liftM toBool $ withCString str $ \cStr -> + found <- liftM toBool $ withUTFString str $ \cStr -> {#call unsafe text_iter_backward_search#} ti cStr ((fromIntegral.fromFlags) flags) start end (fromMaybe (TextIter nullForeignPtr) limit) Index: TextMark.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextMark.chs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TextMark.chs 5 Aug 2002 16:41:34 -0000 1.4 +++ TextMark.chs 9 Jul 2003 22:42:45 -0000 1.5 @@ -39,8 +39,8 @@ ) where import Monad (liftM) -import Foreign -import UTFCForeign +import FFI + import GObject (makeNewGObject) {#import Hierarchy#} {#import Signal#} @@ -77,7 +77,7 @@ textMarkGetName :: TextMarkClass tm => tm -> IO (Maybe String) textMarkGetName tm = do strPtr <- {#call unsafe text_mark_get_name#} (toTextMark tm) - if strPtr==nullPtr then return Nothing else liftM Just $ peekCString strPtr + if strPtr==nullPtr then return Nothing else liftM Just $ peekUTFString strPtr -- @method textMarkGetBuffer@ Extract the @ref type TextBuffer@ of the mark. -- @@ -100,4 +100,4 @@ {#call unsafe text_mark_get_left_gravity#} (toTextMark tm) - \ No newline at end of file + Index: TextTag.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextTag.chs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TextTag.chs 5 Aug 2002 16:41:34 -0000 1.4 +++ TextTag.chs 9 Jul 2003 22:42:45 -0000 1.5 @@ -33,8 +33,8 @@ ) where import Monad (liftM) -import Foreign -import UTFCForeign +import FFI + import Object (makeNewObject) {#import Hierarchy#} {#import Signal#} Index: TextTagTable.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextTagTable.chs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TextTagTable.chs 5 Aug 2002 16:41:34 -0000 1.4 +++ TextTagTable.chs 9 Jul 2003 22:42:45 -0000 1.5 @@ -34,8 +34,8 @@ ) where import Monad (liftM) -import Foreign -import UTFCForeign +import FFI + import Object (makeNewObject) {#import Hierarchy#} {#import Signal#} Index: TextView.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/multiline/TextView.chs,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- TextView.chs 8 Nov 2002 10:39:21 -0000 1.8 +++ TextView.chs 9 Jul 2003 22:42:45 -0000 1.9 @@ -124,8 +124,8 @@ afterToggleOverwrite) where import Monad (liftM) -import Foreign -import UTFCForeign +import FFI + import Object (makeNewObject) import GObject (makeNewGObject) {#import Hierarchy#} |