From: <as...@us...> - 2003-11-02 23:57:10
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/glib In directory sc8-pr-cvs1:/tmp/cvs-serv30179 Modified Files: GList.chs Log Message: Added marshalling functions to create GLists and GSLists. Index: GList.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/glib/GList.chs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- GList.chs 9 Jul 2003 22:42:44 -0000 1.7 +++ GList.chs 2 Nov 2003 23:57:07 -0000 1.8 @@ -19,27 +19,27 @@ -- -- @description@ -------------------------------------------------------------- -- --- * Define functions to extract data from a GList and to produce a GList from +-- * Defines functions to extract data from a GList and to produce a GList from -- a list of pointers. -- --- * Define functions to extract data from a GSList. +-- * The same for GSList. -- -- @documentation@ ------------------------------------------------------------ -- -- -- @todo@ --------------------------------------------------------------------- -- --- * Figure out if we ever need to generate a GList. -- module GList( ptrToInt, GList, fromGList, - -- toGList, + toGList, GSList, readGSList, fromGSList, - fromGSListRev + fromGSListRev, + toGSList ) where import Monad (liftM) @@ -117,11 +117,23 @@ -- Turn a list of something into a GList. -- -toGList :: [a] -> (a -> Ptr b) -> IO GList -toGList xs conv = makeList nullPtr xs +toGList :: [Ptr a] -> IO GList +toGList xs = makeList nullPtr xs where - -- makeList :: GList -> [a] -> IO GList + -- makeList :: GList -> [Ptr a] -> IO GList makeList current (x:xs) = do - newHead <- {#call unsafe list_prepend#} current ((castPtr.conv) x) + newHead <- {#call unsafe list_prepend#} current (castPtr x) makeList newHead xs makeList current [] = return current + +-- Turn a list of something into a GSList. +-- +toGSList :: [Ptr a] -> IO GSList +toGSList xs = makeList nullPtr xs + where + -- makeList :: GSList -> [Ptr a] -> IO GSList + makeList current (x:xs) = do + newHead <- {#call unsafe slist_prepend#} current (castPtr x) + makeList newHead xs + makeList current [] = return current + |