Index: runtime/bin/dartutils.h |
diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h |
index 1d18b5f96e58729e7c48fd7d85dfa64065cfae06..259d84986f5a1e1c30e83dbbbb6d9b73012a5cf5 100644 |
--- a/runtime/bin/dartutils.h |
+++ b/runtime/bin/dartutils.h |
@@ -165,6 +165,23 @@ class DartUtils { |
strlen(str)); |
} |
+ // Allocate length bytes for a C string with Dart_ScopeAllocate. |
+ static char* ScopedCString(intptr_t length) { |
+ char* result = NULL; |
+ result = reinterpret_cast<char*>( |
+ Dart_ScopeAllocate(length * sizeof(*result))); |
+ return result; |
+ } |
+ |
+ // Copy str into a buffer allocated with Dart_ScopeAllocate. |
+ static char* ScopedCopyCString(const char* str) { |
+ size_t str_len = strlen(str); |
+ char* result = ScopedCString(str_len + 1); |
+ strncpy(result, str, str_len); |
Ivan Posva
2016/03/13 20:59:18
Could you use memcpy or memmove instead? There is
zra
2016/03/14 18:07:52
Done.
|
+ result[str_len] = '\0'; |
+ return result; |
+ } |
+ |
// Create a new Dart InternalError object with the provided message. |
static Dart_Handle NewError(const char* format, ...); |
static Dart_Handle NewInternalError(const char* message); |