From: Amos Jeffries Date: Tue, 3 Mar 2015 14:06:31 +0000 (-0800) Subject: Update Packable API to implement vappendf() method X-Git-Tag: merge-candidate-3-v1~101^2~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ea88f0a88ed01623e2ef6ce608adc6701d590c4;p=thirdparty%2Fsquid.git Update Packable API to implement vappendf() method The backend classes actually implement the vappendf() base function receiving va_list args object. The Printf() implementations are all duplicate code. So provide that function in terms of a virtual vappendf(). vappendf() is incidentally the name used by SBuf API for this operation and avoids the global vprintf() libc definition. --- diff --git a/src/Packer.cc b/src/Packer.cc index 4f51f8d1eb..d5ca057d91 100644 --- a/src/Packer.cc +++ b/src/Packer.cc @@ -92,13 +92,9 @@ Packer::append(const char *buf, int sz) } void -Packer::Printf(const char *fmt,...) +Packer::vappendf(const char *fmt, va_list args) { - va_list args; - va_start(args, fmt); - assert(real_handler && packer_vprintf); packer_vprintf(real_handler, fmt, args); - va_end(args); } diff --git a/src/Packer.h b/src/Packer.h index 1e630838da..8dfe8bd285 100644 --- a/src/Packer.h +++ b/src/Packer.h @@ -29,7 +29,7 @@ public: /* Packable API */ virtual void append(const char *buf, int size); - virtual void Printf(const char *fmt,...) PRINTF_FORMAT_ARG2; + virtual void vappendf(const char *fmt, va_list ap); /* protected, use interface functions instead */ append_f append_; diff --git a/src/base/Packable.h b/src/base/Packable.h index 770bd2cc03..a0c559b5d2 100644 --- a/src/base/Packable.h +++ b/src/base/Packable.h @@ -58,7 +58,20 @@ public: * \note we use Printf instead of printf so the compiler won't * think we're calling the libc printf() */ - virtual void Printf(const char *fmt,...) PRINTF_FORMAT_ARG2 = 0; + void Printf(const char *fmt,...) PRINTF_FORMAT_ARG2 + { + va_list args; + va_start(args, fmt); + vappendf(fmt, args); + va_end(args); + } + + /** Append operation, with vsprintf(3)-style arguments. + * + * \note arguments may be evaluated more than once, be careful + * of side-effects + */ + virtual void vappendf(const char *fmt, va_list ap) = 0; }; #endif /* SQUID_SRC_BASE_PACKABLE_H */