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

Issue 2992013002: [vm] Change TypedData_getUint64 native method to silently cast values (Closed)

Created:
3 years, 4 months ago by alexmarkov
Modified:
3 years, 4 months ago
Reviewers:
zra, siva
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

[vm] Change TypedData_getUint64 native method to silently cast values The TypedData_getUint64 native method is used to implement Uint64List and ByteData.getUint64(). When running in --limit-ints-to-64-bits mode (with Dart integers limited to 64 bits), this native method and its clients should silently cast values (with wrap-around) to signed 64-bit integer. This is the intended behavior, chosen to make it possible to work with arbitrary data. This CL changes underlying Integer::NewFromUint64() to do the silent conversion instead of returning Integer::null(). Another client of Integer::NewFromUint64, Dart_NewIntegerFromUint64 is changed to handle error without relying on Integer::NewFromUint64(). R=zra@google.com Issue: https://github.com/dart-lang/sdk/issues/30103 Committed: https://github.com/dart-lang/sdk/commit/41fb3c6d16f1d466d4e7968c2c677c415c397d7c

Patch Set 1 #

Total comments: 6

Patch Set 2 : Added test, review fixes #

Total comments: 2

Patch Set 3 : Loop test to verify optimized mode too #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+72 lines, -13 lines) Patch
M runtime/vm/dart_api_impl.cc View 1 1 chunk +4 lines, -5 lines 0 comments Download
M runtime/vm/object.h View 2 chunks +7 lines, -0 lines 0 comments Download
M runtime/vm/object.cc View 1 1 chunk +11 lines, -8 lines 2 comments Download
M tests/corelib_2/corelib_2.status View 1 2 1 chunk +1 line, -0 lines 0 comments Download
A tests/corelib_2/typed_data_with_limited_ints_test.dart View 1 2 1 chunk +49 lines, -0 lines 0 comments Download

Messages

Total messages: 11 (2 generated)
alexmarkov
3 years, 4 months ago (2017-07-28 20:53:12 UTC) #2
zra
Could you add a test for this behavior? https://codereview.chromium.org/2992013002/diff/1/runtime/vm/dart_api_impl.cc File runtime/vm/dart_api_impl.cc (right): https://codereview.chromium.org/2992013002/diff/1/runtime/vm/dart_api_impl.cc#newcode2095 runtime/vm/dart_api_impl.cc:2095: } ...
3 years, 4 months ago (2017-07-28 21:47:46 UTC) #3
alexmarkov
Added test for ByteData.set/getUint64, Uint64List with limited integers; fixed review comments. https://codereview.chromium.org/2992013002/diff/1/runtime/vm/dart_api_impl.cc File runtime/vm/dart_api_impl.cc (right): ...
3 years, 4 months ago (2017-07-28 23:09:30 UTC) #4
zra
https://codereview.chromium.org/2992013002/diff/20001/tests/corelib_2/typed_data_with_limited_ints_test.dart File tests/corelib_2/typed_data_with_limited_ints_test.dart (right): https://codereview.chromium.org/2992013002/diff/20001/tests/corelib_2/typed_data_with_limited_ints_test.dart#newcode45 tests/corelib_2/typed_data_with_limited_ints_test.dart:45: testByteData(); We should probably check that optimized code has ...
3 years, 4 months ago (2017-07-31 14:36:10 UTC) #5
alexmarkov
Added looping into the test. Also merged with the tip of the source tree, so ...
3 years, 4 months ago (2017-07-31 16:00:35 UTC) #6
zra
lgtm
3 years, 4 months ago (2017-07-31 20:42:58 UTC) #7
alexmarkov
Committed patchset #3 (id:40001) manually as 41fb3c6d16f1d466d4e7968c2c677c415c397d7c (presubmit successful).
3 years, 4 months ago (2017-07-31 21:06:39 UTC) #9
siva
https://codereview.chromium.org/2992013002/diff/40001/runtime/vm/object.cc File runtime/vm/object.cc (left): https://codereview.chromium.org/2992013002/diff/40001/runtime/vm/object.cc#oldcode18166 runtime/vm/object.cc:18166: return Integer::New(value, space); why is it not ok to ...
3 years, 4 months ago (2017-07-31 21:46:08 UTC) #10
alexmarkov
3 years, 4 months ago (2017-07-31 23:58:12 UTC) #11
Message was sent while issue was closed.
https://codereview.chromium.org/2992013002/diff/40001/runtime/vm/object.cc
File runtime/vm/object.cc (left):

https://codereview.chromium.org/2992013002/diff/40001/runtime/vm/object.cc#ol...
runtime/vm/object.cc:18166: return Integer::New(value, space);
On 2017/07/31 21:46:08, siva wrote:
> why is it not ok to just change this to 
>   return Integer::New(static_cast<int64_t>(value), space);
> 
> and not have this new function IsValidUint64 ... and drop the changes in
> Dart_NewIntegerFromUint64

Integer::NewFromUint64 is called from 2 places: Dart_NewIntegerFromUint64 and
TypedData_getUint64. The latter requires silent wrap-around, so range checking
is moved to Dart_NewIntegerFromUint64.

As per our discussion, I'm going to rename Integer::IsValidUint64 in order to
improve readability in the follow-up CL:
https://codereview.chromium.org/2992783002/

Powered by Google App Engine
This is Rietveld 408576698