commit 71f130ff7ec5a02f3e6e5f886988705ce42b0d8d
parent 432e3dd07d7931f1ee91d3a4e9bcb69f1690af9f
Author: vaplv <vaplv@free.fr>
Date: Wed, 18 Nov 2020 10:40:59 +0100
Increase the new variadic macros capacity
Up to 9 arguments can now be handled while previously only 5 were
supported.
Diffstat:
3 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -237,6 +237,7 @@ if(NOT NO_TEST)
new_test(test_stretchy_array rsys)
new_test(test_text_reader rsys)
new_test(test_time rsys)
+ new_test(test_vmacros)
add_library(test_lib SHARED ${RSYS_SOURCE_DIR}/test_library.c)
set_target_properties(test_lib PROPERTIES
diff --git a/src/rsys.h b/src/rsys.h
@@ -315,6 +315,10 @@ static INLINE DEPRECATED void macro_NCHECK(void) { (void)0; }
#define ARG3(A, B, C)
#define ARG4(A, B, C, D)
#define ARG5(A, B, C, D, E)
+#define ARG6(A, B, C, D, E, F)
+#define ARG7(A, B, C, D, E, F, G)
+#define ARG8(A, B, C, D, E, F, G, H)
+#define ARG9(A, B, C, D, E, F, G, H, I)
#define LIST_ARG0()
#define LIST_ARG1(A) A
@@ -322,6 +326,10 @@ static INLINE DEPRECATED void macro_NCHECK(void) { (void)0; }
#define LIST_ARG3(A, B, C) A, B, C
#define LIST_ARG4(A, B, C, D) A, B, C, D
#define LIST_ARG5(A, B, C, D, E) A, B, C, D, E
+#define LIST_ARG6(A, B, C, D, E, F) A, B, C, D, E, F
+#define LIST_ARG7(A, B, C, D, E, F, G) A, B, C, D, E, F, G
+#define LIST_ARG8(A, B, C, D, E, F, G, H) A, B, C, D, E, F, G, H
+#define LIST_ARG9(A, B, C, D, E, F, G, H, I) A, B, C, D, E, F, G, H, I
#define COMMA_ARG0()
#define COMMA_ARG1(A) ,
@@ -329,6 +337,10 @@ static INLINE DEPRECATED void macro_NCHECK(void) { (void)0; }
#define COMMA_ARG3(A, B, C) ,
#define COMMA_ARG4(A, B, C, D) ,
#define COMMA_ARG5(A, B, C, D, E) ,
+#define COMMA_ARG6(A, B, C, D, E, F) ,
+#define COMMA_ARG7(A, B, C, D, E, F, G) ,
+#define COMMA_ARG8(A, B, C, D, E, F, G, H) ,
+#define COMMA_ARG9(A, B, C, D, E, F, G, H, I) ,
/*******************************************************************************
* Result constants
diff --git a/src/test_vmacros.c b/src/test_vmacros.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2013-2020 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSys library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSys library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "rsys.h"
+
+int
+main(int argc, char** argv)
+{
+ (void)argc, (void)argv;
+ #define PRINTF(Fmt, Args) printf(Fmt COMMA_##Args LIST_##Args)
+ PRINTF("Arg0\n", ARG0());
+ PRINTF("Arg1 %d\n", ARG1(1));
+ PRINTF("Arg2 %d %d\n", ARG2(1, 2));
+ PRINTF("Arg3 %d %d %d\n", ARG3(1, 2, 3));
+ PRINTF("Arg4 %d %d %d %d\n", ARG4(1, 2, 3, 4));
+ PRINTF("Arg5 %d %d %d %d %d\n", ARG5(1, 2, 3, 4, 5));
+ PRINTF("Arg6 %d %d %d %d %d %d\n", ARG6(1, 2, 3, 4, 5, 6));
+ PRINTF("Arg7 %d %d %d %d %d %d %d\n", ARG7(1, 2, 3, 4, 5, 6, 7));
+ PRINTF("Arg8 %d %d %d %d %d %d %d %d\n", ARG8(1, 2, 3, 4, 5, 6, 7, 8));
+ PRINTF("Arg9 %d %d %d %d %d %d %d %d %d\n", ARG9(1, 2, 3, 4, 5, 6, 7, 8, 9));
+ #undef PRINTF
+ return 0;
+}