Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Unsafe #-}{-# LANGUAGE NoImplicitPrelude , MagicHash , UnboxedTuples #-}{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module : GHC.Stable-- Copyright : (c) The University of Glasgow, 1992-2004-- License : see libraries/base/LICENSE---- Maintainer : ffi@haskell.org-- Stability : internal-- Portability : non-portable (GHC Extensions)---- Stable pointers.-------------------------------------------------------------------------------moduleGHC.Stable(StablePtr(..),newStablePtr,deRefStablePtr,freeStablePtr,castStablePtrToPtr,castPtrToStablePtr)whereimportGHC.PtrimportGHC.Base------------------------------------------------------------------------------- Stable Pointers{- |A /stable pointer/ is a reference to a Haskell expression that isguaranteed not to be affected by garbage collection, i.e., it will neither bedeallocated nor will the value of the stable pointer itself change duringgarbage collection (ordinary references may be relocated during garbagecollection). Consequently, stable pointers can be passed to foreign code,which can treat it as an opaque reference to a Haskell value.A value of type @StablePtr a@ is a stable pointer to a Haskellexpression of type @a@.-}data{-# CTYPE"HsStablePtr"#-}StablePtra=StablePtr(StablePtr#a)-- |-- Create a stable pointer referring to the given Haskell value.--newStablePtr::a->IO(StablePtra)newStablePtra=IO$\s->casemakeStablePtr#asof(#s',sp#)->(#s',StablePtrsp#)-- |-- Obtain the Haskell value referenced by a stable pointer, i.e., the-- same value that was passed to the corresponding call to-- 'makeStablePtr'. If the argument to 'deRefStablePtr' has-- already been freed using 'freeStablePtr', the behaviour of-- 'deRefStablePtr' is undefined.--deRefStablePtr::StablePtra->IOadeRefStablePtr(StablePtrsp)=IO$\s->deRefStablePtr#sps-- |-- Dissolve the association between the stable pointer and the Haskell-- value. Afterwards, if the stable pointer is passed to-- 'deRefStablePtr' or 'freeStablePtr', the behaviour is-- undefined. However, the stable pointer may still be passed to-- 'castStablePtrToPtr', but the @'Foreign.Ptr.Ptr' ()@ value returned-- by 'castStablePtrToPtr', in this case, is undefined (in particular,-- it may be 'Foreign.Ptr.nullPtr'). Nevertheless, the call-- to 'castStablePtrToPtr' is guaranteed not to diverge.--foreignimportccallunsafe"hs_free_stable_ptr"freeStablePtr::StablePtra->IO()-- |-- Coerce a stable pointer to an address. No guarantees are made about-- the resulting value, except that the original stable pointer can be-- recovered by 'castPtrToStablePtr'. In particular, the address may not-- refer to an accessible memory location and any attempt to pass it to-- the member functions of the class 'Foreign.Storable.Storable' leads to-- undefined behaviour.--castStablePtrToPtr::StablePtra->Ptr()castStablePtrToPtr(StablePtrs)=Ptr(unsafeCoerce#s)-- |-- The inverse of 'castStablePtrToPtr', i.e., we have the identity---- > sp == castPtrToStablePtr (castStablePtrToPtr sp)---- for any stable pointer @sp@ on which 'freeStablePtr' has-- not been executed yet. Moreover, 'castPtrToStablePtr' may-- only be applied to pointers that have been produced by-- 'castStablePtrToPtr'.--castPtrToStablePtr::Ptr()->StablePtracastPtrToStablePtr(Ptra)=StablePtr(unsafeCoerce#a)-- | @since 2.01instanceEq(StablePtra)where(StablePtrsp1)==(StablePtrsp2)=caseeqStablePtr#sp1sp2of0#->False_->True
[8]ページ先頭