Commit dc138da4 authored by Thomas Haller's avatar Thomas Haller

shared: add nm_utils_user_data_pack() and unpack helpers

parent 45fe57ae
......@@ -1359,3 +1359,44 @@ _nm_utils_strv_sort (const char **strv, gssize len)
nm_strcmp_p_with_data,
NULL);
}
/*****************************************************************************/
gpointer
_nm_utils_user_data_pack (int nargs, gconstpointer *args)
{
int i;
gpointer *data;
nm_assert (nargs > 0);
nm_assert (args);
data = g_slice_alloc (((gsize) nargs) * sizeof (gconstpointer));
for (i = 0; i < nargs; i++)
data[i] = (gpointer) args[i];
return data;
}
void
_nm_utils_user_data_unpack (gpointer user_data, int nargs, ...)
{
gpointer *data = user_data;
va_list ap;
int i;
nm_assert (data);
nm_assert (nargs > 0);
va_start (ap, nargs);
for (i = 0; i < nargs; i++) {
gpointer *dst;
dst = va_arg (ap, gpointer *);
nm_assert (dst);
*dst = data[i];
}
va_end (ap);
g_slice_free1 (((gsize) nargs) * sizeof (gconstpointer), user_data);
}
......@@ -611,4 +611,16 @@ guint64 nm_utils_get_start_time_for_pid (pid_t pid, char *out_state, pid_t *out_
/*****************************************************************************/
gpointer _nm_utils_user_data_pack (int nargs, gconstpointer *args);
#define nm_utils_user_data_pack(...) \
_nm_utils_user_data_pack(NM_NARG (__VA_ARGS__), (gconstpointer[]) { __VA_ARGS__ })
void _nm_utils_user_data_unpack (gpointer user_data, int nargs, ...);
#define nm_utils_user_data_unpack(user_data, ...) \
_nm_utils_user_data_unpack(user_data, NM_NARG (__VA_ARGS__), __VA_ARGS__)
/*****************************************************************************/
#endif /* __NM_SHARED_UTILS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment