|
libvdo
|
The vdo library it built on top of GLib, which is a general-purpose, portable utility library for C. This library provides functionality, for implementing the VDO objects above, but also useful macros.
GError is used for error handling. The GError is a struct that contains an error code and an error message. Most vdo API functions have a double pointer to GError parameter, which is used to set a location to a GError pointer. If the double pointer is instead NULL, errors are ignored.
A commonly used feature is the g_autoptr, which allows for automatic freeing of a pointer to heap allocated memory. In the example below, this is used for both the GError and VdoStream object:
This is the recommended usage pattern of the VDO API.
NOTE: when using g_autoptr, the pointer must not be freed manually. It should also not be reassigned to something else. An exception to the latter case, is reusing a non-null GError in a function that continues after a failed vdo call. In that case, the error first need to be cleared with g_clear_error:
If g_autoptr is not used, GErrors should be freed using g_clear_error, and each VDO object needs to be freed using g_clear_object (these functions which will also set the pointer to NULL). Example:
As previously stated, this is not recommended. Use g_autoptr when possible instead.