Index: runtime/vm/dart_api_message.cc |
diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc |
index cef65c67e1b7dcba785bc5d613ed87adaa6799f4..b51b357df3143e094dcdeb2ccb45d39aa8021c84 100644 |
--- a/runtime/vm/dart_api_message.cc |
+++ b/runtime/vm/dart_api_message.cc |
@@ -2,6 +2,8 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+#include <openssl/crypto.h> |
+ |
#include "vm/dart_api_message.h" |
#include "vm/object.h" |
#include "vm/object_store.h" |
@@ -80,6 +82,19 @@ Dart_CObject* ApiMessageReader::AllocateDartCObjectInt32(int32_t val) { |
} |
+Dart_CObject* ApiMessageReader::AllocateDartCObjectBigint(intptr_t length) { |
+ // Allocate a Dart_CObject structure followed by an array of chars |
+ // for the bigint hex string content. The pointer to the bigint |
+ // content is set up to this area. |
+ Dart_CObject* value = |
+ reinterpret_cast<Dart_CObject*>( |
+ alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
+ value->value.as_bigint = reinterpret_cast<char*>(value) + sizeof(*value); |
+ value->type = Dart_CObject::kBigint; |
+ return value; |
+} |
+ |
+ |
Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { |
Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); |
value->value.as_double = val; |
@@ -118,6 +133,17 @@ Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { |
} |
+uint8_t* ApiMessageReader::AllocateTemp(intptr_t size) { |
+ if (Isolate::Current() != NULL) { |
+ return reinterpret_cast<uint8_t*>( |
+ Isolate::Current()->current_zone()->Allocate(size)); |
+ } else { |
+ return reinterpret_cast<uint8_t*>( |
+ ApiNativeScope::Current()->zone()->Allocate(size)); |
+ } |
+} |
+ |
+ |
Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
// Read the class header information and lookup the class. |
intptr_t class_header = ReadIntptrValue(); |
@@ -167,6 +193,28 @@ Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
return value; |
break; |
} |
+ case ObjectStore::kBigintClass: { |
+ // Read in the HexCString representation of the bigint. |
+ intptr_t len = ReadIntptrValue(); |
+ char* hex_string = reinterpret_cast<char*>(AllocateTemp(len + 1)); |
siva
2012/02/09 01:47:27
Why do you use this special temp Allocator and not
Søren Gjesse
2012/02/09 14:08:33
The idea was that temporary data should be freed b
|
+ char* p = hex_string; |
+ for (intptr_t i = 0; i < len; i++) { |
+ *p = Read<uint8_t>(); |
+ p++; |
+ } |
+ *p = '\0'; |
+ // Convert the hex representation to decimal representation. |
+ BIGNUM* bn = BN_new(); |
+ BN_hex2bn(&bn, hex_string); |
+ char* dec_string = BN_bn2dec(bn); |
siva
2012/02/09 01:47:27
What is the advantage of converting this into a de
Søren Gjesse
2012/02/09 14:08:33
Keeping the hex string - no need for bigint operat
|
+ len = strlen(dec_string); |
+ Dart_CObject* object = AllocateDartCObjectBigint(len); |
+ memmove(object->value.as_bigint, dec_string, len + 1); |
+ OPENSSL_free(dec_string); |
+ BN_free(bn); |
+ return object; |
+ break; |
+ } |
case ObjectStore::kDoubleClass: { |
// Read the double value for the object. |
Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |