X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal.hs;h=2c16c018fe622327d02a538a4f32a6b46640a5f0;hb=a50ddaa4f61a3349b7cdecfc2dc8c0ed80795beb;hp=12133e28ddc195bd2827de81266cf897d41763b6;hpb=1c5555c9b71fc8573e0811ae6451df700e3de771;p=ghc-base.git diff --git a/Foreign/Marshal.hs b/Foreign/Marshal.hs index 12133e2..2c16c01 100644 --- a/Foreign/Marshal.hs +++ b/Foreign/Marshal.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -XNoImplicitPrelude #-} ----------------------------------------------------------------------------- -- | -- Module : Foreign.Marshal @@ -14,11 +14,16 @@ ----------------------------------------------------------------------------- module Foreign.Marshal - ( module Foreign.Marshal.Alloc + ( + -- | The module "Foreign.Marshal" re-exports the other modules in the + -- @Foreign.Marshal@ hierarchy: + module Foreign.Marshal.Alloc , module Foreign.Marshal.Array , module Foreign.Marshal.Error , module Foreign.Marshal.Pool , module Foreign.Marshal.Utils + -- | and provides one function: + , unsafeLocalState ) where import Foreign.Marshal.Alloc @@ -26,3 +31,30 @@ import Foreign.Marshal.Array import Foreign.Marshal.Error import Foreign.Marshal.Pool import Foreign.Marshal.Utils + +#ifdef __GLASGOW_HASKELL__ +import GHC.IO +#else +import System.IO.Unsafe +#endif + +{- | +Sometimes an external entity is a pure function, except that it passes +arguments and/or results via pointers. The function +@unsafeLocalState@ permits the packaging of such entities as pure +functions. + +The only IO operations allowed in the IO action passed to +@unsafeLocalState@ are (a) local allocation (@alloca@, @allocaBytes@ +and derived operations such as @withArray@ and @withCString@), and (b) +pointer operations (@Foreign.Storable@ and @Foreign.Ptr@) on the +pointers to local storage, and (c) foreign functions whose only +observable effect is to read and/or write the locally allocated +memory. Passing an IO operation that does not obey these rules +results in undefined behaviour. + +It is expected that this operation will be +replaced in a future revision of Haskell. +-} +unsafeLocalState :: IO a -> a +unsafeLocalState = unsafePerformIO