Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/FFI/StablePtr.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module NHC.FFI
  ( StablePtr		-- abstract
  , newStablePtr	-- :: a -> IO (StablePtr a)
  , deRefStablePtr	-- :: StablePtr a -> IO a
  , freeStablePtr	-- :: StablePtr a -> IO ()
  , castStablePtrToPtr	-- :: StablePtr a -> Ptr ()
  , castPtrToStablePtr	-- :: Ptr () -> StablePtr a
  ) where

import Ptr
import Storable

data StablePtr a

foreign import ccall "makeStablePtr"  newStablePtr   :: a -> IO (StablePtr a)
foreign import ccall "derefStablePtr" deRefStablePtr :: StablePtr a -> IO a
foreign import ccall "freeStablePtr"  freeStablePtr  :: StablePtr a -> IO ()

foreign import cast castStablePtrToPtr :: StablePtr a -> Ptr ()
foreign import cast castPtrToStablePtr :: Ptr () -> StablePtr a

instance Storable (StablePtr a) where
  sizeOf    = const 4
  alignment = const 4
  peek p    = do v <- peek (castPtr p); return (castPtrToStablePtr v)
  poke p x  = do poke (castPtr p) (castStablePtrToPtr x)

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.