Skip to content

Commit 8ef2945

Browse files
authored
Prepare changelog for 0.9.1.0
Also, add mutableByteArrayAsForeignPtr for symmetry with byteArrayAsForeignPtr.
1 parent 4b2de72 commit 8ef2945

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Data/Primitive/ByteArray.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module Data.Primitive.ByteArray (
6363
isByteArrayPinned, isMutableByteArrayPinned,
6464
#endif
6565
byteArrayAsForeignPtr,
66+
mutableByteArrayAsForeignPtr,
6667
byteArrayContents,
6768
withByteArrayContents,
6869
mutableByteArrayContents,
@@ -130,11 +131,21 @@ newAlignedPinnedByteArray (I# n#) (I# k#)
130131

131132
-- | Create a foreign pointer that points to the array's data. This operation
132133
-- is only safe on /pinned/ byte arrays. The array's data is not garbage
133-
-- collected while references to the foreign pointer exist.
134+
-- collected while references to the foreign pointer exist. Writing to the
135+
-- array through the foreign pointer results in undefined behavior.
134136
byteArrayAsForeignPtr :: ByteArray -> ForeignPtr Word8
135137
{-# INLINE byteArrayAsForeignPtr #-}
136138
byteArrayAsForeignPtr (ByteArray arr#) = ForeignPtr (byteArrayContents# arr#) (PlainPtr (unsafeCoerce# arr#))
137139

140+
141+
-- | Variant of 'byteArrayAsForeignPtr' for mutable byte arrays. Similarly, this
142+
-- is only safe on /pinned/ mutable byte arrays. This function differs from the
143+
-- variant for immutable arrays in that it is safe to write to the array though
144+
-- the foreign pointer.
145+
mutableByteArrayAsForeignPtr :: MutableByteArray RealWorld -> ForeignPtr Word8
146+
{-# INLINE mutableByteArrayAsForeignPtr #-}
147+
mutableByteArrayAsForeignPtr (MutableByteArray arr#) = ForeignPtr (mutableByteArrayContentsShim arr#) (PlainPtr arr#)
148+
138149
-- | Yield a pointer to the array's data. This operation is only safe on
139150
-- /pinned/ byte arrays. Byte arrays allocated by 'newPinnedByteArray' and
140151
-- 'newAlignedPinnedByteArray' are guaranteed to be pinned. Byte arrays

changelog.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
## Changes in version 0.9.1.0
2-
* Add `byteArrayAsForeignPtr`.
2+
3+
* Make fromListN functions good consumers for list fusion.
4+
5+
* Add functions to improve `MutVar`'s interoperability with `IORef` and `STRef`.
6+
7+
* Add `createPrimArray` and `createByteArray`.
8+
9+
* Add `byteArrayAsForeignPtr` and `mutableByteArrayAsForeignPtr`.
10+
11+
* Use `copyMutableByteArrayNonOverlapping#` in the implementation of `copyMutableByteArray`
12+
on sufficiently new GHCs. This does not change the contract for `copyMutableByteArray`.
13+
This function has always been documented as having undefined behavior when the slices
14+
overlap. However, overlaps previously were handled gracefully (with the semantics
15+
of C's `memmove`). Going forward, users who do not uphold `copyMutableByteArray`'s
16+
precondition will be met with unpredictable results.
17+
18+
* Drop support for GHC 8.0.
319

420
## Changes in version 0.9.0.0
521

0 commit comments

Comments
 (0)