From: Duncan C. <dun...@us...> - 2005-12-08 17:31:05
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Gdk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3778/gtk/Graphics/UI/Gtk/Gdk Modified Files: Pixbuf.chs.pp Log Message: Tidy up some low level marshaling stuff, eliminating the use of Foreign.free. FFI.hs.pp: We should almost certainly not be using the standard free function anywhere in the glib or gtk bindings, so we do not re-export it from this module. It is not gueranteed by the Haskell FFI spec that free calls the C free() function. It is also not guaranteed that g_free() simply calls the stanard C free() function. UTFString.hs: call g_free() rather than Haskell free for freeing glib strings (which of course were allocated with g_new()). Pixbuf.chs.pp: use withUTFStringArray and withUTFStringArray0 rather than ad-hoc implementations. StockItems.hsc: use readUTFString rather than peekUTFString + g_free(). GList.chs: add withGSList function. SourceTag.chs: use withGSList and withUTFStrings rather than the more complex exising solution. Index: Pixbuf.chs.pp =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Gdk/Pixbuf.chs.pp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Pixbuf.chs.pp 26 Nov 2005 16:00:21 -0000 1.12 +++ Pixbuf.chs.pp 8 Dec 2005 17:30:55 -0000 1.13 @@ -108,7 +108,6 @@ ) where import Monad (liftM) -import Control.Exception(bracket) import Data.Bits ((.|.), shiftL) import Data.Ix import System.Glib.FFI @@ -378,20 +377,14 @@ checkGError (\errPtrPtr -> withUTFString fname $ \fnPtr -> withUTFString iType $ \tyPtr -> - allocaArray0 optLen $ \keysPtr -> - allocaArray optLen $ \valuesPtr -> do - keyPtrs <- mapM newUTFString keys - valuePtrs <- mapM newUTFString values - pokeArray keysPtr (keyPtrs ++ [nullPtr]) - pokeArray valuesPtr valuePtrs + withUTFStringArray0 keys $ \keysPtr -> + withUTFStringArray values $ \valuesPtr -> do #if defined (WIN32) && GTK_CHECK_VERSION(2,6,5) {# call unsafe pixbuf_savev_utf8 #} #else {# call unsafe pixbuf_savev #} #endif pb fnPtr tyPtr keysPtr valuesPtr errPtrPtr - mapM_ free keyPtrs - mapM_ free valuePtrs return Nothing) (\gerror -> liftM Just $ handlePixbufError gerror) @@ -418,9 +411,8 @@ -- pixbufNewFromXPMData :: [String] -> IO Pixbuf pixbufNewFromXPMData s = - bracket (mapM newUTFString s) (mapM free) $ \strPtrs -> - withArray0 nullPtr strPtrs $ \strsPtr -> - constructNewGObject mkPixbuf $ {#call pixbuf_new_from_xpm_data#} strsPtr + withUTFStringArray0 s $ \strsPtr -> + constructNewGObject mkPixbuf $ {#call pixbuf_new_from_xpm_data#} strsPtr -- | A dymmy type for inline picture data. -- |