Skip to content

Commit 8b91d25

Browse files
committed
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 96bf88d reminded me. Discussion: https://postgr.es/m/22709.1535135640@sss.pgh.pa.us Discussion: https://postgr.es/m/20180926190934.ea4xvzhkayuw7gkx@alap3.anarazel.de
1 parent a6b88d6 commit 8b91d25

File tree

3 files changed

+7
-23
lines changed

3 files changed

+7
-23
lines changed

src/include/port.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,19 @@ extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2,
173173
extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
174174

175175
/*
176-
* The GCC-specific code below prevents the pg_attribute_printf above from
177-
* being replaced, and this is required because gcc doesn't know anything
178-
* about pg_printf.
176+
* We use __VA_ARGS__ for printf to prevent replacing references to
177+
* the "printf" format archetype in format() attribute declarations.
178+
* That unfortunately means that taking a function pointer to printf
179+
* will not do what we'd wish. (If you need to do that, you must name
180+
* pg_printf explicitly.) For printf's sibling functions, use
181+
* parameterless macros so that function pointers will work unsurprisingly.
179182
*/
180-
#ifdef __GNUC__
181-
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
182-
#define snprintf(...) pg_snprintf(__VA_ARGS__)
183-
#define sprintf(...) pg_sprintf(__VA_ARGS__)
184-
#define vfprintf(...) pg_vfprintf(__VA_ARGS__)
185-
#define fprintf(...) pg_fprintf(__VA_ARGS__)
186-
#define printf(...) pg_printf(__VA_ARGS__)
187-
#else
188183
#define vsnprintf pg_vsnprintf
189184
#define snprintf pg_snprintf
190185
#define sprintf pg_sprintf
191186
#define vfprintf pg_vfprintf
192187
#define fprintf pg_fprintf
193-
#define printf pg_printf
194-
#endif
188+
#define printf(...) pg_printf(__VA_ARGS__)
195189

196190
/* Replace strerror() with our own, somewhat more robust wrapper */
197191
extern char *pg_strerror(int errnum);

src/pl/plperl/plperl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,8 @@
102102
#ifdef vsnprintf
103103
#undef vsnprintf
104104
#endif
105-
#ifdef __GNUC__
106-
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
107-
#define snprintf(...) pg_snprintf(__VA_ARGS__)
108-
#else
109105
#define vsnprintf pg_vsnprintf
110106
#define snprintf pg_snprintf
111-
#endif /* __GNUC__ */
112107

113108
/* perl version and platform portability */
114109
#define NEED_eval_pv

src/pl/plpython/plpython.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,8 @@ typedef int Py_ssize_t;
127127
#ifdef vsnprintf
128128
#undef vsnprintf
129129
#endif
130-
#ifdef __GNUC__
131-
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
132-
#define snprintf(...) pg_snprintf(__VA_ARGS__)
133-
#else
134130
#define vsnprintf pg_vsnprintf
135131
#define snprintf pg_snprintf
136-
#endif /* __GNUC__ */
137132

138133
/*
139134
* Used throughout, and also by the Python 2/3 porting layer, so it's easier to

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy