#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO(type, macro, empty) \
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME(type, macro, macro##p, empty)
+/* Clean up a NULL-terminated array by dropping all the items in it (up to the first NULL).
+ * The array itself is not deallocated. */
+#define DEFINE_ARRAY_DONE_FUNC(type, helper) \
+ void helper ## _many(type (*p)[]) { \
+ for (type *t = *ASSERT_PTR(p); *t; t++) \
+ *t = helper(*t); \
+ }
+
typedef void (*free_array_func_t)(void *p, size_t n);
/* An automatic _cleanup_-like logic for destroy arrays (i.e. pointers + size) when leaving scope */
return 0;
}
-static void unref_many_tables(Table* (*tablesp)[]) {
- for (Table **t = *ASSERT_PTR(tablesp); *t; t++)
- *t = table_unref(*t);
-}
-
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
"Other",
};
- _cleanup_(unref_many_tables) Table* tables[ELEMENTSOF(groups) + 1] = {};
+ _cleanup_(table_unref_many) Table* tables[ELEMENTSOF(groups) + 1] = {};
for (size_t i = 0; i < ELEMENTSOF(groups); i++) {
r = option_parser_get_help_table_group(groups[i], &tables[i]);
Table* table_unref(Table *t);
DEFINE_TRIVIAL_CLEANUP_FUNC(Table*, table_unref);
+static inline DEFINE_ARRAY_DONE_FUNC(Table*, table_unref);
int table_add_cell_full(Table *t, TableCell **ret_cell, TableDataType dt, const void *data, size_t minimum_width, size_t maximum_width, unsigned weight, unsigned align_percent, unsigned ellipsize_percent);
static inline int table_add_cell(Table *t, TableCell **ret_cell, TableDataType dt, const void *data) {
STATIC_DESTRUCTOR_REGISTER(arg_bind_user_shell, freep);
STATIC_DESTRUCTOR_REGISTER(arg_bind_user_groups, strv_freep);
-static void unref_many_tables(Table* (*tablesp)[]) {
- for (Table **t = *ASSERT_PTR(tablesp); *t; t++)
- *t = table_unref(*t);
-}
-
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
"Credentials",
};
- _cleanup_(unref_many_tables) Table* tables[ELEMENTSOF(groups) + 1] = {};
+ _cleanup_(table_unref_many) Table* tables[ELEMENTSOF(groups) + 1] = {};
for (size_t i = 0; i < ELEMENTSOF(groups); i++) {
r = option_parser_get_help_table_group(groups[i], &tables[i]);