Add fprintf macro - Mailing list pgsql-patches

From Bruce Momjian
Subject Add fprintf macro
Date
Msg-id 200503111914.j2BJEMZ28289@candle.pha.pa.us
Whole thread Raw
List pgsql-patches
I have applied the following patch:

    Add fprintf() custom version to libpgport.

    Document use of macros for pg_printf functions.

    Bump major versions of all interfaces to handle movement of get_progname
    from libpq to libpgport in 8.0, and probably other libpgport changes in
    8.1.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/bootstrap/bootscanner.l
===================================================================
RCS file: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v
retrieving revision 1.38
diff -c -c -r1.38 bootscanner.l
*** src/backend/bootstrap/bootscanner.l    31 Dec 2004 21:59:34 -0000    1.38
--- src/backend/bootstrap/bootscanner.l    11 Mar 2005 19:02:15 -0000
***************
*** 42,47 ****
--- 42,48 ----


  /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+ #undef fprintf
  #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))


Index: src/backend/parser/scan.l
===================================================================
RCS file: /cvsroot/pgsql/src/backend/parser/scan.l,v
retrieving revision 1.120
diff -c -c -r1.120 scan.l
*** src/backend/parser/scan.l    22 Feb 2005 04:36:22 -0000    1.120
--- src/backend/parser/scan.l    11 Mar 2005 19:02:16 -0000
***************
*** 28,33 ****
--- 28,34 ----


  /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+ #undef fprintf
  #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))

  extern YYSTYPE yylval;
Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.29
diff -c -c -r1.29 guc-file.l
*** src/backend/utils/misc/guc-file.l    1 Jan 2005 05:43:08 -0000    1.29
--- src/backend/utils/misc/guc-file.l    11 Mar 2005 19:02:16 -0000
***************
*** 19,24 ****
--- 19,25 ----
  #include "utils/guc.h"

  /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+ #undef fprintf
  #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))

  static unsigned ConfigFileLineno;
Index: src/include/port.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/port.h,v
retrieving revision 1.71
diff -c -c -r1.71 port.h
*** src/include/port.h    11 Mar 2005 17:20:34 -0000    1.71
--- src/include/port.h    11 Mar 2005 19:02:17 -0000
***************
*** 112,128 ****
  extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
  /* This extension allows gcc to check the format string */
  __attribute__((format(printf, 3, 4)));
  extern int pg_printf(const char *fmt,...)
  /* This extension allows gcc to check the format string */
  __attribute__((format(printf, 1, 2)));

  #ifdef __GNUC__
! #define vsnprintf(...)    pg_vsnprintf(__VA_ARGS__)
  #define snprintf(...)    pg_snprintf(__VA_ARGS__)
  #define printf(...)        pg_printf(__VA_ARGS__)
  #else
  #define vsnprintf        pg_vsnprintf
  #define snprintf        pg_snprintf
  #define printf            pg_printf
  #endif
  #endif
--- 112,138 ----
  extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
  /* This extension allows gcc to check the format string */
  __attribute__((format(printf, 3, 4)));
+ extern int pg_fprintf(FILE *stream, const char *fmt,...)
+ /* This extension allows gcc to check the format string */
+ __attribute__((format(printf, 2, 3)));
  extern int pg_printf(const char *fmt,...)
  /* This extension allows gcc to check the format string */
  __attribute__((format(printf, 1, 2)));

+ /*
+  *    The GCC-specific code below prevents the __attribute__(... 'printf')
+  *    above from being replaced, and this is required because gcc doesn't
+  *    know anything about pg_printf.
+  */
  #ifdef __GNUC__
! #define    vsnprintf(...)    pg_vsnprintf(__VA_ARGS__)
  #define snprintf(...)    pg_snprintf(__VA_ARGS__)
+ #define fprintf(...)    pg_fprintf(__VA_ARGS__)
  #define printf(...)        pg_printf(__VA_ARGS__)
  #else
  #define vsnprintf        pg_vsnprintf
  #define snprintf        pg_snprintf
+ #define fprintf            pg_fprintf
  #define printf            pg_printf
  #endif
  #endif
Index: src/interfaces/ecpg/compatlib/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v
retrieving revision 1.19
diff -c -c -r1.19 Makefile
*** src/interfaces/ecpg/compatlib/Makefile    18 Jan 2005 05:00:15 -0000    1.19
--- src/interfaces/ecpg/compatlib/Makefile    11 Mar 2005 19:02:17 -0000
***************
*** 13,20 ****
  include $(top_builddir)/src/Makefile.global

  NAME= ecpg_compat
! SO_MAJOR_VERSION= 1
! SO_MINOR_VERSION= 2
  DLTYPE= library

  override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) \
--- 13,20 ----
  include $(top_builddir)/src/Makefile.global

  NAME= ecpg_compat
! SO_MAJOR_VERSION= 2
! SO_MINOR_VERSION= 0
  DLTYPE= library

  override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) \
Index: src/interfaces/ecpg/ecpglib/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v
retrieving revision 1.31
diff -c -c -r1.31 Makefile
*** src/interfaces/ecpg/ecpglib/Makefile    26 Jan 2005 19:24:01 -0000    1.31
--- src/interfaces/ecpg/ecpglib/Makefile    11 Mar 2005 19:02:17 -0000
***************
*** 13,20 ****
  include $(top_builddir)/src/Makefile.global

  NAME= ecpg
! SO_MAJOR_VERSION= 4
! SO_MINOR_VERSION= 3
  DLTYPE= library

  override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
--- 13,20 ----
  include $(top_builddir)/src/Makefile.global

  NAME= ecpg
! SO_MAJOR_VERSION= 5
! SO_MINOR_VERSION= 0
  DLTYPE= library

  override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
Index: src/interfaces/ecpg/pgtypeslib/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v
retrieving revision 1.24
diff -c -c -r1.24 Makefile
*** src/interfaces/ecpg/pgtypeslib/Makefile    18 Jan 2005 05:00:23 -0000    1.24
--- src/interfaces/ecpg/pgtypeslib/Makefile    11 Mar 2005 19:02:17 -0000
***************
*** 13,20 ****
  include $(top_builddir)/src/Makefile.global

  NAME= pgtypes
! SO_MAJOR_VERSION= 1
! SO_MINOR_VERSION= 3
  DLTYPE= library

  override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include \
--- 13,20 ----
  include $(top_builddir)/src/Makefile.global

  NAME= pgtypes
! SO_MAJOR_VERSION= 2
! SO_MINOR_VERSION= 0
  DLTYPE= library

  override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include \
Index: src/interfaces/ecpg/preproc/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v
retrieving revision 1.112
diff -c -c -r1.112 Makefile
*** src/interfaces/ecpg/preproc/Makefile    25 Jan 2005 12:51:31 -0000    1.112
--- src/interfaces/ecpg/preproc/Makefile    11 Mar 2005 19:02:17 -0000
***************
*** 13,20 ****
  top_builddir = ../../../..
  include $(top_builddir)/src/Makefile.global

! MAJOR_VERSION=3
! MINOR_VERSION=2
  PATCHLEVEL=1

  override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
--- 13,20 ----
  top_builddir = ../../../..
  include $(top_builddir)/src/Makefile.global

! MAJOR_VERSION= 4
! MINOR_VERSION= 0
  PATCHLEVEL=1

  override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
Index: src/interfaces/libpq/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v
retrieving revision 1.128
diff -c -c -r1.128 Makefile
*** src/interfaces/libpq/Makefile    26 Jan 2005 19:24:02 -0000    1.128
--- src/interfaces/libpq/Makefile    11 Mar 2005 19:02:17 -0000
***************
*** 16,23 ****

  # shared library parameters
  NAME= pq
! SO_MAJOR_VERSION= 3
! SO_MINOR_VERSION= 3
  DLTYPE= library

  override CPPFLAGS :=  -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
--- 16,23 ----

  # shared library parameters
  NAME= pq
! SO_MAJOR_VERSION= 4
! SO_MINOR_VERSION= 0
  DLTYPE= library

  override CPPFLAGS :=  -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
Index: src/pl/plpgsql/src/scan.l
===================================================================
RCS file: /cvsroot/pgsql/src/pl/plpgsql/src/scan.l,v
retrieving revision 1.39
diff -c -c -r1.39 scan.l
*** src/pl/plpgsql/src/scan.l    22 Feb 2005 07:18:24 -0000    1.39
--- src/pl/plpgsql/src/scan.l    11 Mar 2005 19:02:18 -0000
***************
*** 45,50 ****
--- 45,51 ----
  #define YY_READ_BUF_SIZE 16777216

  /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+ #undef fprintf
  #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))

  /* Handles to the buffer that the lexer uses internally */
Index: src/port/snprintf.c
===================================================================
RCS file: /cvsroot/pgsql/src/port/snprintf.c,v
retrieving revision 1.17
diff -c -c -r1.17 snprintf.c
*** src/port/snprintf.c    11 Mar 2005 17:20:35 -0000    1.17
--- src/port/snprintf.c    11 Mar 2005 19:02:18 -0000
***************
*** 72,77 ****
--- 72,83 ----
  int            pg_printf(const char *format, ...);
  static void dopr(char *buffer, const char *format, va_list args, char *end);

+ /* Prevent recursion */
+ #undef    vsnprintf
+ #undef    snprintf
+ #undef    fprintf
+ #undef    printf
+
  int
  pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
  {
***************
*** 97,114 ****
  }

  int
  pg_printf(const char *fmt,...)
  {
      int            len;
!     va_list            args;
      char*        buffer[4096];
!     char*            p;

      va_start(args, fmt);
      len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
      va_end(args);
      p = (char*)buffer;
!     for(;*p;p++)
          putchar(*p);
      return len;
  }
--- 103,137 ----
  }

  int
+ pg_fprintf(FILE *stream, const char *fmt,...)
+ {
+     int            len;
+     va_list        args;
+     char*        buffer[4096];
+     char*        p;
+
+     va_start(args, fmt);
+     len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
+     va_end(args);
+     p = (char*)buffer;
+     for( ;*p; p++)
+         putc(*p, stream);
+     return len;
+ }
+
+ int
  pg_printf(const char *fmt,...)
  {
      int            len;
!     va_list        args;
      char*        buffer[4096];
!     char*        p;

      va_start(args, fmt);
      len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
      va_end(args);
      p = (char*)buffer;
!     for( ;*p; p++)
          putchar(*p);
      return len;
  }
Index: src/tools/RELEASE_CHANGES
===================================================================
RCS file: /cvsroot/pgsql/src/tools/RELEASE_CHANGES,v
retrieving revision 1.56
diff -c -c -r1.56 RELEASE_CHANGES
*** src/tools/RELEASE_CHANGES    2 Feb 2005 16:58:52 -0000    1.56
--- src/tools/RELEASE_CHANGES    11 Mar 2005 19:02:19 -0000
***************
*** 6,14 ****
  * Version numbers
      o configure.in, and run autoconf or update configure
      o doc/bug.template
!     o bump interface version numbers
          - src/interfaces/*/Makefile (major releases only)
          - src/interfaces/*/*/Makefile (major releases only)
          - src/interfaces/libpq/libpq.rc.in (major and minor releases)
          - src/include/pg_config.h.win32 (major and minor releases)
          - src/port/win32ver.rc (major and minor releases)
--- 6,15 ----
  * Version numbers
      o configure.in, and run autoconf or update configure
      o doc/bug.template
!     o bump library versions
          - src/interfaces/*/Makefile (major releases only)
          - src/interfaces/*/*/Makefile (major releases only)
+     o bump interface version numbers
          - src/interfaces/libpq/libpq.rc.in (major and minor releases)
          - src/include/pg_config.h.win32 (major and minor releases)
          - src/port/win32ver.rc (major and minor releases)

pgsql-patches by date:

Previous
From: Marko Kreen
Date:
Subject: pgcrypto: openssl digest fix
Next
From: Bruce Momjian
Date:
Subject: Re: [pgsql-hackers-win32] Repleacement for src/port/snprintf.c