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

Unified Diff: runtime/bin/dartutils.cc

Issue 9403012: Add utility functions for creating and accessing Dart_CObject structures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed Dart_ZoneAllocate to Dart_ScopeAllocate Created 8 years, 10 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
« runtime/bin/dartutils.h ('K') | « runtime/bin/dartutils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dartutils.cc
diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc
index cb0ae2bac099356a22c9d3b2b502fd65866c60cd..c7984e88d41569340510e3a6718bcff16744c28c 100644
--- a/runtime/bin/dartutils.cc
+++ b/runtime/bin/dartutils.cc
@@ -252,9 +252,7 @@ const char* DartUtils::GetCanonicalPath(const char* reference_dir,
bool DartUtils::PostNull(Dart_Port port_id) {
// Post a message with just the null object.
- Dart_CObject object;
- object.type = Dart_CObject::kNull;
- return Dart_PostCObject(port_id, &object);
+ return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject());
}
@@ -268,3 +266,89 @@ bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) {
object.value.as_int32 = value;
return Dart_PostCObject(port_id, &object);
}
+
+
+// Statically allocated Dart_Cobject instances for immutable
Mads Ager (google) 2012/02/20 12:38:38 Dart_CObject?
Søren Gjesse 2012/02/21 08:24:25 Done.
+// objects. As these will be used by different threads the use of
+// these is depending on that the marking internally in the
Mads Ager (google) 2012/02/20 12:38:38 is depending on that -> depends on the fact that ?
Søren Gjesse 2012/02/21 08:24:25 Done.
+// Dart_CObject structure is not marking simple value objects.
+Dart_CObject CObject::api_null_ = {Dart_CObject::kNull , { 0 } };
Mads Ager (google) 2012/02/20 12:38:38 I would add space between '{' and Dart_CObject.
Søren Gjesse 2012/02/21 08:24:25 Done.
+Dart_CObject CObject::api_true_ = {Dart_CObject::kBool , { true } };
+Dart_CObject CObject::api_false_ = {Dart_CObject::kBool, { false } };
+CObject CObject::null_ = CObject(&api_null_);
+CObject CObject::true_ = CObject(&api_true_);
+CObject CObject::false_ = CObject(&api_false_);
+
+
+CObject* CObject::Null() {
+ return &null_;
+}
+
+
+CObject* CObject::True() {
+ return &true_;
+}
+
+
+CObject* CObject::False() {
+ return &false_;
+}
+
+
+CObject* CObject::Bool(bool value) {
+ return value ? &true_ : &false_;
+}
+
+
+Dart_CObject* CObject::New(Dart_CObject::Type type, int additional_bytes) {
+ Dart_CObject* cobject = reinterpret_cast<Dart_CObject*>(
+ Dart_ScopeAllocate(sizeof(Dart_CObject) + additional_bytes));
+ cobject->type = type;
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewInt32(int32_t value) {
+ Dart_CObject* cobject = New(Dart_CObject::kInt32);
+ cobject->value.as_int32 = value;
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewInt64(int64_t value) {
+ Dart_CObject* cobject = New(Dart_CObject::kInt64);
+ cobject->value.as_int64 = value;
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewDouble(double value) {
+ Dart_CObject* cobject = New(Dart_CObject::kDouble);
+ cobject->value.as_double = value;
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewString(int length) {
+ Dart_CObject* cobject = New(Dart_CObject::kString, length + 1);
+ cobject->value.as_string = reinterpret_cast<char*>(cobject + 1);
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewString(const char* str) {
+ int length = strlen(str);
+ Dart_CObject* cobject = NewString(length);
+ memmove(cobject->value.as_string, str, length + 1);
+ return cobject;
+}
+
+
+Dart_CObject* CObject::NewArray(int length) {
+ Dart_CObject* cobject =
+ New(Dart_CObject::kArray, length * sizeof(Dart_CObject*)); // NOLINT
+ cobject->value.as_array.length = length;
+ cobject->value.as_array.values =
+ reinterpret_cast<Dart_CObject**>(cobject + 1);
+ return cobject;
+}
« runtime/bin/dartutils.h ('K') | « runtime/bin/dartutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698