Chromium Code Reviews| Index: src/base/macros.h |
| diff --git a/src/base/macros.h b/src/base/macros.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3253d84ab549b92ef271b87dd291d409197205a6 |
| --- /dev/null |
| +++ b/src/base/macros.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +#ifndef V8_BASE_MACROS_H_ |
| +#define V8_BASE_MACROS_H_ |
| + |
| +#include "../../include/v8stdint.h" |
|
Sven Panne
2014/04/23 11:38:35
Just a note: I think we have to reconsider our inc
jochen (gone - plz use gerrit)
2014/04/23 11:50:15
Yes
|
| + |
| + |
| +// The expression OFFSET_OF(type, field) computes the byte-offset |
| +// of the specified field relative to the containing type. This |
| +// corresponds to 'offsetof' (in stddef.h), except that it doesn't |
| +// use 0 or NULL, which causes a problem with the compiler warnings |
| +// we have enabled (which is also why 'offsetof' doesn't seem to work). |
| +// Here we simply use the non-zero value 4, which seems to work. |
|
Nico
2015/06/16 21:02:46
Is this really still needed? Other places use offs
Sven Panne
2015/06/17 07:42:13
Alas, yes. :-/ I made a mechanical CL (https://cod
|
| +#define OFFSET_OF(type, field) \ |
| + (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) |
| + |
| + |
| +// The expression ARRAY_SIZE(a) is a compile-time constant of type |
| +// size_t which represents the number of elements of the given |
| +// array. You should only use ARRAY_SIZE on statically allocated |
| +// arrays. |
| +#define ARRAY_SIZE(a) \ |
| + ((sizeof(a) / sizeof(*(a))) / \ |
| + static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) |
|
Sven Panne
2014/04/23 11:38:35
This has been here before, but anyway: The divisor
jochen (gone - plz use gerrit)
2014/04/23 11:50:15
See https://code.google.com/p/chromium/codesearch#
|
| + |
| + |
| +// 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) \ |
| + TypeName(const TypeName&) V8_DELETE; \ |
| + void operator=(const TypeName&) V8_DELETE |
| + |
| + |
| +// A macro to disallow all the implicit constructors, namely the |
| +// default constructor, copy constructor and operator= functions. |
| +// |
| +// This should be used in the private: declarations for a class |
| +// that wants to prevent anyone from instantiating it. This is |
| +// especially useful for classes containing only static methods. |
| +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
| + TypeName() V8_DELETE; \ |
| + DISALLOW_COPY_AND_ASSIGN(TypeName) |
| + |
| + |
| +// Newly written code should use V8_INLINE and V8_NOINLINE directly. |
| +#define INLINE(declarator) V8_INLINE declarator |
| +#define NO_INLINE(declarator) V8_NOINLINE declarator |
| + |
| + |
| +// Newly written code should use V8_WARN_UNUSED_RESULT. |
| +#define MUST_USE_RESULT V8_WARN_UNUSED_RESULT |
| + |
| + |
| +// Define DISABLE_ASAN macros. |
| +#if defined(__has_feature) |
| +#if __has_feature(address_sanitizer) |
| +#define DISABLE_ASAN __attribute__((no_sanitize_address)) |
| +#endif |
| +#endif |
| + |
| + |
| +#ifndef DISABLE_ASAN |
| +#define DISABLE_ASAN |
| +#endif |
| + |
| + |
| +#if V8_CC_GNU |
| +#define V8_IMMEDIATE_CRASH() __builtin_trap() |
| +#else |
| +#define V8_IMMEDIATE_CRASH() ((void(*)())0)() |
| +#endif |
| + |
| +#endif // V8_BASE_MACROS_H_ |