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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 707
708 708
709 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 709 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
710 DARTSCOPE(Isolate::Current()); 710 DARTSCOPE(Isolate::Current());
711 const String& str_obj = String::Handle(String::New(str)); 711 const String& str_obj = String::Handle(String::New(str));
712 const Integer& obj = Integer::Handle(Integer::New(str_obj)); 712 const Integer& obj = Integer::Handle(Integer::New(str_obj));
713 return Api::NewLocalHandle(obj); 713 return Api::NewLocalHandle(obj);
714 } 714 }
715 715
716 716
717 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { 717 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
718 int64_t* value) {
718 DARTSCOPE(Isolate::Current()); 719 DARTSCOPE(Isolate::Current());
719 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 720 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
720 if (obj.IsSmi() || obj.IsMint()) { 721 if (obj.IsSmi() || obj.IsMint()) {
721 Integer& integer = Integer::Handle(); 722 Integer& integer = Integer::Handle();
722 integer ^= obj.raw(); 723 integer ^= obj.raw();
723 *value = integer.AsInt64Value(); 724 *value = integer.AsInt64Value();
724 return Api::Success(); 725 return Api::Success();
725 } 726 }
726 if (obj.IsBigint()) { 727 if (obj.IsBigint()) {
727 Bigint& bigint = Bigint::Handle(); 728 Bigint& bigint = Bigint::Handle();
728 bigint ^= obj.raw(); 729 bigint ^= obj.raw();
729 if (BigintOperations::FitsIntoInt64(bigint)) { 730 if (BigintOperations::FitsIntoInt64(bigint)) {
730 *value = BigintOperations::ToInt64(bigint); 731 *value = BigintOperations::ToInt64(bigint);
731 return Api::Success(); 732 return Api::Success();
732 } else { 733 } else {
733 return Api::Error("Integer too big to fit in int64_t"); 734 return Api::Error("Integer too big to fit in int64_t");
734 } 735 }
735 } 736 }
736 return Api::Error("Object is not a Integer"); 737 return Api::Error("Object is not a Integer");
737 } 738 }
738 739
739 740
741 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
742 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.
743 DARTSCOPE(Isolate::Current());
744 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
745 if (obj.IsSmi() || obj.IsMint()) {
746 Integer& integer = Integer::Handle();
747 integer ^= obj.raw();
748 if (integer.IsNegative()) {
749 return Api::Error("Integer too small to fit in uint64_t");
750 }
751 integer ^= obj.raw();
752 *value = integer.AsInt64Value();
753 return Api::Success();
754 }
755 if (obj.IsBigint()) {
756 Bigint& bigint = Bigint::Handle();
757 bigint ^= obj.raw();
758 if (BigintOperations::FitsIntoUint64(bigint)) {
759 *value = BigintOperations::ToUint64(bigint);
760 return Api::Success();
761 } else {
762 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
763 }
764 }
765 return Api::Error("Object is not a Integer");
766 }
767
768
740 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, 769 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
741 const char** value) { 770 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
742 DARTSCOPE(Isolate::Current()); 771 DARTSCOPE(Isolate::Current());
743 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 772 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
744 Bigint& bigint = Bigint::Handle(); 773 Bigint& bigint = Bigint::Handle();
745 if (obj.IsSmi() || obj.IsMint()) { 774 if (obj.IsSmi() || obj.IsMint()) {
746 Integer& integer = Integer::Handle(); 775 Integer& integer = Integer::Handle();
747 integer ^= obj.raw(); 776 integer ^= obj.raw();
748 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value()); 777 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value());
749 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); 778 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
750 return Api::Success(); 779 return Api::Success();
751 } 780 }
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2147 ASSERT(isolate != NULL); 2176 ASSERT(isolate != NULL);
2148 ApiState* state = isolate->api_state(); 2177 ApiState* state = isolate->api_state();
2149 ASSERT(state != NULL); 2178 ASSERT(state != NULL);
2150 ApiLocalScope* scope = state->top_scope(); 2179 ApiLocalScope* scope = state->top_scope();
2151 ASSERT(scope != NULL); 2180 ASSERT(scope != NULL);
2152 return scope->zone().Reallocate(ptr, old_size, new_size); 2181 return scope->zone().Reallocate(ptr, old_size, new_size);
2153 } 2182 }
2154 2183
2155 2184
2156 } // namespace dart 2185 } // namespace dart
OLDNEW
« 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