~ubuntu-branches/ubuntu/precise/ghc/precise

« back to all changes in this revision

Viewing changes to libraries/haskell2010/Foreign/Marshal.hs

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-01-17 12:49:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110117124924-do1pym1jlf5o636m
Tags: upstream-7.0.1
ImportĀ upstreamĀ versionĀ 7.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Foreign.Marshal (
 
2
         -- | The module "Foreign.Marshal" re-exports the other modules in the
 
3
         -- @Foreign.Marshal@ hierarchy:
 
4
 
 
5
         module Foreign.Marshal.Alloc,
 
6
         module Foreign.Marshal.Array,
 
7
         module Foreign.Marshal.Error,
 
8
        -- Not in Haskell 2010:
 
9
        -- , module Foreign.Marshal.Pool
 
10
         module Foreign.Marshal.Utils,
 
11
         -- | and provides one function:
 
12
         unsafeLocalState
 
13
  ) where
 
14
 
 
15
import "this" Foreign.Marshal.Alloc
 
16
import "this" Foreign.Marshal.Array
 
17
import "this" Foreign.Marshal.Error
 
18
-- Not in Haskell 2010:
 
19
-- import "this" Foreign.Marshal.Pool
 
20
import "this" Foreign.Marshal.Utils
 
21
 
 
22
import "base" System.IO.Unsafe
 
23
 
 
24
{- |
 
25
Sometimes an external entity is a pure function, except that it passes
 
26
arguments and/or results via pointers.  The function
 
27
@unsafeLocalState@ permits the packaging of such entities as pure
 
28
functions.  
 
29
 
 
30
The only IO operations allowed in the IO action passed to
 
31
@unsafeLocalState@ are (a) local allocation (@alloca@, @allocaBytes@
 
32
and derived operations such as @withArray@ and @withCString@), and (b)
 
33
pointer operations (@Foreign.Storable@ and @Foreign.Ptr@) on the
 
34
pointers to local storage, and (c) foreign functions whose only
 
35
observable effect is to read and/or write the locally allocated
 
36
memory.  Passing an IO operation that does not obey these rules
 
37
results in undefined behaviour.
 
38
 
 
39
It is expected that this operation will be
 
40
replaced in a future revision of Haskell.
 
41
-}
 
42
unsafeLocalState :: IO a -> a
 
43
unsafeLocalState = unsafePerformIO