From 31b7ea9a4251057dfd2dc9e02e72440d957011e5 Mon Sep 17 00:00:00 2001 From: Maxim Orlov Date: Thu, 24 Aug 2023 15:54:19 +0300 Subject: [PATCH v1 1/4] Add lists_free and lists_free_deep This macro functions can handle multiple args at a time. --- src/include/c.h | 10 ++++++++++ src/include/nodes/pg_list.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/include/c.h b/src/include/c.h index 82f8e9d4c7..3f8cee0361 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1108,6 +1108,16 @@ extern void ExceptionalCondition(const char *conditionName, #define FLOAT8_FITS_IN_INT64(num) \ ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN)) +/* + * TODO: add comment + */ +#define func_vectorizor(func, ...) \ +do { \ + void *end = (int[]) {0}; \ + void **args = (void *[]) {__VA_ARGS__, end}; \ + for (int i = 0; args[i] != end; i++) \ + func(args[i]); \ +} while (0) /* ---------------------------------------------------------------- * Section 8: random stuff diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 529a382d28..daae56ec32 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -621,6 +621,11 @@ extern void list_deduplicate_oid(List *list); extern void list_free(List *list); extern void list_free_deep(List *list); +#define lists_free(...) \ + func_vectorizor(list_free, __VA_ARGS__) +#define lists_free_deep(...) \ + func_vectorizor(list_free_deep, __VA_ARGS__) + extern pg_nodiscard List *list_copy(const List *oldlist); extern pg_nodiscard List *list_copy_head(const List *oldlist, int len); extern pg_nodiscard List *list_copy_tail(const List *oldlist, int nskip); -- 2.41.0