Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #ifndef V8_BASE_MACROS_H_ | |
| 29 #define V8_BASE_MACROS_H_ | |
| 30 | |
| 31 #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
| |
| 32 | |
| 33 | |
| 34 // The expression OFFSET_OF(type, field) computes the byte-offset | |
| 35 // of the specified field relative to the containing type. This | |
| 36 // corresponds to 'offsetof' (in stddef.h), except that it doesn't | |
| 37 // use 0 or NULL, which causes a problem with the compiler warnings | |
| 38 // we have enabled (which is also why 'offsetof' doesn't seem to work). | |
| 39 // 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
| |
| 40 #define OFFSET_OF(type, field) \ | |
| 41 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) | |
| 42 | |
| 43 | |
| 44 // The expression ARRAY_SIZE(a) is a compile-time constant of type | |
| 45 // size_t which represents the number of elements of the given | |
| 46 // array. You should only use ARRAY_SIZE on statically allocated | |
| 47 // arrays. | |
| 48 #define ARRAY_SIZE(a) \ | |
| 49 ((sizeof(a) / sizeof(*(a))) / \ | |
| 50 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#
| |
| 51 | |
| 52 | |
| 53 // A macro to disallow the evil copy constructor and operator= functions | |
| 54 // This should be used in the private: declarations for a class | |
| 55 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
| 56 TypeName(const TypeName&) V8_DELETE; \ | |
| 57 void operator=(const TypeName&) V8_DELETE | |
| 58 | |
| 59 | |
| 60 // A macro to disallow all the implicit constructors, namely the | |
| 61 // default constructor, copy constructor and operator= functions. | |
| 62 // | |
| 63 // This should be used in the private: declarations for a class | |
| 64 // that wants to prevent anyone from instantiating it. This is | |
| 65 // especially useful for classes containing only static methods. | |
| 66 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | |
| 67 TypeName() V8_DELETE; \ | |
| 68 DISALLOW_COPY_AND_ASSIGN(TypeName) | |
| 69 | |
| 70 | |
| 71 // Newly written code should use V8_INLINE and V8_NOINLINE directly. | |
| 72 #define INLINE(declarator) V8_INLINE declarator | |
| 73 #define NO_INLINE(declarator) V8_NOINLINE declarator | |
| 74 | |
| 75 | |
| 76 // Newly written code should use V8_WARN_UNUSED_RESULT. | |
| 77 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT | |
| 78 | |
| 79 | |
| 80 // Define DISABLE_ASAN macros. | |
| 81 #if defined(__has_feature) | |
| 82 #if __has_feature(address_sanitizer) | |
| 83 #define DISABLE_ASAN __attribute__((no_sanitize_address)) | |
| 84 #endif | |
| 85 #endif | |
| 86 | |
| 87 | |
| 88 #ifndef DISABLE_ASAN | |
| 89 #define DISABLE_ASAN | |
| 90 #endif | |
| 91 | |
| 92 | |
| 93 #if V8_CC_GNU | |
| 94 #define V8_IMMEDIATE_CRASH() __builtin_trap() | |
| 95 #else | |
| 96 #define V8_IMMEDIATE_CRASH() ((void(*)())0)() | |
| 97 #endif | |
| 98 | |
| 99 #endif // V8_BASE_MACROS_H_ | |
| OLD | NEW |