]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update Packable API to implement vappendf() method
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 3 Mar 2015 14:06:31 +0000 (06:06 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 3 Mar 2015 14:06:31 +0000 (06:06 -0800)
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.

src/Packer.cc
src/Packer.h
src/base/Packable.h

index 4f51f8d1ebc623df61d4b5426b0faaca6d2828ab..d5ca057d91029721408013742c596be58651c84b 100644 (file)
@@ -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);
 }
 
index 1e630838da05ae2946387a56e37840ed1b8e466b..8dfe8bd28520ad320c6601596662d942d5772d59 100644 (file)
@@ -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_;
index 770bd2cc03a25e34a0b0f380f2c56e7dbc465f89..a0c559b5d24d872b3530b88ec1ad37a94219f9f1 100644 (file)
@@ -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 */