weak-0: Weak pointer extas

Copyright(c) 2019-2021 Edward Kmett
LicenseBSD-2-Clause OR Apache-2.0
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

System.Mem.Weak.ForeignPtr

Description

 
Synopsis

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 ForeignPtrs, 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 ForeignPtrs.

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 ForeignPtrs.

A specialised version of mkWeakForeignPtr where the value is actually a pair of the key and value passed to mkWeakForeignPtrPair: mkWeakForeignPtrPair key val finalizer ≡ mkWeakForeignPtr key (key,val) finalizer The advantage of this is that the key can be retrieved by deRefWeak in addition to the value.