Update of /cvsroot/gtk2hs/gtk2hs/gtk/general
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26699/gtk/general
Modified Files:
FFI.hs
Log Message:
Moved a couple of useful string marshaling functions to a common location.
Index: FFI.hs
===================================================================
RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/general/FFI.hs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- FFI.hs 23 May 2004 15:58:48 -0000 1.3
+++ FFI.hs 3 Aug 2004 02:36:39 -0000 1.4
@@ -36,6 +36,8 @@
newUTFStringLen,
peekUTFString,
peekUTFStringLen,
+ readUTFString,
+ readCString,
newForeignPtr,
foreignPtrToPtr,
module Foreign,
@@ -83,7 +85,7 @@
#endif
#if __GLASGOW_HASKELL__>=600
-foreign import ccall unsafe "&free"
+foreign import ccall unsafe "&free" --TODO: should we be using g_free?
free' :: FinalizerPtr a
foreignFree :: Ptr a -> FinalizerPtr a
@@ -130,6 +132,22 @@
peekUTFStringLen :: CStringLen -> IO String
peekUTFStringLen strPtr = liftM fromUTF $ peekCStringLen strPtr
+-- like peekUTFString but then frees the string using g_free
+--
+readUTFString :: CString -> IO String
+readUTFString strPtr = do
+ str <- peekUTFString strPtr
+ free (castPtr strPtr)
+ return str
+
+-- like peekCString but then frees the string using g_free
+--
+readCString :: CString -> IO String
+readCString strPtr = do
+ str <- peekCString strPtr
+ free (castPtr strPtr)
+ return str
+
-- Convert Unicode characters to UTF-8.
--
toUTF :: String -> String
|