-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: fix Region.storeNat32/loadNat32 and Region.storeInt32/loadInt…
…32 (#4335) bugfix: fix broken implementations of `Region.loadNat32`, `Region.storeNat32`, `Region.loadInt32`, `Region.storeInt32` (#4335). The operations were writing the 32-bit vanilla representation of the Motoko values, not the decoded values. Values previously stored with the broken 32-bit operations must be loaded with care. If bit 0 is clear, the original value can be obtained by an arithmetic shift right by 1 bit. If bit 0 is set, the value cannot be trusted and should be ignored (it encodes some transient address of a boxed value).
- Loading branch information
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
ingress Completed: Reply: 0x4449444c0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
region-nat32-bug.mo:5.5-5.6: warning [M0145], this pattern of type | ||
Nat64 | ||
does not cover value | ||
1 or 2 or _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Prim "mo:⛔"; | ||
import Region "stable-region/Region"; | ||
|
||
let r = Region.new(); | ||
let 0 = Region.grow(r, 1); | ||
|
||
do { | ||
var i : Nat32 = 0; | ||
while(i < 0xFFFF) { | ||
Region.storeNat32(r, 0, i); | ||
let i32 = Region.loadNat32(r, 0); | ||
let i64 = Region.loadNat64(r, 0); | ||
if (i32 != i or Prim.nat64ToNat32(i64) != i) { | ||
Prim.debugPrint(debug_show({i;i64;i32;bytes=Region.loadBlob(r,0,4)})); | ||
assert(false); | ||
}; | ||
i += 1; | ||
}; | ||
}; | ||
|
||
do { | ||
var i : Nat32 = 0xFFFF_FFFF; | ||
while(i > 0xFFFF_0000) { | ||
Region.storeNat32(r, 0, i); | ||
let i32 = Region.loadNat32(r, 0); | ||
let i64 = Region.loadNat64(r, 0); | ||
if (i32 != i or Prim.nat64ToNat32(i64) != i) { | ||
Prim.debugPrint(debug_show({i;i64;i32;bytes=Region.loadBlob(r,0,4)})); | ||
assert(false); | ||
}; | ||
i -= 1; | ||
}; | ||
} | ||
|
||
//SKIP run-low | ||
//SKIP run | ||
//SKIP run-ir |