shared: fix UNIQ definition
authorLucas De Marchi <lucas.demarchi@intel.com>
Fri, 18 Dec 2020 16:02:08 +0000 (08:02 -0800)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 28 Dec 2020 00:40:08 +0000 (16:40 -0800)
We need a macro indirection for UNIQ to work. Otherwise it won't be
unique at all since it will just append "UNIQ" to the name:

In file included from testsuite/test-init.c:30:

testsuite/testsuite.h:142:27: error: redefinition of â€˜stest_load_resourcesUNIQ’

shared/macro.h
testsuite/testsuite.h

index 4fc5405..b59f7dc 100644 (file)
        })
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
+
 #define XSTRINGIFY(x) #x
 #define STRINGIFY(x) XSTRINGIFY(x)
 
+#define XCONCATENATE(x, y) x ## y
+#define CONCATENATE(x, y) XCONCATENATE(x, y)
+#define UNIQ(x) CONCATENATE(x, __COUNTER__)
+
 /* Temporaries for importing index handling */
 #define NOFAIL(x) (x)
 #define fatal(x...) do { } while (0)
@@ -69,5 +74,3 @@
 #define noreturn __attribute__((noreturn))
 #endif
 #endif
-
-#define UNIQ __COUNTER__
index 7ed96bf..f190249 100644 (file)
@@ -139,7 +139,7 @@ int test_run(const struct test *t);
 
 /* Test definitions */
 #define DEFINE_TEST(_name, ...) \
-       static const struct test s##_name##UNIQ \
+       static const struct test UNIQ(s##_name) \
        __attribute__((used, section("kmod_tests"), aligned(8))) = { \
                .name = #_name, \
                .func = _name, \