diff options
author | Simon Marlow <marlowsd@gmail.com> | 2010-07-20 08:28:19 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2010-07-20 08:28:19 +0000 |
commit | 175e79527ad9aee76a0173d7a450093af7eac642 (patch) | |
tree | b2b883e8f9a7a0839d2a9ac87bbac8b867728901 /libraries/base/Foreign | |
parent | 73bd02b6e03ff1fbd508ad222c39f5cbd1c006b2 (diff) | |
download | haskell-175e79527ad9aee76a0173d7a450093af7eac642.tar.gz |
add unsafeLocalState from Haskell 2010, and docs
Diffstat (limited to 'libraries/base/Foreign')
-rw-r--r-- | libraries/base/Foreign/Marshal.hs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/libraries/base/Foreign/Marshal.hs b/libraries/base/Foreign/Marshal.hs index 1daf8ef937..b815122845 100644 --- a/libraries/base/Foreign/Marshal.hs +++ b/libraries/base/Foreign/Marshal.hs @@ -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,26 @@ import Foreign.Marshal.Array import Foreign.Marshal.Error import Foreign.Marshal.Pool import Foreign.Marshal.Utils + +import GHC.IO + +{- | +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 |