From 07eb5697abae9716d9ef58b6d43502d8e11cdcfa Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 6 Feb 2021 22:22:50 +0100 Subject: [PATCH] Remove limitation of M_AS_STR to be called within a M_APPLY --- m-core.h | 6 +++--- m-serial-json.h | 4 ++-- m-tuple.h | 2 +- m-variant.h | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/m-core.h b/m-core.h index 2a90565e..949bd4ac 100644 --- a/m-core.h +++ b/m-core.h @@ -1042,9 +1042,9 @@ M_BEGIN_PROTECTED_CODE #define M_COMMA_P(...) M_RETI_ARG76(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, useless) #endif -/* Return the string representation of the evaluated x. - NOTE: Need to be used with M_APPLY to defer the evaluation */ -#define M_AS_STR(x) #x +/* Return the string representation of the evaluated x. */ +#define M_AS_STR(x) M_AS_STRI(x) +#define M_AS_STRI(x) #x /* Return 1 if the argument is empty (aka ''), 0 otherwise. Handle: EMPTY_P(), EMPTY_P(x), EMPTY_P(()) and EMPTY_P(,) and EMPTY_P(f) with #define f() 2,3 */ diff --git a/m-serial-json.h b/m-serial-json.h index db9b1c4f..28037592 100644 --- a/m-serial-json.h +++ b/m-serial-json.h @@ -474,7 +474,7 @@ m_serial_json_read_tuple_id(m_serial_local_t local, m_serial_read_t serial, cons /* Read the field in the JSON */ c = -1; char field[M_MAX_IDENTIFIER_LENGTH+1]; - int nn = m_core_fscanf(f, " \"%" M_APPLY(M_AS_STR, M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", + int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &c); (void) nn ; // Unused. Check is done through 'c' (more robust). if (c <= 0) @@ -510,7 +510,7 @@ m_serial_json_read_variant_start(m_serial_local_t local, m_serial_read_t serial, /* Read the field in the JSON */ char field[M_MAX_IDENTIFIER_LENGTH+1]; - nn = m_core_fscanf(f, " \"%" M_APPLY(M_AS_STR, M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", + nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &final2); (void) nn ; // Unused. Check is done through final (more robust). if (final2 <= 0) return m_core_serial_fail(); diff --git a/m-tuple.h b/m-tuple.h index f5e1253b..e46fdc8a 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -517,7 +517,7 @@ namespace m_lib { /* Return the parameter name as a C string */ #define TUPLEI_STRINGIFY_NAME(a) \ - M_APPLY(M_AS_STR, TUPLEI_GET_FIELD a) + M_AS_STR(TUPLEI_GET_FIELD a) /* Define a OUT_SERIAL method by calling the OUT_SERIAL methods for all params */ diff --git a/m-variant.h b/m-variant.h index f55491a9..a81de9b5 100644 --- a/m-variant.h +++ b/m-variant.h @@ -536,7 +536,7 @@ #define VARIANTI_DEFINE_GET_STR_FUNC(name, a) \ case M_C4(name, _, VARIANTI_GET_FIELD a, _value): \ - func(str, "@" M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a) "@"); \ + func(str, "@" M_AS_STR(VARIANTI_GET_FIELD a) "@"); \ VARIANTI_CALL_GET_STR(a, str, el -> value . VARIANTI_GET_FIELD a, true); \ break; @@ -576,7 +576,7 @@ } #define VARIANTI_DEFINE_PARSE_STR_FUNC(name, a) \ - else if (strcmp (variantTypeBuf, M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a)) == 0) { \ + else if (strcmp (variantTypeBuf, M_AS_STR(VARIANTI_GET_FIELD a)) == 0) { \ el->type = M_C4(name, _, VARIANTI_GET_FIELD a, _value); \ VARIANTI_CALL_INIT(a, el ->value . VARIANTI_GET_FIELD a ); \ bool b = VARIANTI_CALL_PARSE_STR(a, el -> value . VARIANTI_GET_FIELD a, str, &str); \ @@ -600,7 +600,7 @@ #define VARIANTI_DEFINE_OUT_STR_FUNC(name, a) \ case M_C4(name, _, VARIANTI_GET_FIELD a, _value): \ - fprintf(f, "@" M_APPLY(M_AS_STR, VARIANTI_GET_FIELD a) "@"); \ + fprintf(f, "@" M_AS_STR(VARIANTI_GET_FIELD a) "@"); \ VARIANTI_CALL_OUT_STR(a, f, el -> value . VARIANTI_GET_FIELD a); \ break; @@ -635,7 +635,7 @@ } #define VARIANTI_DEFINE_IN_STR_FUNC(name, a) \ - else if (strcmp (variantTypeBuf, M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a)) == 0) { \ + else if (strcmp (variantTypeBuf, M_AS_STR(VARIANTI_GET_FIELD a)) == 0) { \ el->type = M_C4(name, _, VARIANTI_GET_FIELD a, _value); \ VARIANTI_CALL_INIT(a, el ->value . VARIANTI_GET_FIELD a ); \ b = VARIANTI_CALL_IN_STR(a, el -> value . VARIANTI_GET_FIELD a, f); \ @@ -644,7 +644,7 @@ /* Return the STRING version of a parameter name */ #define VARIANTI_STRINGIFY_NAME(a) \ - M_APPLY(M_AS_STR, VARIANTI_GET_FIELD a) + M_AS_STR(VARIANTI_GET_FIELD a) /* Define the OUT_SERIAL function */