diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-04-19 11:27:49 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-14 03:35:07 -0500 |
commit | 2de813324245f43e0177549dfb2820f06189964b (patch) | |
tree | d81e95511025fc899d53cdd8c3d35557302aebb9 | |
parent | 74fec146d2dcf05921d58dc81fd5481f9de6d6e9 (diff) | |
download | haskell-2de813324245f43e0177549dfb2820f06189964b.tar.gz |
base: Use keepAlive# in withForeignPtr
-rw-r--r-- | libraries/base/GHC/ForeignPtr.hs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libraries/base/GHC/ForeignPtr.hs b/libraries/base/GHC/ForeignPtr.hs index 79d1614529..774dafdf70 100644 --- a/libraries/base/GHC/ForeignPtr.hs +++ b/libraries/base/GHC/ForeignPtr.hs @@ -526,7 +526,9 @@ withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b -- or from the object pointed to by the -- 'ForeignPtr', using the operations from the -- 'Storable' class. -withForeignPtr = unsafeWithForeignPtr +withForeignPtr fo@(ForeignPtr _ r) f = IO $ \s -> + case f (unsafeForeignPtrToPtr fo) of + IO action# -> keepAlive# r s action# -- | This is similar to 'withForeignPtr' but comes with an important caveat: -- the user must guarantee that the continuation does not diverge (e.g. loop or |