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

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: Created 9 years, 1 month 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/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index f445bdb442af1c153a919c74f965d4caadba70c4..7640e6247a3826782c573050954a722fe7dcc821 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -714,7 +714,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));
if (obj.IsSmi() || obj.IsMint()) {
@@ -737,6 +738,34 @@ DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
}
+DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
+ uint64_t* value) {
turnidge 2011/11/17 23:19:02 Seeing "Uint64", I might actually prefer the form
cshapiro 2011/11/18 10:06:54 I agree, but I was the one who put the UInt into t
turnidge 2011/11/22 21:06:14 Okay, go ahead with Uint then. That seems okay.
+ DARTSCOPE(Isolate::Current());
+ const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
+ 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");
+ }
+ 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/11/17 23:19:02 Regarding the range checks here and above. Not su
cshapiro 2011/11/18 10:06:54 The missing negative test is an outright bug. (Th
+ }
+ }
+ return Api::Error("Object is not a Integer");
+}
+
+
DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
const char** value) {
turnidge 2011/11/17 23:19:02 I think we should make this name consistent with t
cshapiro 2011/11/18 10:06:54 We should certainly try and reduce the amount of n
DARTSCOPE(Isolate::Current());
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698