Function
GLibclear_pointer
since: 2.34
Declaration [src]
void
g_clear_pointer (
gpointer* pp,
GDestroyNotify destroy
)
Description [src]
Clears a reference to a variable.
pp
must not be NULL
.
If the reference is NULL
then this function does nothing.
Otherwise, the variable is destroyed using destroy
and the
pointer is set to NULL
.
A macro is also included that allows this function to be used without
pointer casts. This will mask any warnings about incompatible function types
or calling conventions, so you must ensure that your destroy
function is
compatible with being called as GDestroyNotify
using the
standard calling convention for the platform that GLib was compiled for;
otherwise the program will experience undefined behaviour.
Examples of this kind of undefined behaviour include using many Windows Win32
APIs, as well as many if not all OpenGL and Vulkan calls on 32-bit Windows,
which typically use the __stdcall
calling convention rather than the
__cdecl
calling convention.
The affected functions can be used by wrapping them in a
GDestroyNotify
that is declared with the standard calling convention:
// Wrapper needed to avoid mismatched calling conventions on Windows
static void
destroy_sync (void *sync)
{
glDeleteSync (sync);
}
// …
g_clear_pointer (&sync, destroy_sync);
Available since: 2.34
This function is not directly available to language bindings.
Parameters
pp
-
Type:
gpointer*
A pointer to a variable, struct member etc. holding a pointer.
The argument will be modified by the function. destroy
-
Type:
GDestroyNotify
A function to which a gpointer can be passed, to destroy
*pp
.