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

Unified Diff: runtime/vm/object.cc

Issue 580903004: Make sure Bigint._digits is always a Uint32List (instead of sometimes null). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 40444)
+++ runtime/vm/object.cc (working copy)
@@ -16264,6 +16264,8 @@
void Bigint::set_digits(const TypedData& value) const {
+ // The VM expects digits_ to be a Uint32List (not null).
+ ASSERT(!value.IsNull() && (value.GetClassId() == kTypedDataUint32ArrayCid));
StorePointer(&raw_ptr()->digits_, value.raw());
}
@@ -16341,15 +16343,16 @@
ASSERT(!digits_.IsNull());
set_digits(digits_);
} else {
- ASSERT(digits() == TypedData::null());
+ ASSERT(digits() == TypedData::EmptyUint32Array(Isolate::Current()));
}
return true;
}
RawBigint* Bigint::New(Heap::Space space) {
- ASSERT(Isolate::Current()->object_store()->bigint_class() != Class::null());
- Bigint& result = Bigint::Handle();
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate->object_store()->bigint_class() != Class::null());
+ Bigint& result = Bigint::Handle(isolate);
{
RawObject* raw = Object::Allocate(Bigint::kClassId,
Bigint::InstanceSize(),
@@ -16358,7 +16361,9 @@
result ^= raw;
}
result.set_neg(Bool::Get(false));
- result.set_used(Smi::Handle(Smi::New(0)));
+ result.set_used(Smi::Handle(isolate, Smi::New(0)));
+ result.set_digits(
+ TypedData::Handle(isolate, TypedData::EmptyUint32Array(isolate)));
return result.raw();
}
@@ -16423,10 +16428,10 @@
void Bigint::EnsureLength(intptr_t length, Heap::Space space) const {
ASSERT(length >= 0);
TypedData& old_digits = TypedData::Handle(digits());
- if ((length > 0) && (old_digits.IsNull() || (length > old_digits.Length()))) {
+ if ((length > 0) && (length > old_digits.Length())) {
TypedData& new_digits = TypedData::Handle(
TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space));
- if (!old_digits.IsNull()) {
+ if (old_digits.Length() > 0) {
TypedData::Copy(new_digits, TypedData::data_offset(),
old_digits, TypedData::data_offset(),
old_digits.LengthInBytes());
@@ -19635,6 +19640,20 @@
}
+RawTypedData* TypedData::EmptyUint32Array(Isolate* isolate) {
+ ASSERT(isolate != NULL);
+ ASSERT(isolate->object_store() != NULL);
+ if (isolate->object_store()->empty_uint32_array() != TypedData::null()) {
+ // Already created.
+ return isolate->object_store()->empty_uint32_array();
+ }
+ const TypedData& array = TypedData::Handle(isolate,
+ TypedData::New(kTypedDataUint32ArrayCid, 0, Heap::kOld));
+ isolate->object_store()->set_empty_uint32_array(array);
+ return array.raw();
+}
+
+
const char* TypedData::ToCString() const {
return "TypedData";
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698