diff options
author | Tom Lane | 2018-09-26 21:35:01 +0000 |
---|---|---|
committer | Tom Lane | 2018-09-26 21:35:01 +0000 |
commit | 8b91d258844afa58e856ac354f9ba9745ff9ffb2 (patch) | |
tree | 27036ef0901cc574352ef9276d2c056940a34740 | |
parent | a6b88d682cbec73474a73c9782fb7096e9440a8b (diff) |
Clean up *printf macros to avoid conflict with format archetypes.
We must define the macro "printf" with arguments, else it can mess
up format archetype attributes in builds where PG_PRINTF_ATTRIBUTE
is just "printf". Fortunately, that's easy to do now that we're
requiring C99; we can use __VA_ARGS__.
On the other hand, it's better not to use __VA_ARGS__ for the rest
of the *printf crew, so that one can take the addresses of those
functions without surprises.
I'd proposed doing this some time ago, but forgot to make it happen;
buildfarm failures subsequent to 96bf88d52 reminded me.
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
-rw-r--r-- | src/include/port.h | 20 | ||||
-rw-r--r-- | src/pl/plperl/plperl.h | 5 | ||||
-rw-r--r-- | src/pl/plpython/plpython.h | 5 |
3 files changed, 7 insertions, 23 deletions
diff --git a/src/include/port.h b/src/include/port.h index 597d05e553..e654d5cbdf 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -173,25 +173,19 @@ extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2); /* - * The GCC-specific code below prevents the pg_attribute_printf above from - * being replaced, and this is required because gcc doesn't know anything - * about pg_printf. + * We use __VA_ARGS__ for printf to prevent replacing references to + * the "printf" format archetype in format() attribute declarations. + * That unfortunately means that taking a function pointer to printf + * will not do what we'd wish. (If you need to do that, you must name + * pg_printf explicitly.) For printf's sibling functions, use + * parameterless macros so that function pointers will work unsurprisingly. */ -#ifdef __GNUC__ -#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) -#define snprintf(...) pg_snprintf(__VA_ARGS__) -#define sprintf(...) pg_sprintf(__VA_ARGS__) -#define vfprintf(...) pg_vfprintf(__VA_ARGS__) -#define fprintf(...) pg_fprintf(__VA_ARGS__) -#define printf(...) pg_printf(__VA_ARGS__) -#else #define vsnprintf pg_vsnprintf #define snprintf pg_snprintf #define sprintf pg_sprintf #define vfprintf pg_vfprintf #define fprintf pg_fprintf -#define printf pg_printf -#endif +#define printf(...) pg_printf(__VA_ARGS__) /* Replace strerror() with our own, somewhat more robust wrapper */ extern char *pg_strerror(int errnum); diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h index f8888a451e..2b733546c3 100644 --- a/src/pl/plperl/plperl.h +++ b/src/pl/plperl/plperl.h @@ -102,13 +102,8 @@ #ifdef vsnprintf #undef vsnprintf #endif -#ifdef __GNUC__ -#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) -#define snprintf(...) pg_snprintf(__VA_ARGS__) -#else #define vsnprintf pg_vsnprintf #define snprintf pg_snprintf -#endif /* __GNUC__ */ /* perl version and platform portability */ #define NEED_eval_pv diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h index aefbfc2f82..eaf3e4a154 100644 --- a/src/pl/plpython/plpython.h +++ b/src/pl/plpython/plpython.h @@ -127,13 +127,8 @@ typedef int Py_ssize_t; #ifdef vsnprintf #undef vsnprintf #endif -#ifdef __GNUC__ -#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) -#define snprintf(...) pg_snprintf(__VA_ARGS__) -#else #define vsnprintf pg_vsnprintf #define snprintf pg_snprintf -#endif /* __GNUC__ */ /* * Used throughout, and also by the Python 2/3 porting layer, so it's easier to |