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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/flow_graph_inliner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 74458f5aaf9f365665bc5008b7fafff51428d7af..202a81fd5bdc560a189954585a4f80466eae9376 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -142,7 +142,7 @@ RawObject* Api::UnwrapHandle(Dart_Handle object) {
} \
return type::Handle(iso); \
}
-CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP)
+CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP)
#undef DEFINE_UNWRAP
@@ -1642,6 +1642,9 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
const char** cstr) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (cstr == NULL) {
+ RETURN_NULL_ERROR(cstr);
+ }
const String& str_obj = Api::UnwrapStringHandle(isolate, object);
if (str_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, object, String);
@@ -1660,20 +1663,27 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
- uint8_t* utf8_array,
+ uint8_t** utf8_array,
intptr_t* length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (utf8_array == NULL) {
+ RETURN_NULL_ERROR(utf8_array);
+ }
+ if (length == NULL) {
+ RETURN_NULL_ERROR(length);
+ }
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
if (str_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, str, String);
}
- intptr_t str_len = str_obj.Length();
- if (str_len > *length) {
- return Api::NewError("Input array is not large enough to hold the result");
+ intptr_t str_len = Utf8::Length(str_obj);
+ *utf8_array = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(str_len);
+ if (*utf8_array == NULL) {
+ return Api::NewError("Unable to allocate memory");
}
- str_obj.ToUTF8(utf8_array, str_len);
- *length= str_len;
+ str_obj.ToUTF8(*utf8_array, str_len);
+ *length = str_len;
return Api::Success(isolate);
}
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/flow_graph_inliner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698