Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ara Adkins
Glasgow Haskell Compiler
Commits
d12525bd
Commit
d12525bd
authored
Mar 30, 2004
by
panne
Browse files
[project @ 2004-03-30 07:05:46 by panne]
Added withArrayLen and withArrayLen0
parent
edde7161
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/base/Foreign/Marshal/Array.hs
View file @
d12525bd
...
...
@@ -44,6 +44,9 @@ module Foreign.Marshal.Array (
withArray
,
-- :: Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray0
,
-- :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
withArrayLen
,
-- :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen0
,
-- :: Storable a => a -> [a] -> (Int -> Ptr a -> IO b) -> IO b
-- ** Copying
-- | (argument order: destination, source)
...
...
@@ -189,22 +192,33 @@ newArray0 marker vals = do
-- |Temporarily store a list of storable values in memory
--
withArray
::
Storable
a
=>
[
a
]
->
(
Ptr
a
->
IO
b
)
->
IO
b
withArray
vals
f
=
withArray
::
Storable
a
=>
[
a
]
->
(
Ptr
a
->
IO
b
)
->
IO
b
withArray
vals
=
withArrayLen
vals
.
const
-- |Like 'withArray', but the action gets the number of values
-- as an additional parameter
--
withArrayLen
::
Storable
a
=>
[
a
]
->
(
Int
->
Ptr
a
->
IO
b
)
->
IO
b
withArrayLen
vals
f
=
allocaArray
len
$
\
ptr
->
do
pokeArray
ptr
vals
res
<-
f
ptr
res
<-
f
len
ptr
return
res
where
len
=
length
vals
-- |Like 'withArray', but a terminator indicates where the array ends
--
withArray0
::
Storable
a
=>
a
->
[
a
]
->
(
Ptr
a
->
IO
b
)
->
IO
b
withArray0
marker
vals
f
=
withArray0
::
Storable
a
=>
a
->
[
a
]
->
(
Ptr
a
->
IO
b
)
->
IO
b
withArray0
marker
vals
=
withArrayLen0
marker
vals
.
const
-- |Like 'withArrayLen', but a terminator indicates where the array ends
--
withArrayLen0
::
Storable
a
=>
a
->
[
a
]
->
(
Int
->
Ptr
a
->
IO
b
)
->
IO
b
withArrayLen0
marker
vals
f
=
allocaArray0
len
$
\
ptr
->
do
pokeArray0
marker
ptr
vals
res
<-
f
ptr
res
<-
f
len
ptr
return
res
where
len
=
length
vals
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment