haskell-gi-base-0.26.8: Foundation for libraries generated by haskell-gi
Safe HaskellNone
LanguageHaskell2010

Data.GI.Base.Utils

Description

Assorted utility functions for bindings.

Synopsis

Documentation

whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () Source #

When the given value is of "Just a" form, execute the given action, otherwise do nothing.

maybeM :: Monad m => b -> Maybe a -> (a -> m b) -> m b Source #

Like maybe, but for actions on a monad, and with slightly different argument order.

maybeFromPtr :: Ptr a -> Maybe (Ptr a) Source #

Check if the pointer is nullPtr, and wrap it on a Maybe accordingly.

mapFirst :: (a -> c) -> [(a, b)] -> [(c, b)] Source #

Given a function and a list of two-tuples, apply the function to every first element of the tuples.

mapFirstA :: Applicative f => (a -> f c) -> [(a, b)] -> f [(c, b)] Source #

Applicative version of mapFirst.

mapSecond :: (b -> c) -> [(a, b)] -> [(a, c)] Source #

Same for the second element.

mapSecondA :: Applicative f => (b -> f c) -> [(a, b)] -> f [(a, c)] Source #

Applicative version of mapSecond.

convertIfNonNull :: Ptr a -> (Ptr a -> IO b) -> IO (Maybe b) Source #

Apply the given conversion action to the given pointer if it is non-NULL, otherwise return Nothing.

convertFunPtrIfNonNull :: FunPtr a -> (FunPtr a -> IO b) -> IO (Maybe b) Source #

Apply the given conversion action to the given function pointer if it is non-NULL, otherwise return Nothing.

callocBytes :: Int -> IO (Ptr a) Source #

Make a zero-filled allocation using the GLib allocator.

callocBoxedBytes :: GBoxed a => Int -> IO (Ptr a) Source #

Make a zero filled allocation of n bytes for a boxed object. The difference with a normal callocBytes is that the returned memory is allocated using whatever memory allocator g_boxed_copy uses, which in particular may well be different from a plain g_malloc. In particular g_slice_alloc is often used for allocating boxed objects, which are then freed using g_slice_free.

callocMem :: Storable a => IO (Ptr a) Source #

Make a zero-filled allocation of enough size to hold the given Storable type, using the GLib allocator.

allocBytes :: Integral a => a -> IO (Ptr b) Source #

Allocate the given number of bytes using the GLib allocator.

allocMem :: Storable a => IO (Ptr a) Source #

Allocate space for the given Storable using the GLib allocator.

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

A wrapper for g_free.

ptr_to_g_free :: FunPtr (Ptr a -> IO ()) Source #

Pointer to g_free.

memcpy :: Ptr a -> Ptr b -> Int -> IO () Source #

Copy memory into a destination (in the first argument) from a source (in the second argument).

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

Same as freeHaskellFunPtr, but it does nothing when given a nullPtr.

safeFreeFunPtrPtr' :: FunPtr (Ptr a -> Ptr b -> IO ()) Source #

Similar to safeFreeFunPtrPtr, but accepts an additional (ignored) argument. The first argument is interpreted as a FunPtr, and released.

maybeReleaseFunPtr :: Maybe (Ptr (FunPtr a)) -> IO () Source #

If given a pointer to the memory location, free the FunPtr at that location, and then the pointer itself. Useful for freeing the memory associated to callbacks which are called just once, with no destroy notification.

checkUnexpectedReturnNULL :: HasCallStack => Text -> Ptr a -> IO () Source #

Check that the given pointer is not NULL. If it is, raise a UnexpectedNullPointerReturn exception.

checkUnexpectedNothing :: HasCallStack => Text -> IO (Maybe a) -> IO a Source #

An annotated version of fromJust, which raises a UnexpectedNullPointerReturn in case it encounters a Nothing.

dbgLog :: Text -> IO () Source #

Print a string to the debug log in an atomic way (so the output of different threads does not get intermingled).