Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: src/base/macros.h

Issue 734873002: Use 16 instead of 4 for determining member offsets. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/heap/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_BASE_MACROS_H_ 5 #ifndef V8_BASE_MACROS_H_
6 #define V8_BASE_MACROS_H_ 6 #define V8_BASE_MACROS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <cstring> 11 #include <cstring>
12 12
13 #include "src/base/build_config.h" 13 #include "src/base/build_config.h"
14 #include "src/base/compiler-specific.h" 14 #include "src/base/compiler-specific.h"
15 #include "src/base/logging.h" 15 #include "src/base/logging.h"
16 16
17 17
18 // The expression OFFSET_OF(type, field) computes the byte-offset 18 // The expression OFFSET_OF(type, field) computes the byte-offset
19 // of the specified field relative to the containing type. This 19 // of the specified field relative to the containing type. This
20 // corresponds to 'offsetof' (in stddef.h), except that it doesn't 20 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
21 // use 0 or NULL, which causes a problem with the compiler warnings 21 // use 0 or NULL, which causes a problem with the compiler warnings
22 // we have enabled (which is also why 'offsetof' doesn't seem to work). 22 // we have enabled (which is also why 'offsetof' doesn't seem to work).
23 // Here we simply use the non-zero value 4, which seems to work. 23 // Here we simply use the aligned, non-zero value 16.
24 #define OFFSET_OF(type, field) \ 24 #define OFFSET_OF(type, field) \
25 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) 25 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(16)->field)) - 16)
26 26
27 27
28 #if V8_OS_NACL 28 #if V8_OS_NACL
29 29
30 // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, 30 // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize,
31 // but can be used on anonymous types or types defined inside 31 // but can be used on anonymous types or types defined inside
32 // functions. It's less safe than arraysize as it accepts some 32 // functions. It's less safe than arraysize as it accepts some
33 // (although not all) pointers. Therefore, you should use arraysize 33 // (although not all) pointers. Therefore, you should use arraysize
34 // whenever possible. 34 // whenever possible.
35 // 35 //
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 409 }
410 410
411 template <> 411 template <>
412 inline bool is_fundamental<uint8_t>() { 412 inline bool is_fundamental<uint8_t>() {
413 return true; 413 return true;
414 } 414 }
415 } 415 }
416 } // namespace v8::base 416 } // namespace v8::base
417 417
418 #endif // V8_BASE_MACROS_H_ 418 #endif // V8_BASE_MACROS_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698