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

Side by Side Diff: runtime/platform/globals.h

Issue 13994008: - Add OS::StrNDup instead of redefining it when needed. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months 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
« no previous file with comments | « no previous file | runtime/vm/isolate.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 PLATFORM_GLOBALS_H_ 5 #ifndef PLATFORM_GLOBALS_H_
6 #define PLATFORM_GLOBALS_H_ 6 #define PLATFORM_GLOBALS_H_
7 7
8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to
9 // enable platform independent printf format specifiers. 9 // enable platform independent printf format specifiers.
10 #ifndef __STDC_FORMAT_MACROS 10 #ifndef __STDC_FORMAT_MACROS
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 inline D bit_copy(const S& source) { 389 inline D bit_copy(const S& source) {
390 D destination; 390 D destination;
391 // This use of memcpy is safe: source and destination cannot overlap. 391 // This use of memcpy is safe: source and destination cannot overlap.
392 memcpy(&destination, 392 memcpy(&destination,
393 reinterpret_cast<const void*>(&source), 393 reinterpret_cast<const void*>(&source),
394 sizeof(destination)); 394 sizeof(destination));
395 return destination; 395 return destination;
396 } 396 }
397 397
398 398
399 // Some platforms do not support strndup. We add it below as necessary.
400 #if defined(TARGET_OS_MACOS)
401 // strndup has only been added to Mac OS X in 10.7. We are supplying
402 // our own copy here.
403 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \
404 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060
405 #define NEEDS_STRNDUP 1
406 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
407 #elif defined(TARGET_OS_WINDOWS)
408 #define NEEDS_STRNDUP 1
409 #endif // defined(TARGET_OS_MACOS)
410
411 #if defined(NEEDS_STRNDUP)
412 // size_t used to match function signature on other platforms.
413 inline char* strndup(const char* s, size_t n) {
414 size_t len = strlen(s);
415 if (n < len) {
416 len = n;
417 }
418 char* result = reinterpret_cast<char*>(malloc(len + 1));
419 if (!result) {
420 return NULL;
421 }
422 result[len] = '\0';
423 return reinterpret_cast<char*>(memcpy(result, s, len));
424 }
425 #endif // defined(NEEDS_STRNDUP)
426 #undef NEEDS_STRNDUP
427
428
429 // A macro to ensure that memcpy cannot be called. memcpy does not handle 399 // A macro to ensure that memcpy cannot be called. memcpy does not handle
430 // overlapping memory regions. Even though this is well documented it seems 400 // overlapping memory regions. Even though this is well documented it seems
431 // to be used in error quite often. To avoid problems we disallow the direct 401 // to be used in error quite often. To avoid problems we disallow the direct
432 // use of memcpy here. 402 // use of memcpy here.
433 // 403 //
434 // On Android and Windows the basic libraries use memcpy and therefore 404 // On Android and Windows the basic libraries use memcpy and therefore
435 // compilation will fail if memcpy is overwritten even if user code does not 405 // compilation will fail if memcpy is overwritten even if user code does not
436 // use memcpy. 406 // use memcpy.
437 #if defined(memcpy) 407 #if defined(memcpy)
438 #undef memcpy 408 #undef memcpy
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods 448 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods
479 // have an implicit 'this' argument, the arguments of such methods 449 // have an implicit 'this' argument, the arguments of such methods
480 // should be counted from two, not one." 450 // should be counted from two, not one."
481 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ 451 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \
482 __attribute__((__format__(__printf__, string_index, first_to_check))) 452 __attribute__((__format__(__printf__, string_index, first_to_check)))
483 #else 453 #else
484 #define PRINTF_ATTRIBUTE(string_index, first_to_check) 454 #define PRINTF_ATTRIBUTE(string_index, first_to_check)
485 #endif 455 #endif
486 456
487 #endif // PLATFORM_GLOBALS_H_ 457 #endif // PLATFORM_GLOBALS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698