From 630a8a703828ea6d05abfca774a4e2b8a3d6646b Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Tue, 26 Aug 2014 10:29:51 +0000 Subject: [PATCH] Next attempt to fix NaCl build. TBR=yangguo@chromium.org git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23393 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/base/macros.h | 69 +++++++++++++++++++++++++++-------------------- src/serialize.cc | 4 +-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/base/macros.h b/src/base/macros.h index c8a140849d..bfa3170920 100644 --- a/src/base/macros.h +++ b/src/base/macros.h @@ -20,35 +20,6 @@ (reinterpret_cast(&(reinterpret_cast(4)->field)) - 4) -// The arraysize(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. If you use arraysize on -// a pointer by mistake, you will get a compile-time error. -// -// One caveat is that arraysize() doesn't accept any array of an -// anonymous type or a type defined inside a function. In these rare -// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is -// due to a limitation in C++'s template system. The limitation might -// eventually be removed, but it hasn't happened yet. -#define arraysize(array) (sizeof(ArraySizeHelper(array))) - - -// This template function declaration is used in defining arraysize. -// Note that the function doesn't need an implementation, as we only -// use its type. -template -char (&ArraySizeHelper(T (&array)[N]))[N]; - - -#if V8_CC_GNU -// That gcc wants both of these prototypes seems mysterious. VC, for -// its part, can't decide which to use (another mystery). Matching of -// template overloads: the final frontier. -template -char (&ArraySizeHelper(const T (&array)[N]))[N]; -#endif - - // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, // but can be used on anonymous types or types defined inside // functions. It's less safe than arraysize as it accepts some @@ -90,6 +61,46 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; static_cast(!(sizeof(a) % sizeof(*(a))))) // NOLINT +#if V8_OS_NACL + +// TODO(bmeurer): For some reason, the NaCl toolchain cannot handle the correct +// definition of arraysize() below, so we have to use the unsafe version for +// now. +#define arraysize ARRAYSIZE_UNSAFE + +#else // V8_OS_NACL + +// The arraysize(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. If you use arraysize on +// a pointer by mistake, you will get a compile-time error. +// +// One caveat is that arraysize() doesn't accept any array of an +// anonymous type or a type defined inside a function. In these rare +// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is +// due to a limitation in C++'s template system. The limitation might +// eventually be removed, but it hasn't happened yet. +#define arraysize(array) (sizeof(ArraySizeHelper(array))) + + +// This template function declaration is used in defining arraysize. +// Note that the function doesn't need an implementation, as we only +// use its type. +template +char (&ArraySizeHelper(T (&array)[N]))[N]; + + +#if !V8_CC_MSVC +// That gcc wants both of these prototypes seems mysterious. VC, for +// its part, can't decide which to use (another mystery). Matching of +// template overloads: the final frontier. +template +char (&ArraySizeHelper(const T (&array)[N]))[N]; +#endif + +#endif // V8_OS_NACL + + // A macro to disallow the evil copy constructor and operator= functions // This should be used in the private: declarations for a class #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ diff --git a/src/serialize.cc b/src/serialize.cc index 0e5ab064bc..d13b00cfcc 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -314,7 +314,7 @@ void ExternalReferenceTable::PopulateTable(Isolate* isolate) { #undef IC_ENTRY }; // end of ref_table[]. - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ref_table); ++i) { + for (size_t i = 0; i < arraysize(ref_table); ++i) { AddFromId(ref_table[i].type, ref_table[i].id, ref_table[i].name, @@ -340,7 +340,7 @@ void ExternalReferenceTable::PopulateTable(Isolate* isolate) { }; // end of stats_ref_table[]. Counters* counters = isolate->counters(); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(stats_ref_table); ++i) { + for (size_t i = 0; i < arraysize(stats_ref_table); ++i) { Add(reinterpret_cast
(GetInternalPointer( (counters->*(stats_ref_table[i].counter))())), STATS_COUNTER,