forked from anza-xyz/move
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix another move-native fmt::Debug crash (vector-of-structs). (anza-x…
…yz#194) This patch fixes another occurrence of the move-native runtime defect where a debug formatter-- this time in the vector-of-structs case-- dereferenced and called a rogue pointer. This results in a callx out of the address space. anza-xyz#191. Also enhanced the fmt::Debug routines for structs to output the struct name and otherwise make the output more like what a default rust debug formatter for structs would do. Other minor NFC clean-ups. Added a runnable rbpf test cases demonstrating vector-of-struct operations and debug-printing. Updated the log messages of the other rtty tests since the output now includes names.
- Loading branch information
Showing
6 changed files
with
90 additions
and
33 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
2 changes: 1 addition & 1 deletion
2
language/tools/move-mv-llvm-compiler/tests/rbpf-tests/rtty-struct01.move
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
2 changes: 1 addition & 1 deletion
2
language/tools/move-mv-llvm-compiler/tests/rbpf-tests/rtty-struct02.move
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// log [456, [true, 0, ], 0, ] | ||
// log ST::A1 {456, ST::A0 {true, 0, }, 0, } | ||
// log 456 | ||
// log true | ||
|
||
|
60 changes: 60 additions & 0 deletions
60
language/tools/move-mv-llvm-compiler/tests/rbpf-tests/rtty-struct03.move
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,60 @@ | ||
// log ST::A1 {254, 36893488147419103232, 0, } | ||
// log [ST::A1 {254, 36893488147419103232, 0, }, ST::A1 {123, 456, 0, }, ] | ||
// log 123 | ||
// log 456 | ||
|
||
|
||
module 0x10::debug { | ||
native public fun print<T>(x: &T); | ||
} | ||
|
||
module 0x10::vector { | ||
native public fun empty<Element>(): vector<Element>; | ||
native public fun length<Element>(v: &vector<Element>): u64; | ||
native public fun push_back<Element>(v: &mut vector<Element>, e: Element); | ||
native public fun pop_back<Element>(v: &mut vector<Element>): Element; | ||
native public fun destroy_empty<Element>(v: vector<Element>); | ||
native public fun swap<Element>(v: &mut vector<Element>, i: u64, j: u64); | ||
native public fun borrow<Element>(v: &vector<Element>, i: u64): ∈ | ||
native public fun borrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element; | ||
} | ||
|
||
module 0x200::ST { | ||
struct A1 has drop, copy { | ||
f1: u8, | ||
f2: u128 | ||
} | ||
|
||
public fun new(a1: u8, a2: u128): A1 { | ||
A1 { f1: a1, f2: a2 } | ||
} | ||
|
||
public fun get(s: &A1): (u8, u128) { | ||
let A1 { f1: x, f2: y } = *s; | ||
(x, y) | ||
} | ||
} | ||
|
||
script { | ||
use 0x10::debug; | ||
use 0x10::vector; | ||
use 0x200::ST; | ||
|
||
fun main() { | ||
let s1 = ST::new(254, 36893488147419103232_u128); | ||
let s2 = ST::new(123, 456); | ||
debug::print(&s1); | ||
|
||
// Now we're really going gonzo and operating on and debug-printing | ||
// a vector-of-structs. | ||
let v: vector<ST::A1> = vector::empty(); | ||
vector::push_back(&mut v, s1); | ||
vector::push_back(&mut v, s2); | ||
debug::print(&v); | ||
|
||
let sref = vector::borrow<ST::A1>(&v, 1); | ||
let (f1, f2) = ST::get(sref); | ||
debug::print(&f1); | ||
debug::print(&f2); | ||
} | ||
} |