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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8585049: Add an interface for retrieving the value of unsigned 64-bit integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years 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
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index a3a9e2a0eebc05f38a283817edd43948d6bcfc3b..2547fcb180d8b77134103ed56491fbb5673350ed 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -971,6 +971,29 @@ DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
}
+DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
+ bool* fits) {
+ DARTSCOPE(Isolate::Current());
+ const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
turnidge 2011/12/08 18:26:25 I've been doing things a new way. Sorry I didn't
cshapiro 2011/12/08 22:50:50 Done. I will put together a separate change for D
+ if (obj.IsSmi() || obj.IsMint()) {
+ Integer& integer = Integer::Handle();
+ integer ^= obj.raw();
+ if (integer.IsNegative()) {
+ *fits = false;
+ } else {
+ *fits = true;
+ }
+ return Api::Success();
+ } else if (obj.IsBigint()) {
+ Bigint& bigint = Bigint::Handle();
+ bigint ^= obj.raw();
+ *fits = BigintOperations::FitsIntoUint64(bigint);
+ return Api::Success();
+ }
+ return Api::Error("Object is not a Integer");
+}
+
+
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
DARTSCOPE(Isolate::Current());
const Integer& obj = Integer::Handle(Integer::New(value));
@@ -986,7 +1009,8 @@ DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
}
-DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
+DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
+ int64_t* value) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
turnidge 2011/12/08 18:26:25 Do you mind changing this to use UnwrapIntegerHand
cshapiro 2011/12/08 22:50:50 Done.
if (obj.IsSmi() || obj.IsMint()) {
@@ -1009,8 +1033,36 @@ DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
}
-DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
- const char** value) {
+DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
+ uint64_t* value) {
+ DARTSCOPE(Isolate::Current());
+ const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
turnidge 2011/12/08 18:26:25 UnwrapIntegerHandle here too?
cshapiro 2011/12/08 22:50:50 Done.
+ if (obj.IsSmi() || obj.IsMint()) {
+ Integer& integer = Integer::Handle();
+ integer ^= obj.raw();
+ if (integer.IsNegative()) {
+ return Api::Error("Integer too small to fit in uint64_t");
turnidge 2011/12/08 18:26:25 Fixup error message as suggested for IntegerToInt6
cshapiro 2011/12/08 22:50:50 Done. I have created a single call to error with
+ }
+ integer ^= obj.raw();
+ *value = integer.AsInt64Value();
+ return Api::Success();
+ }
+ if (obj.IsBigint()) {
+ Bigint& bigint = Bigint::Handle();
+ bigint ^= obj.raw();
+ if (BigintOperations::FitsIntoUint64(bigint)) {
+ *value = BigintOperations::ToUint64(bigint);
+ return Api::Success();
+ } else {
+ return Api::Error("Integer too big to fit in uint64_t");
turnidge 2011/12/08 18:26:25 Fixup error message as above.
cshapiro 2011/12/08 22:50:50 Done.
+ }
+ }
+ return Api::Error("Object is not a Integer");
+}
+
+
+DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
+ const char** value) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
turnidge 2011/12/08 18:26:25 UnwrapIntegerHandle here too?
cshapiro 2011/12/08 22:50:50 Done.
Bigint& bigint = Bigint::Handle();

Powered by Google App Engine
This is Rietveld 408576698