Commit 5cfb9efa authored by scottmg's avatar scottmg Committed by Commit bot

Remove GG_VA_COPY in favor of va_copy

This was a workaround for VS's before 2013 that lack va_copy, and is
no longer required. The unittest is removed as it seems unnecessary
to test the standard library's implementation of va_copy.

R=thakis@chromium.org
TBR=cpu@chromium.org

Review URL: https://codereview.chromium.org/802533002

Cr-Commit-Position: refs/heads/master@{#307991}
parent 8ae1a697
...@@ -26,18 +26,6 @@ ...@@ -26,18 +26,6 @@
#define GG_INT64_C(x) GG_LONGLONG(x) #define GG_INT64_C(x) GG_LONGLONG(x)
#define GG_UINT64_C(x) GG_ULONGLONG(x) #define GG_UINT64_C(x) GG_ULONGLONG(x)
// It's possible for functions that use a va_list, such as StringPrintf, to
// invalidate the data in it upon use. The fix is to make a copy of the
// structure before using it and use that copy instead. va_copy is provided
// for this purpose. MSVC does not provide va_copy, so define an
// implementation here. It is not guaranteed that assignment is a copy, so the
// StringUtil.VariableArgsFunc unit test tests this capability.
#if defined(COMPILER_GCC)
#define GG_VA_COPY(a, b) (va_copy(a, b))
#elif defined(COMPILER_MSVC)
#define GG_VA_COPY(a, b) (a = b)
#endif
// Define an OS-neutral wrapper for shared library entry points // Define an OS-neutral wrapper for shared library entry points
#if defined(OS_WIN) #if defined(OS_WIN)
#define API_CALL __stdcall #define API_CALL __stdcall
......
...@@ -669,39 +669,6 @@ TEST(StringUtilTest, HexDigitToInt) { ...@@ -669,39 +669,6 @@ TEST(StringUtilTest, HexDigitToInt) {
EXPECT_EQ(15, HexDigitToInt('f')); EXPECT_EQ(15, HexDigitToInt('f'));
} }
// This checks where we can use the assignment operator for a va_list. We need
// a way to do this since Visual C doesn't support va_copy, but assignment on
// va_list is not guaranteed to be a copy. See StringAppendVT which uses this
// capability.
static void VariableArgsFunc(const char* format, ...) {
va_list org;
va_start(org, format);
va_list dup;
GG_VA_COPY(dup, org);
int i1 = va_arg(org, int);
int j1 = va_arg(org, int);
char* s1 = va_arg(org, char*);
double d1 = va_arg(org, double);
va_end(org);
int i2 = va_arg(dup, int);
int j2 = va_arg(dup, int);
char* s2 = va_arg(dup, char*);
double d2 = va_arg(dup, double);
EXPECT_EQ(i1, i2);
EXPECT_EQ(j1, j2);
EXPECT_STREQ(s1, s2);
EXPECT_EQ(d1, d2);
va_end(dup);
}
TEST(StringUtilTest, VAList) {
VariableArgsFunc("%d %d %s %lf", 45, 92, "This is interesting", 9.21);
}
// Test for Tokenize // Test for Tokenize
template <typename STR> template <typename STR>
void TokenizeTest() { void TokenizeTest() {
......
...@@ -48,7 +48,7 @@ static void StringAppendVT(StringType* dst, ...@@ -48,7 +48,7 @@ static void StringAppendVT(StringType* dst,
typename StringType::value_type stack_buf[1024]; typename StringType::value_type stack_buf[1024];
va_list ap_copy; va_list ap_copy;
GG_VA_COPY(ap_copy, ap); va_copy(ap_copy, ap);
#if !defined(OS_WIN) #if !defined(OS_WIN)
ScopedClearErrno clear_errno; ScopedClearErrno clear_errno;
...@@ -94,7 +94,7 @@ static void StringAppendVT(StringType* dst, ...@@ -94,7 +94,7 @@ static void StringAppendVT(StringType* dst,
// NOTE: You can only use a va_list once. Since we're in a while loop, we // NOTE: You can only use a va_list once. Since we're in a while loop, we
// need to make a new copy each time so we don't use up the original. // need to make a new copy each time so we don't use up the original.
GG_VA_COPY(ap_copy, ap); va_copy(ap_copy, ap);
result = vsnprintfT(&mem_buf[0], mem_length, format, ap_copy); result = vsnprintfT(&mem_buf[0], mem_length, format, ap_copy);
va_end(ap_copy); va_end(ap_copy);
......
...@@ -32,18 +32,6 @@ ...@@ -32,18 +32,6 @@
#define GG_UINT32_C(x) (x ## U) #define GG_UINT32_C(x) (x ## U)
#define GG_UINT64_C(x) GG_ULONGLONG(x) #define GG_UINT64_C(x) GG_ULONGLONG(x)
// It's possible for functions that use a va_list, such as StringPrintf, to
// invalidate the data in it upon use. The fix is to make a copy of the
// structure before using it and use that copy instead. va_copy is provided
// for this purpose. MSVC does not provide va_copy, so define an
// implementation here. It is not guaranteed that assignment is a copy, so the
// StringUtil.VariableArgsFunc unit test tests this capability.
#if defined(COMPILER_GCC)
#define GG_VA_COPY(a, b) (va_copy(a, b))
#elif defined(COMPILER_MSVC)
#define GG_VA_COPY(a, b) (a = b)
#endif
// Define an OS-neutral wrapper for shared library entry points // Define an OS-neutral wrapper for shared library entry points
#if defined(OS_WIN) #if defined(OS_WIN)
#define API_CALL __stdcall #define API_CALL __stdcall
......
...@@ -54,7 +54,7 @@ class ChromiumLogger : public Logger { ...@@ -54,7 +54,7 @@ class ChromiumLogger : public Logger {
// Print the message // Print the message
if (p < limit) { if (p < limit) {
va_list backup_ap; va_list backup_ap;
GG_VA_COPY(backup_ap, ap); va_copy(backup_ap, ap);
p += vsnprintf(p, limit - p, format, backup_ap); p += vsnprintf(p, limit - p, format, backup_ap);
va_end(backup_ap); va_end(backup_ap);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment