glib-aux: add nm_g_array_append_val()

g_array_append_val() takes the pointer of the macro argument, that only works
with lvalues. Add nm_g_array_append_val()
This commit is contained in:
Thomas Haller
2022-12-06 18:07:01 +01:00
parent 73267b4d60
commit de322afcd9

View File

@@ -1989,6 +1989,20 @@ nm_g_array_unref(GArray *arr)
&g_array_index(arr, Type, _len); \
})
#define nm_g_array_append_simple(arr, val) \
G_STMT_START \
{ \
/* Similar to `g_array_append_val()`, but `g_array_append_val()`
* only works with lvalues. That makes sense if the value is a larger
* struct and you anyway have a pointer to it. It doesn't make sense
* if you have a list of int and want to append a number literal.
*
* nm_g_array_append_simple() is different. It depends on typeof(val)
* to be compatible. */ \
(*nm_g_array_append_new((arr), typeof(val))) = (val); \
} \
G_STMT_END
/*****************************************************************************/
static inline GPtrArray *