diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2020-03-18 22:50:47 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-22 20:18:11 -0400 |
commit | 7484a9a47ad277bb7e51c6357817f7e7c59e744a (patch) | |
tree | 0cbc0b8551b7cebf4229e5da6c26ef92da2954f7 | |
parent | 8336ba78e00ec42521ba8314bc65ec766e6bcc7d (diff) | |
download | haskell-7484a9a47ad277bb7e51c6357817f7e7c59e744a.tar.gz |
Encoding: Add comment about tricky ForeignPtr lifetime
-rw-r--r-- | compiler/GHC/Utils/Encoding.hs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/GHC/Utils/Encoding.hs b/compiler/GHC/Utils/Encoding.hs index 96531e7cd1..113620e895 100644 --- a/compiler/GHC/Utils/Encoding.hs +++ b/compiler/GHC/Utils/Encoding.hs @@ -158,6 +158,10 @@ utf8DecodeStringLazy fp offset (I# len#) = unsafeDupablePerformIO $ withForeignPtr fp $ \ptr -> let !(Ptr a#) = ptr `plusPtr` offset in utf8DecodeLazy# (touchForeignPtr fp) (utf8DecodeCharAddr# a#) len# +-- Note that since utf8DecodeLazy# returns a thunk the lifetime of the +-- ForeignPtr actually needs to be longer than the lexical lifetime +-- withForeignPtr would provide here. That's why we use touchForeignPtr to +-- keep the fp alive until the last character has actually been decoded. utf8DecodeShortByteString :: ShortByteString -> [Char] utf8DecodeShortByteString (SBS ba#) |