16 Aug 2000 12:26:43 GMT, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> pisze:
> Libraries could even use pointers instead of ForeignObj.
Currently it's indeed simpler for e.g. stat. ForeignObj provides
nothing because struct stat is almost not used from C functions:
------------------------------------------------------------------------
newtype FileStatus = FS (Ptr ())
getFileStatus:: FilePath -> IO FileStatus
getFileStatus name = do
ptr <- autoPtrToBytes (#const sizeof (struct stat))
call (throwIf_1 "stat" stat) name ptr :: IO CInt
return (FS ptr)
foreign import unsafe stat :: CString -> Ptr () -> IO CInt
fileOwner:: FileStatus -> UserID
fileOwner (FS ptr) = unsafePerformIO $ hold ptr $
(#peek struct stat, st_uid) ptr
------------------------------------------------------------------------
autoPtrTo* functions have the same interface as malloc* but the memory
is freed automatically when unreachable from Haskell.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK