Interface TypeValueCollectFunc
- All Superinterfaces:
FunctionPointer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
TypeValueCollectFunc callback.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionrun(Value value, @Nullable TypeCValue @Nullable [] collectValues, int collectFlags) This function is responsible for converting the values collected from a variadic argument list into contents suitable for storage in aGValue.default MemorySegmenttoCallback(Arena arena) Creates a native function pointer to theupcall(java.lang.foreign.MemorySegment, int, java.lang.foreign.MemorySegment, int)method.default MemorySegmentupcall(MemorySegment value, int nCollectValues, MemorySegment collectValues, int collectFlags) Theupcallmethod is called from native code.
-
Method Details
-
run
This function is responsible for converting the values collected from a variadic argument list into contents suitable for storage in aGValue.This function should setup
valuesimilar toGTypeValueInitFunc; e.g. for a string value that does not allowNULLpointers, it needs to either emit an error, or do an implicit conversion by storing an empty string.The
valuepassed in to this function has a zero-filled data array, so just like forGTypeValueInitFuncit is guaranteed to not contain any old contents that might need freeing.The
nCollectValuesargument is the string length of thecollect_formatfield ofGTypeValueTable, andcollect_valuesis an array ofGTypeCValuewith length ofnCollectValues,containing the collected values according tocollect_format.The
collectFlagsargument provided as a hint by the caller. It may contain the flagG_VALUE_NOCOPY_CONTENTSindicating that the collected value contents may be considered ‘static’ for the duration of thevaluelifetime. Thus an extra copy of the contents stored incollectValuesis not required for assignment tovalue.For our above string example, we continue with:
if (!collect_values[0].v_pointer) value->data[0].v_pointer = g_strdup (""); else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) { value->data[0].v_pointer = collect_values[0].v_pointer; // keep a flag for the value_free() implementation to not free this string value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; } else value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer); return NULL;It should be noted, that it is generally a bad idea to follow the
G_VALUE_NOCOPY_CONTENTShint for reference counted types. Due to reentrancy requirements and reference count assertions performed by the signal emission code, reference counts should always be incremented for reference counted contents stored in thevalue->dataarray. To deviate from our string example for a moment, and taking a look at an exemplary implementation forGTypeValueTable.collect_value()ofGObject:GObject *object = G_OBJECT (collect_values[0].v_pointer); g_return_val_if_fail (object != NULL, g_strdup_printf ("Object %p passed as invalid NULL pointer", object)); // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types value->data[0].v_pointer = g_object_ref (object); return NULL;The reference count for valid objects is always incremented, regardless of
collect_flags. For invalid objects, the example returns a newly allocated string without alteringvalue.Upon success,
collect_value()needs to returnNULL. If, however, an error condition occurred,collect_value()should return a newly allocated string containing an error diagnostic.The calling code makes no assumptions about the
valuecontents being valid upon error returns,valueis simply thrown away without further freeing. As such, it is a good idea to not allocateGValuecontents prior to returning an error; however,collect_values()is not obliged to return a correctly setupvaluefor error returns, simply because any non-NULLreturn is considered a fatal programming error, and further program behaviour is undefined.- Since:
- 2.78
-
upcall
default MemorySegment upcall(MemorySegment value, int nCollectValues, MemorySegment collectValues, int collectFlags) Theupcallmethod is called from native code. The parameters are marshaled andrun(org.gnome.gobject.Value, org.gnome.gobject.TypeCValue[], int)is executed. -
toCallback
Creates a native function pointer to theupcall(java.lang.foreign.MemorySegment, int, java.lang.foreign.MemorySegment, int)method.- Specified by:
toCallbackin interfaceFunctionPointer- Parameters:
arena- the arena in which the function pointer is allocated- Returns:
- the native function pointer
-