From b9a5f8588facd64fcff0f75fa91e3f80730b93f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Jan 2015 17:49:28 +0100 Subject: [PATCH] import: only define the _to_string() enum mapping function, thus making gcc shut up --- src/import/importd.c | 2 +- src/shared/util.h | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/import/importd.c b/src/import/importd.c index 92ad80130..3e417b174 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -86,7 +86,7 @@ static const char* const transfer_type_table[_TRANSFER_TYPE_MAX] = { [TRANSFER_DKR] = "dkr", }; -DEFINE_PRIVATE_STRING_TABLE_LOOKUP(transfer_type, TransferType); +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(transfer_type, TransferType); static Transfer *transfer_unref(Transfer *t) { if (!t) diff --git a/src/shared/util.h b/src/shared/util.h index bfa56335c..ca0c2e5e3 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -348,12 +348,14 @@ static inline uint32_t random_u32(void) { } /* For basic lookup tables with strictly enumerated entries */ -#define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ +#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ scope const char *name##_to_string(type i) { \ if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \ return NULL; \ return name##_table[i]; \ - } \ + } + +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ scope type name##_from_string(const char *s) { \ type i; \ if (!s) \ @@ -363,11 +365,17 @@ static inline uint32_t random_u32(void) { streq(name##_table[i], s)) \ return i; \ return (type) -1; \ - } \ + } + +#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ struct __useless_struct_to_allow_trailing_semicolon__ -#define DEFINE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,static) +#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static) /* For string conversions where numbers are also acceptable */ #define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \ -- 2.30.2