Allow BPF structure passing and returning (#2100)

* Add BPF struct passing and returning tests
This commit is contained in:
jackcmay
2018-12-11 09:03:37 -08:00
committed by GitHub
parent 166945a461
commit e3dfd7b1ab
5 changed files with 68 additions and 21 deletions

View File

@ -0,0 +1,17 @@
#include <solana_sdk.h>
struct foo {const uint8_t *input;};
void foo(const uint8_t *input, struct foo foo) ;
extern bool entrypoint(const uint8_t *input) {
struct foo f;
f.input = input;
foo(input, f);
return true;
}
void foo(const uint8_t *input, struct foo foo) {
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
sol_assert(input == foo.input);
}

View File

@ -0,0 +1,18 @@
#include <solana_sdk.h>
struct foo {const uint8_t *input;};
struct foo bar(const uint8_t *input);
extern bool entrypoint(const uint8_t *input) {
struct foo foo = bar(input);
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
sol_assert(input == foo.input);
return true;
}
struct foo bar(const uint8_t *input) {
struct foo foo;
foo.input = input;
return foo;
}

View File

@ -18,6 +18,9 @@ fn main() {
println!("cargo:rerun-if-changed=../../bpf/c/src/bench_alu.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/move_funds.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/noop.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/noop++.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/struct_pass.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/struct_ret.c");
println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
let status = Command::new("make")
.current_dir("../../bpf/c")