hercules-ci-cnix-store-0.3.6.0: Haskell bindings for Nix's libstore
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hercules.CNix.Memory

Description

Memory management utilities.

Synopsis

Free after use

class Delete a where Source #

Types whose memory / resources can be freed in a consistent way.

Methods

delete :: Ptr a -> IO () Source #

Instances

Instances details
Delete CStdString Source # 
Instance details

Defined in Hercules.CNix.Std.String

Methods

delete :: Ptr CStdString -> IO () Source #

Delete DerivationInputsIterator Source # 
Instance details

Defined in Hercules.CNix.Store

Delete DerivationOutputsIterator Source # 
Instance details

Defined in Hercules.CNix.Store

Delete StringPairs Source # 
Instance details

Defined in Hercules.CNix.Store

Methods

delete :: Ptr StringPairs -> IO () Source #

Delete StringPairsIterator Source # 
Instance details

Defined in Hercules.CNix.Store

Delete Strings Source # 
Instance details

Defined in Hercules.CNix.Store

Methods

delete :: Ptr Strings -> IO () Source #

Delete (Ref NixStore) Source # 
Instance details

Defined in Hercules.CNix.Store

Methods

delete :: Ptr (Ref NixStore) -> IO () Source #

withDelete :: Delete a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b Source #

Obtain a pointer to a resource and run an action with it.

Free on GC

class Finalizer a where Source #

Like Delete, but the design of finalizers favors that we implement it by means of a function pointer instead of a Haskell function. That way, it can be run during GC, without the need for a separate thread and such.

NOTE: This should always return a CAF, to avoid repeated allocation, initialization, etc.

Example:

instance Finalizer CStdString where
  finalizer = finalize

finalize :: FinalizerPtr CStdString
{-# NOINLINE finalize #-}
finalize =
  unsafePerformIO
    [C.exp|
      void (*)(std::string *) {
        [](std::string *v) {
          delete v;
        }
      }
    |]

toForeignPtr :: Finalizer a => Ptr a -> IO (ForeignPtr a) Source #

Construct a ForeignPtr using finalizer. This takes ownership of the pointer, so it must only be called once per pointer.

Nullable pointers

forNonNull :: Applicative m => Ptr a -> (Ptr a -> m b) -> m (Maybe b) Source #

Run an action with a pointer, if it is not nullPtr.

Same as flip traverseNonNull.

traverseNonNull :: Applicative m => (Ptr a -> m b) -> Ptr a -> m (Maybe b) Source #

Turn an action on pointer into an action that returns Nothing iff the pointer is nullPtr.

Same as flip forNonNull.