mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Always use our own versions of *printf().
We've spent an awful lot of effort over the years in coping with platform-specific vagaries of the *printf family of functions. Let's just forget all that mess and standardize on always using src/port/snprintf.c. This gets rid of a lot of configure logic, and it will allow a saner approach to dealing with %m (though actually changing that is left for a follow-on patch). Preliminary performance testing suggests that as it stands, snprintf.c is faster than the native printf functions for some tasks on some platforms, and slower for other cases. A pending patch will improve that, though cases with floating-point conversions will doubtless remain slower unless we want to put a *lot* of effort into that. Still, we've not observed that *printf is really a performance bottleneck for most workloads, so I doubt this matters much. Patch by me, reviewed by Michael Paquier Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us
This commit is contained in:
@ -1147,14 +1147,6 @@ typedef union PGAlignedXLogBlock
|
||||
* standard C library.
|
||||
*/
|
||||
|
||||
#if !HAVE_DECL_SNPRINTF
|
||||
extern int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_VSNPRINTF
|
||||
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
|
||||
extern int fdatasync(int fildes);
|
||||
#endif
|
||||
|
@ -166,10 +166,6 @@
|
||||
don't. */
|
||||
#undef HAVE_DECL_RTLD_NOW
|
||||
|
||||
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_STRLCAT
|
||||
@ -194,10 +190,6 @@
|
||||
don't. */
|
||||
#undef HAVE_DECL_SYS_SIGLIST
|
||||
|
||||
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `dlopen' function. */
|
||||
#undef HAVE_DLOPEN
|
||||
|
||||
@ -510,9 +502,6 @@
|
||||
/* Define to 1 if you have the `shm_open' function. */
|
||||
#undef HAVE_SHM_OPEN
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have spinlocks. */
|
||||
#undef HAVE_SPINLOCKS
|
||||
|
||||
@ -715,9 +704,6 @@
|
||||
/* Define to 1 if you have the <uuid/uuid.h> header file. */
|
||||
#undef HAVE_UUID_UUID_H
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#undef HAVE_WCHAR_H
|
||||
|
||||
@ -926,9 +912,6 @@
|
||||
/* Define to 1 to build with PAM support. (--with-pam) */
|
||||
#undef USE_PAM
|
||||
|
||||
/* Use replacement snprintf() functions. */
|
||||
#undef USE_REPL_SNPRINTF
|
||||
|
||||
/* Define to 1 to use software CRC-32C implementation (slicing-by-8). */
|
||||
#undef USE_SLICING_BY_8_CRC32C
|
||||
|
||||
|
@ -135,10 +135,6 @@
|
||||
don't. */
|
||||
#define HAVE_DECL_RTLD_NOW 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_SNPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_STRNLEN 1
|
||||
@ -151,10 +147,6 @@
|
||||
don't. */
|
||||
#define HAVE_DECL_STRTOULL 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_VSNPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `dlopen' function. */
|
||||
/* #undef HAVE_DLOPEN */
|
||||
|
||||
@ -376,9 +368,6 @@
|
||||
/* Define to 1 if you have the `setsid' function. */
|
||||
/* #undef HAVE_SETSID */
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
/* #undef HAVE_SNPRINTF */
|
||||
|
||||
/* Define to 1 if you have spinlocks. */
|
||||
#define HAVE_SPINLOCKS 1
|
||||
|
||||
@ -556,9 +545,6 @@
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#define HAVE_UTIME_H 1
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#define HAVE_WCHAR_H 1
|
||||
|
||||
@ -715,9 +701,6 @@
|
||||
/* Define to 1 to build with PAM support. (--with-pam) */
|
||||
/* #undef USE_PAM */
|
||||
|
||||
/* Use replacement snprintf() functions. */
|
||||
#define USE_REPL_SNPRINTF 1
|
||||
|
||||
/* Define to 1 to use software CRC-32C implementation (slicing-by-8). */
|
||||
#if (_MSC_VER < 1500)
|
||||
#define USE_SLICING_BY_8_CRC32C 1
|
||||
|
@ -134,7 +134,12 @@ extern unsigned char pg_tolower(unsigned char ch);
|
||||
extern unsigned char pg_ascii_toupper(unsigned char ch);
|
||||
extern unsigned char pg_ascii_tolower(unsigned char ch);
|
||||
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
/*
|
||||
* Beginning in v12, we always replace snprintf() and friends with our own
|
||||
* implementation. This symbol is no longer consulted by the core code,
|
||||
* but keep it defined anyway in case any extensions are looking at it.
|
||||
*/
|
||||
#define USE_REPL_SNPRINTF 1
|
||||
|
||||
/*
|
||||
* Versions of libintl >= 0.13 try to replace printf() and friends with
|
||||
@ -187,7 +192,6 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
|
||||
#define fprintf pg_fprintf
|
||||
#define printf pg_printf
|
||||
#endif
|
||||
#endif /* USE_REPL_SNPRINTF */
|
||||
|
||||
/* Replace strerror() with our own, somewhat more robust wrapper */
|
||||
extern char *pg_strerror(int errnum);
|
||||
|
@ -31,7 +31,8 @@ SHLIB_EXPORTS = exports.txt
|
||||
# Need to recompile any libpgport object files
|
||||
LIBS := $(filter-out -lpgport, $(LIBS))
|
||||
|
||||
OBJS= informix.o strerror.o $(filter snprintf.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
|
||||
OBJS= informix.o snprintf.o strerror.o \
|
||||
$(filter strnlen.o, $(LIBOBJS)) $(WIN32RES)
|
||||
|
||||
PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
|
||||
|
||||
|
@ -26,8 +26,8 @@ override CFLAGS += $(PTHREAD_CFLAGS)
|
||||
LIBS := $(filter-out -lpgport, $(LIBS))
|
||||
|
||||
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
|
||||
connect.o misc.o path.o pgstrcasecmp.o strerror.o \
|
||||
$(filter snprintf.o strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
|
||||
connect.o misc.o path.o pgstrcasecmp.o snprintf.o strerror.o \
|
||||
$(filter strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
|
||||
$(WIN32RES)
|
||||
|
||||
# thread.c is needed only for non-WIN32 implementation of path.c
|
||||
|
@ -30,8 +30,8 @@ SHLIB_LINK += $(filter -lm, $(LIBS))
|
||||
SHLIB_EXPORTS = exports.txt
|
||||
|
||||
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
|
||||
pgstrcasecmp.o strerror.o \
|
||||
$(filter rint.o snprintf.o strnlen.o, $(LIBOBJS)) \
|
||||
pgstrcasecmp.o snprintf.o strerror.o \
|
||||
$(filter rint.o strnlen.o, $(LIBOBJS)) \
|
||||
string.o \
|
||||
$(WIN32RES)
|
||||
|
||||
|
@ -36,9 +36,9 @@ OBJS= fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-l
|
||||
libpq-events.o
|
||||
# libpgport C files we always use
|
||||
OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o \
|
||||
strerror.o thread.o
|
||||
snprintf.o strerror.o thread.o
|
||||
# libpgport C files that are needed if identified by configure
|
||||
OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o snprintf.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
|
||||
OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
|
||||
|
||||
ifeq ($(enable_strong_random), yes)
|
||||
OBJS += pg_strong_random.o
|
||||
|
@ -29,11 +29,8 @@
|
||||
* Sometimes perl carefully scribbles on our *printf macros.
|
||||
* So we undefine them here and redefine them after it's done its dirty deed.
|
||||
*/
|
||||
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#undef snprintf
|
||||
#undef vsnprintf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
|
||||
@ -99,7 +96,6 @@
|
||||
#endif
|
||||
|
||||
/* put back our snprintf and vsnprintf */
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#ifdef snprintf
|
||||
#undef snprintf
|
||||
#endif
|
||||
@ -113,7 +109,6 @@
|
||||
#define vsnprintf pg_vsnprintf
|
||||
#define snprintf pg_snprintf
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* USE_REPL_SNPRINTF */
|
||||
|
||||
/* perl version and platform portability */
|
||||
#define NEED_eval_pv
|
||||
|
@ -33,11 +33,8 @@
|
||||
* Sometimes python carefully scribbles on our *printf macros.
|
||||
* So we undefine them here and redefine them after it's done its dirty deed.
|
||||
*/
|
||||
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#undef snprintf
|
||||
#undef vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
/* Python uses #pragma to bring in a non-default libpython on VC++ if
|
||||
@ -124,7 +121,6 @@ typedef int Py_ssize_t;
|
||||
#include <eval.h>
|
||||
|
||||
/* put back our snprintf and vsnprintf */
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#ifdef snprintf
|
||||
#undef snprintf
|
||||
#endif
|
||||
@ -138,7 +134,6 @@ typedef int Py_ssize_t;
|
||||
#define vsnprintf pg_vsnprintf
|
||||
#define snprintf pg_snprintf
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* USE_REPL_SNPRINTF */
|
||||
|
||||
/*
|
||||
* Used throughout, and also by the Python 2/3 porting layer, so it's easier to
|
||||
|
@ -33,7 +33,8 @@ LIBS += $(PTHREAD_LIBS)
|
||||
OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
|
||||
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
|
||||
pgstrcasecmp.o pqsignal.o \
|
||||
qsort.o qsort_arg.o quotes.o sprompt.o strerror.o tar.o thread.o
|
||||
qsort.o qsort_arg.o quotes.o snprintf.o sprompt.o strerror.o \
|
||||
tar.o thread.o
|
||||
|
||||
ifeq ($(enable_strong_random), yes)
|
||||
OBJS += pg_strong_random.o
|
||||
|
@ -18,7 +18,7 @@ and adding infrastructure to recompile the object files:
|
||||
|
||||
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
|
||||
connect.o misc.o path.o exec.o \
|
||||
$(filter snprintf.o, $(LIBOBJS))
|
||||
$(filter strlcat.o, $(LIBOBJS))
|
||||
|
||||
The problem is that there is no testing of which object files need to be
|
||||
added, but missing functions usually show up when linking user
|
||||
|
Reference in New Issue
Block a user