Update of /cvsroot/gtk2hs/gtk2hs/glib/System/Glib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1483/glib/System/Glib
Modified Files:
FFI.hs
Log Message:
Add maybeNull function which is used by marshaling functions to help marshal
values that might be NULL into a Maybe type where NULL gets mapped to Nothing.
Index: FFI.hs
===================================================================
RCS file: /cvsroot/gtk2hs/gtk2hs/glib/System/Glib/FFI.hs,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- FFI.hs 16 Jan 2005 21:29:41 -0000 1.2
+++ FFI.hs 15 Mar 2005 19:45:01 -0000 1.3
@@ -28,6 +28,7 @@
module System.Glib.FFI (
with,
nullForeignPtr,
+ maybeNull,
foreignFree,
newForeignPtr,
foreignPtrToPtr,
@@ -77,3 +78,12 @@
foreignFree = free
#endif
+-- A marshaling utility function that is used by the code produced by the code
+-- generator to marshal return values that can be null
+maybeNull :: (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
+maybeNull marshal genPtr = do
+ ptr <- genPtr
+ if ptr == nullPtr
+ then return Nothing
+ else do result <- marshal (return ptr)
+ return (Just result)
|