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

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: 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..bb88fd51ab6faea630a5caaabcb43356d6cf3269 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,27 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
}
+DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object,
+ const char** bytes,
cshapiro 2012/05/02 22:10:25 This is typed wrong, this should be a uint8_t, I'l
+ 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);
+ }
siva 2012/05/02 22:15:48 if (bytes == NULL) { return Api::NewError("%s ex
cshapiro 2012/05/02 22:40:59 Done. As an aside, I think we do not do enough ar
+ 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