Revision: 3016
Author: [email protected]
Date: Sat Oct  3 06:46:22 2009
Log: Add CHECK_INT64_EQ function to avoid operand size ambiguities.
Review URL: http://codereview.chromium.org/256048
http://code.google.com/p/v8/source/detail?r=3016

Modified:
  /branches/bleeding_edge/src/checks.h
  /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/checks.h        Fri Oct  2 11:49:23 2009
+++ /branches/bleeding_edge/src/checks.h        Sat Oct  3 06:46:22 2009
@@ -80,17 +80,18 @@
    }
  }

-#if !V8_HOST_ARCH_64_BIT
-// Helper function used by the CHECK_EQ function when given int64_t
-// arguments.  Should not be called directly.
-static inline void CheckEqualsHelper(const char* file, int line,
-                                     const char* expected_source,
-                                     int64_t expected,
-                                     const char* value_source,
-                                     int64_t value) {
+// Helper function used by the CHECK_INT64_EQ function when given int64_t
+// arguments.  Should not be called directly.  We do not overload CHECK_EQ
+// with both 32-bit and 64-bit integers, because it causes ambiguity
+// with operands of mixed sizes.
+static inline void CheckInt64EqualsHelper(const char* file, int line,
+                                          const char* expected_source,
+                                          int64_t expected,
+                                          const char* value_source,
+                                          int64_t value) {
    if (expected != value) {
-    // Sorry, printing int64_t in a fanky hex way,
-    // that's our mother tongue after all :)
+    // Print int64_t values in hex, as two int32s,
+    // to avoid platform-dependencies.
      V8_Fatal(file, line,
               "CHECK_EQ(%s, %s) failed\n#"
               "   Expected: 0x%08x%08x\n#   Found: 0x%08x%08x",
@@ -99,7 +100,6 @@
               uint32_t(value >> 32), uint32_t(value));
    }
  }
-#endif


  // Helper function used by the CHECK_NE function when given int
@@ -233,6 +233,9 @@
  #define CHECK_GT(a, b) CHECK((a) > (b))
  #define CHECK_GE(a, b) CHECK((a) >= (b))

+#define CHECK_INT64_EQ(expected, value) CheckInt64EqualsHelper(__FILE__, \
+  __LINE__, #expected, expected, #value, value)
+

  // This is inspired by the static assertion facility in boost.  This
  // is pretty magical.  If it causes you trouble on a platform you may
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Oct  2 11:49:23 2009
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Sat Oct  3 06:46:22 2009
@@ -702,18 +702,12 @@
  }


-#if V8_HOST_ARCH_64_BIT
-# define CAST_TO_INT64(x) (int(x))
-#else
-# define CAST_TO_INT64(x) (int64_t(x))
-#endif
-
  THREADED_TEST(TinyInteger) {
    v8::HandleScope scope;
    LocalContext env;
    int32_t value = 239;
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -724,7 +718,7 @@
    CHECK(i::Smi::IsValid(value));
    CHECK(!i::Smi::IsValid(value + 1));
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -734,7 +728,7 @@
    int32_t value = (1 << 30) + 1;
    CHECK(!i::Smi::IsValid(value));
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -743,7 +737,7 @@
    LocalContext env;
    uint32_t value = 239;
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -754,7 +748,7 @@
    CHECK(i::Smi::IsValid(value));
    CHECK(!i::Smi::IsValid(value + 1));
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -764,7 +758,7 @@
    uint32_t value = (1 << 30) + 1;
    CHECK(!i::Smi::IsValid(value));
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }


@@ -773,7 +767,7 @@
    LocalContext env;
    uint32_t value = uint32_t(0xffffffff);
    Local<v8::Integer> value_obj = v8::Integer::New(value);
-  CHECK_EQ(CAST_TO_INT64(value), value_obj->Value());
+  CHECK_INT64_EQ(static_cast<int64_t>(value), value_obj->Value());
  }



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to