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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 2997173002: [vm] Remove Dart_MakeExternalString and --support-externalizable-strings (Closed)
Patch Set: Update vm.status Created 3 years, 4 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "lib/stacktrace.h" 9 #include "lib/stacktrace.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #if defined(DART_NO_SNAPSHOT) 64 #if defined(DART_NO_SNAPSHOT)
65 DEFINE_FLAG(bool, 65 DEFINE_FLAG(bool,
66 check_function_fingerprints, 66 check_function_fingerprints,
67 true, 67 true,
68 "Check function fingerprints"); 68 "Check function fingerprints");
69 #endif // defined(DART_NO_SNAPSHOT). 69 #endif // defined(DART_NO_SNAPSHOT).
70 DEFINE_FLAG(bool, 70 DEFINE_FLAG(bool,
71 verify_acquired_data, 71 verify_acquired_data,
72 false, 72 false,
73 "Verify correct API acquire/release of typed data."); 73 "Verify correct API acquire/release of typed data.");
74 DEFINE_FLAG(bool,
75 support_externalizable_strings,
76 false,
77 "Support Dart_MakeExternalString.");
78 74
79 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; 75 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey;
80 Dart_Handle Api::true_handle_ = NULL; 76 Dart_Handle Api::true_handle_ = NULL;
81 Dart_Handle Api::false_handle_ = NULL; 77 Dart_Handle Api::false_handle_ = NULL;
82 Dart_Handle Api::null_handle_ = NULL; 78 Dart_Handle Api::null_handle_ = NULL;
83 Dart_Handle Api::empty_string_handle_ = NULL; 79 Dart_Handle Api::empty_string_handle_ = NULL;
84 80
85 const char* CanonicalFunction(const char* func) { 81 const char* CanonicalFunction(const char* func) {
86 if (strncmp(func, "dart::", 6) == 0) { 82 if (strncmp(func, "dart::", 6) == 0) {
87 return func + 6; 83 return func + 6;
(...skipping 2380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 if (str_obj.IsNull()) { 2464 if (str_obj.IsNull()) {
2469 RETURN_TYPE_ERROR(thread->zone(), str, String); 2465 RETURN_TYPE_ERROR(thread->zone(), str, String);
2470 } 2466 }
2471 if (size == NULL) { 2467 if (size == NULL) {
2472 RETURN_NULL_ERROR(size); 2468 RETURN_NULL_ERROR(size);
2473 } 2469 }
2474 *size = (str_obj.Length() * str_obj.CharSize()); 2470 *size = (str_obj.Length() * str_obj.CharSize());
2475 return Api::Success(); 2471 return Api::Success();
2476 } 2472 }
2477 2473
2478 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
2479 void* array,
2480 intptr_t external_size,
2481 void* peer,
2482 Dart_PeerFinalizer cback) {
2483 DARTSCOPE(Thread::Current());
2484 if (!FLAG_support_externalizable_strings) {
2485 return Api::NewError(
2486 "Dart_MakeExternalString with "
2487 "--support_externalizable_strings=false");
2488 }
2489 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2490 if (str_obj.IsExternal()) {
2491 return str; // String is already an external string.
2492 }
2493 if (str_obj.IsNull()) {
2494 RETURN_TYPE_ERROR(Z, str, String);
2495 }
2496 if (array == NULL) {
2497 RETURN_NULL_ERROR(array);
2498 }
2499 intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
2500 if ((external_size < str_size) || (external_size > String::kMaxElements)) {
2501 return Api::NewError(
2502 "Dart_MakeExternalString "
2503 "expects argument external_size to be in the range"
2504 "[%" Pd "..%" Pd "].",
2505 str_size, String::kMaxElements);
2506 }
2507 if (str_obj.InVMHeap()) {
2508 // Since the string object is read only we do not externalize
2509 // the string but instead copy the contents of the string into the
2510 // specified buffer add the specified peer/cback as a Peer object
2511 // to this string. The Api::StringGetPeerHelper function picks up
2512 // the peer from the Peer table.
2513 intptr_t copy_len = str_obj.Length();
2514 if (str_obj.IsOneByteString()) {
2515 ASSERT(external_size >= copy_len);
2516 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array);
2517 for (intptr_t i = 0; i < copy_len; i++) {
2518 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i));
2519 }
2520 OneByteString::SetPeer(str_obj, external_size, peer, cback);
2521 } else {
2522 ASSERT(str_obj.IsTwoByteString());
2523 ASSERT(external_size >= (copy_len * str_obj.CharSize()));
2524 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array);
2525 for (intptr_t i = 0; i < copy_len; i++) {
2526 utf16_array[i] = str_obj.CharAt(i);
2527 }
2528 TwoByteString::SetPeer(str_obj, external_size, peer, cback);
2529 }
2530 return str;
2531 }
2532 return Api::NewHandle(
2533 T, str_obj.MakeExternal(array, external_size, peer, cback));
2534 }
2535
2536 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, 2474 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
2537 intptr_t* char_size, 2475 intptr_t* char_size,
2538 intptr_t* str_len, 2476 intptr_t* str_len,
2539 void** peer) { 2477 void** peer) {
2540 Thread* thread = Thread::Current(); 2478 Thread* thread = Thread::Current();
2541 CHECK_ISOLATE(thread->isolate()); 2479 CHECK_ISOLATE(thread->isolate());
2542 ReusableObjectHandleScope reused_obj_handle(thread); 2480 ReusableObjectHandleScope reused_obj_handle(thread);
2543 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); 2481 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object);
2544 if (str.IsNull()) { 2482 if (str.IsNull()) {
2545 RETURN_TYPE_ERROR(thread->zone(), object, String); 2483 RETURN_TYPE_ERROR(thread->zone(), object, String);
(...skipping 4257 matching lines...) Expand 10 before | Expand all | Expand 10 after
6803 #endif 6741 #endif
6804 } 6742 }
6805 6743
6806 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { 6744 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
6807 #ifndef PRODUCT 6745 #ifndef PRODUCT
6808 Profiler::DumpStackTrace(context); 6746 Profiler::DumpStackTrace(context);
6809 #endif 6747 #endif
6810 } 6748 }
6811 6749
6812 } // namespace dart 6750 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698