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

Side by Side Diff: vm/globals.h

Issue 8555024: - Avoid allocating variable length arrays on the stack. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_GLOBALS_H_ 5 #ifndef VM_GLOBALS_H_
6 #define VM_GLOBALS_H_ 6 #define VM_GLOBALS_H_
7 7
8 // __STDC_FORMAT_MACROS has to be defined to enable platform independent printf. 8 // __STDC_FORMAT_MACROS has to be defined to enable platform independent printf.
9 #ifndef __STDC_FORMAT_MACROS 9 #ifndef __STDC_FORMAT_MACROS
10 #define __STDC_FORMAT_MACROS 10 #define __STDC_FORMAT_MACROS
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 // Similar to bit_cast, but allows copying from types of unrelated 309 // Similar to bit_cast, but allows copying from types of unrelated
310 // sizes. This method was introduced to enable the strict aliasing 310 // sizes. This method was introduced to enable the strict aliasing
311 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on 311 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on
312 // obscure details in the C++ standard that make reinterpret_cast 312 // obscure details in the C++ standard that make reinterpret_cast
313 // virtually useless. 313 // virtually useless.
314 template<class D, class S> 314 template<class D, class S>
315 inline D bit_copy(const S& source) { 315 inline D bit_copy(const S& source) {
316 D destination; 316 D destination;
317 // This use of memcpy is safe: source and destination cannot overlap. 317 // This use of memcpy is safe: source and destination cannot overlap.
318 memcpy(&destination, &source, sizeof(destination)); 318 memcpy(&destination,
319 reinterpret_cast<const void*>(&source),
320 sizeof(destination));
319 return destination; 321 return destination;
320 } 322 }
321 323
322 // A macro to ensure that memcpy cannot be called. memcpy does not handle 324 // A macro to ensure that memcpy cannot be called. memcpy does not handle
323 // overlapping memory regions. Even though this is well documented it seems 325 // overlapping memory regions. Even though this is well documented it seems
324 // to be used in error quite often. To avoid problems we disallow the direct 326 // to be used in error quite often. To avoid problems we disallow the direct
325 // use of memcpy here. 327 // use of memcpy here.
326 // 328 //
327 // On Windows the basic libraries use memcpy and therefore compilation will 329 // On Windows the basic libraries use memcpy and therefore compilation will
328 // fail if memcpy is overwritten even if user code does not use memcpy. 330 // fail if memcpy is overwritten even if user code does not use memcpy.
329 #if defined(memcpy) 331 #if defined(memcpy)
330 #undef memcpy 332 #undef memcpy
331 #endif 333 #endif
332 #if !defined(TARGET_OS_WINDOWS) 334 #if !defined(TARGET_OS_WINDOWS)
333 #define memcpy "Please use memmove instead of memcpy." 335 #define memcpy "Please use memmove instead of memcpy."
334 #endif 336 #endif
335 337
336 338
337 // When using GCC we can use GCC attributes to ensure that certain 339 // When using GCC we can use GCC attributes to ensure that certain
338 // contants are 16 byte aligned. 340 // contants are 16 byte aligned.
339 #if defined(TARGET_OS_WINDOWS) 341 #if defined(TARGET_OS_WINDOWS)
340 #define ALIGN16 __declspec(align(16)) 342 #define ALIGN16 __declspec(align(16))
341 #else 343 #else
342 #define ALIGN16 __attribute__((aligned(16))) 344 #define ALIGN16 __attribute__((aligned(16)))
343 #endif 345 #endif
344 346
345 } // namespace dart 347 } // namespace dart
346 348
347 #endif // VM_GLOBALS_H_ 349 #endif // VM_GLOBALS_H_
OLDNEW
« bin/process_linux.cc ('K') | « bin/process_macos.cc ('k') | vm/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698