TPRINTF in trace.h

Started by Andreas Zeugswetterover 27 years ago3 messages
#1Andreas Zeugswetter
andreas.zeugswetter@telecom.at

The recent changes in the tracing code are unfortunately not portable.

#define PRINTF(args...) tprintf(TRACE_ALL, args)

is not accepted by all compilers. Is there another way to express this ?
Is my AIX xlc Version 3.1.4 the only one with this problem ?

Andreas

#2Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Andreas Zeugswetter (#1)
Re: [HACKERS] TPRINTF in trace.h

The recent changes in the tracing code are unfortunately not portable.

#define PRINTF(args...) tprintf(TRACE_ALL, args)

is not accepted by all compilers. Is there another way to express this ?
Is my AIX xlc Version 3.1.4 the only one with this problem ?

Yikes, that is certainly not standard C. I have never seen that before.
Looks like a GNU-ism. I nice one, but still a GNU-ism.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#3Massimo Dal Zotto
dz@cs.unitn.it
In reply to: Bruce Momjian (#2)
Re: [HACKERS] TPRINTF in trace.h

The recent changes in the tracing code are unfortunately not portable.

#define PRINTF(args...) tprintf(TRACE_ALL, args)

is not accepted by all compilers. Is there another way to express this ?
Is my AIX xlc Version 3.1.4 the only one with this problem ?

Yikes, that is certainly not standard C. I have never seen that before.
Looks like a GNU-ism. I nice one, but still a GNU-ism.

Sorry, I didn't know it is a GNU extension. I have written this patch
which should fix the problem. Let me know if you still have problems.

*** src/include/utils/trace.h.orig	Tue Aug 25 23:43:47 1998
--- src/include/utils/trace.h	Mon Aug 31 22:35:47 1998
***************
*** 26,31 ****
--- 26,32 ----
  #define TIMESTAMP_SIZE 0
  #endif

+ extern int tprintf1(const char *fmt, ...);
extern int tprintf(int flag, const char *fmt, ...);
extern int eprintf(const char *fmt, ...);
extern int option_flag(int flag);
***************
*** 70,78 ****

extern int pg_options[NUM_PG_OPTIONS];

! #define PRINTF(args...) tprintf(TRACE_ALL, args)
#define EPRINTF(args...) eprintf(args)
#define TPRINTF(flag, args...) tprintf(flag, args)

#endif /* TRACE_H */

--- 71,85 ----

extern int pg_options[NUM_PG_OPTIONS];

! #ifdef __GNUC__
! #define PRINTF(args...)			tprintf1(args)
  #define EPRINTF(args...) 		eprintf(args)
  #define TPRINTF(flag, args...)	tprintf(flag, args)
+ #else
+ #define PRINTF	tprintf1
+ #define EPRINTF eprintf
+ #define TPRINTF	tprintf
+ #endif

#endif /* TRACE_H */

*** src/backend/utils/misc/trace.c.orig	Tue Aug 25 23:43:47 1998
--- src/backend/utils/misc/trace.c	Mon Aug 31 22:36:10 1998
***************
*** 126,131 ****
--- 126,159 ----
  }
  /*
+  * Print a timestamp and a message to stdout or to syslog.
+  */
+ int
+ tprintf1(const char *fmt, ... )
+ {
+ 	va_list		ap;
+ 	char		line[ELOG_MAXLEN+TIMESTAMP_SIZE+1];
+ 
+ 	va_start(ap, fmt);
+ #ifdef ELOG_TIMESTAMPS
+ 	strcpy(line, tprintf_timestamp());
+ #endif
+ 	vsprintf(line+TIMESTAMP_SIZE, fmt, ap);
+ 	va_end(ap);
+ 
+ #ifdef USE_SYSLOG
+ 	write_syslog(LOG_INFO, line+TIMESTAMP_SIZE);
+ #endif
+ 
+ 	if (UseSyslog <= 1) {
+ 		puts(line);
+ 		fflush(stdout);
+ 	}
+ 
+ 	return 1;
+ }
+ 
+ /*
   * Print a timestamp and a message to stderr.
   */
  int

--
Massimo Dal Zotto

+----------------------------------------------------------------------+
|  Massimo Dal Zotto                email:  dz@cs.unitn.it             |
|  Via Marconi, 141                 phone:  ++39-461-534251            |
|  38057 Pergine Valsugana (TN)     www:  http://www.cs.unitn.it/~dz/  |
|  Italy                            pgp:  finger dz@tango.cs.unitn.it  |
+----------------------------------------------------------------------+