Copyright | (c) 2019-2021 Edward Kmett |
---|---|
License | BSD-2-Clause OR Apache-2.0 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- mkWeakForeignPtr :: ForeignPtr k -> v -> Maybe (IO ()) -> IO (Weak v)
- mkWeakForeignPtrPtr :: ForeignPtr a -> Maybe (IO ()) -> IO (Weak (ForeignPtr a))
- mkWeakForeignPtrPair :: ForeignPtr k -> v -> Maybe (IO ()) -> IO (Weak (ForeignPtr k, v))
Documentation
mkWeakForeignPtr :: ForeignPtr k -> v -> Maybe (IO ()) -> IO (Weak v) Source #
Make a Weak
reference from a ForeignPtr
.
This attaches to the IORef
down inside of the ForeignPtr
that
holds onto the finalizers. This is safer than attaching to the ForeignPtr
itself.
However: this does not work with PlainPtr
or FinalPtr
-based
ForeignPtr
s, so make sure you know how you built your
ForeignPtr
.
mkWeakForeignPtrPtr :: ForeignPtr a -> Maybe (IO ()) -> IO (Weak (ForeignPtr a)) Source #
Functions like mkWeakPtr
but for ForeignPtr
s.
A specialised version of mkWeakForeignPtr
, where the key and the value are the same object:
mkWeakForeignPtrPtr
key finalizer =mkWeakForeignPtr
key key finalizer
mkWeakForeignPtrPair :: ForeignPtr k -> v -> Maybe (IO ()) -> IO (Weak (ForeignPtr k, v)) Source #
Functions like mkWeakPair
but for ForeignPtr
s.
A specialised version of mkWeakForeignPtr
where the value
is actually a pair of the key and value passed to mkWeakForeignPtrPair
:
The advantage of this is that the key can be retrieved by mkWeakForeignPtrPair
key val finalizer ≡ mkWeakForeignPtr
key (key,val) finalizer
deRefWeak
in addition to the value.