From 3260e429a13efdbc8e371206f26c2761b365ab13 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 24 Nov 2021 19:02:40 +0000 Subject: [PATCH] Move STR() and CAT() into defs.h. I'm actually quite surprised there was only _one_ copy of each of these standard macros in the code base, given my general habit of casually redefining them anywhere I need them! But each one was in a silly place. Moved them up to the top level where they're available globally. --- defs.h | 24 ++++++++++++++++++++++++ unix/gtk-common.c | 2 -- windows/platform.h | 2 -- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/defs.h b/defs.h index 437bef97..c30ac5cf 100644 --- a/defs.h +++ b/defs.h @@ -210,4 +210,28 @@ typedef struct PacketProtocolLayer PacketProtocolLayer; #define NORETURN #endif +/* + * Standard macro definitions. STR() behaves like the preprocessor + * stringification # operator, and CAT() behaves like the token paste + * ## operator, except that each one macro-expands its argument(s) + * first, unlike the raw version. E.g. + * + * #__LINE__ -> "__LINE__" + * STR(__LINE__) -> "1234" (or whatever) + * + * and similarly, + * + * foo ## __LINE__ -> foo__LINE__ + * CAT(foo, __LINE__) -> foo1234 (or whatever) + * + * The expansion is achieved by having each macro pass its arguments + * to a secondary inner macro, because parameter lists of a macro call + * get expanded before the called macro is invoked. So STR(__LINE__) + * -> STR_INNER(1234) -> #1234 -> "1234", and similarly for CAT. + */ +#define STR_INNER(x) #x +#define STR(x) STR_INNER(x) +#define CAT_INNER(x,y) x ## y +#define CAT(x,y) CAT_INNER(x,y) + #endif /* PUTTY_DEFS_H */ diff --git a/unix/gtk-common.c b/unix/gtk-common.c index af39a83c..da653253 100644 --- a/unix/gtk-common.c +++ b/unix/gtk-common.c @@ -44,8 +44,6 @@ #include #endif -#define CAT2(x,y) x ## y -#define CAT(x,y) CAT2(x,y) #define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)} #if GTK_CHECK_VERSION(2,0,0) diff --git a/windows/platform.h b/windows/platform.h index cfd47281..78ea1e59 100644 --- a/windows/platform.h +++ b/windows/platform.h @@ -144,8 +144,6 @@ static inline uintmax_t strtoumax(const char *nptr, char **endptr, int base) /* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to * define the function pointer in a source file */ #define DEF_WINDOWS_FUNCTION(name) t_##name p_##name -#define STR1(x) #x -#define STR(x) STR1(x) #define GET_WINDOWS_FUNCTION_PP(module, name) \ TYPECHECK((t_##name)NULL == name, \ (p_##name = module ? \