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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10306002: Do not externalize Dart strings as C strings for "print()". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | no next file » | 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 c00397a71fb3c62b673eb8fafba47b9062ff7acc..b3f504fa48f02ba52e31d4614b85d1dffe7dc4b2 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -25,6 +25,7 @@
#include "vm/resolver.h"
#include "vm/stack_frame.h"
#include "vm/timer.h"
+#include "vm/unicode.h"
#include "vm/verifier.h"
namespace dart {
@@ -1611,6 +1612,35 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
}
+DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object,
+ const uint8_t** bytes,
+ intptr_t *length) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const String& str = Api::UnwrapStringHandle(isolate, object);
+ if (str.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, object, String);
+ }
+ if (bytes == NULL) {
+ return Api::NewError("%s expects argument 'bytes' to be non-null.",
+ CURRENT_FUNC);
+ }
+ if (length == NULL) {
+ return Api::NewError("%s expects argument 'length' to be non-null.",
+ CURRENT_FUNC);
+ }
+ const char* cstring = str.ToCString();
+ *length = Utf8::Length(str);
+ char* result = reinterpret_cast<char*>(Api::Allocate(isolate, *length));
+ if (result == NULL) {
+ return Api::NewError("Unable to allocate memory");
+ }
+ memmove(result, cstring, *length);
+ *bytes = result;
+ return Api::Success(isolate);
+}
+
+
// --- Lists ---
« no previous file with comments | « runtime/include/dart_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698