Skip to content

Commit f1005cf

Browse files
committed
fix examples
Signed-off-by: Jorge Prendes <[email protected]>
1 parent 0314d49 commit f1005cf

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

src/hyperlight_host/examples/func_ctx/main.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
use hyperlight_host::func::call_ctx::MultiUseGuestCallContext;
18-
use hyperlight_host::sandbox::{Callable, MultiUseSandbox, UninitializedSandbox};
17+
use hyperlight_host::sandbox::{MultiUseSandbox, UninitializedSandbox};
1918
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2019
use hyperlight_host::sandbox_state::transition::Noop;
2120
use hyperlight_host::{GuestBinary, Result};
@@ -24,32 +23,32 @@ use hyperlight_testing::simple_guest_as_string;
2423
fn main() {
2524
// create a new `MultiUseSandbox` configured to run the `simpleguest.exe`
2625
// test guest binary
27-
let sbox1: MultiUseSandbox = {
26+
let mut sbox1: MultiUseSandbox = {
2827
let path = simple_guest_as_string().unwrap();
2928
let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap();
3029
u_sbox.evolve(Noop::default())
3130
}
3231
.unwrap();
3332

3433
// create a new call context from the sandbox, then do some calls with it.
35-
let ctx1 = sbox1.new_call_context();
36-
let sbox2 = do_calls(ctx1).unwrap();
34+
do_calls(&mut sbox1).unwrap();
35+
3736
// create a new call context from the returned sandbox, then do some calls
3837
// with that one
39-
let ctx2 = sbox2.new_call_context();
40-
do_calls(ctx2).unwrap();
38+
do_calls(&mut sbox1).unwrap();
4139
}
4240

4341
/// Given a `MultiUseGuestCallContext` derived from an existing
4442
/// `MultiUseSandbox` configured to run the `simpleguest.exe` test guest
4543
/// binary, do several calls against that binary, print their results, then
4644
/// call `ctx.finish()` and return the resulting `MultiUseSandbox`. Return an `Err`
4745
/// if anything failed.
48-
fn do_calls(mut ctx: MultiUseGuestCallContext) -> Result<MultiUseSandbox> {
49-
let res: String = ctx.call("Echo", "hello".to_string())?;
46+
fn do_calls(sbox: &mut MultiUseSandbox) -> Result<()> {
47+
let res: String = sbox.call_guest_function_by_name("Echo", "hello".to_string())?;
5048
println!("got Echo res: {res}");
5149

52-
let res: i32 = ctx.call("CallMalloc", 200_i32)?;
50+
let res: i32 = sbox.call_guest_function_by_name("CallMalloc", 200_i32)?;
5351
println!("got CallMalloc res: {res}");
54-
ctx.finish()
52+
53+
Ok(())
5554
}

src/hyperlight_host/examples/logging/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate hyperlight_host;
1818

1919
use std::sync::{Arc, Barrier};
2020

21-
use hyperlight_host::sandbox::Callable;
2221
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
2322
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2423
use hyperlight_host::sandbox_state::transition::Noop;
@@ -102,10 +101,10 @@ fn main() -> Result<()> {
102101
// Call a function that gets cancelled by the host function 5 times to generate some log entries.
103102

104103
for _ in 0..NUM_CALLS {
105-
let mut ctx = multiuse_sandbox.new_call_context();
106104
barrier.wait();
107-
ctx.call::<()>("Spin", ()).unwrap_err();
108-
multiuse_sandbox = ctx.finish().unwrap();
105+
multiuse_sandbox
106+
.call_guest_function_by_name::<()>("Spin", ())
107+
.unwrap_err();
109108
}
110109
thread.join().unwrap();
111110

src/hyperlight_host/examples/metrics/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate hyperlight_host;
1818
use std::sync::{Arc, Barrier};
1919
use std::thread::{JoinHandle, spawn};
2020

21-
use hyperlight_host::sandbox::Callable;
2221
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
2322
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2423
use hyperlight_host::sandbox_state::transition::Noop;
@@ -116,10 +115,10 @@ fn do_hyperlight_stuff() {
116115
// Call a function that gets cancelled by the host function 5 times to generate some metrics.
117116

118117
for _ in 0..NUM_CALLS {
119-
let mut ctx = multiuse_sandbox.new_call_context();
120118
barrier.wait();
121-
ctx.call::<()>("Spin", ()).unwrap_err();
122-
multiuse_sandbox = ctx.finish().unwrap();
119+
multiuse_sandbox
120+
.call_guest_function_by_name::<()>("Spin", ())
121+
.unwrap_err();
123122
}
124123

125124
for join_handle in join_handles {

src/hyperlight_host/examples/tracing-otlp/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::io::stdin;
2626
use std::sync::{Arc, Barrier, Mutex};
2727
use std::thread::{JoinHandle, spawn};
2828

29-
use hyperlight_host::sandbox::Callable;
3029
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
3130
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
3231
use hyperlight_host::sandbox_state::transition::Noop;
@@ -184,10 +183,10 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
184183
uuid = %id,
185184
);
186185
let _entered = span.enter();
187-
let mut ctx = multiuse_sandbox.new_call_context();
188186
barrier.wait();
189-
ctx.call::<()>("Spin", ()).unwrap_err();
190-
multiuse_sandbox = ctx.finish().unwrap();
187+
multiuse_sandbox
188+
.call_guest_function_by_name::<()>("Spin", ())
189+
.unwrap_err();
191190
}
192191
thread.join().expect("Thread panicked");
193192
}

src/hyperlight_host/examples/tracing/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern crate hyperlight_host;
1919
use std::sync::{Arc, Barrier};
2020
use std::thread::{JoinHandle, spawn};
2121

22-
use hyperlight_host::sandbox::Callable;
2322
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
2423
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2524
use hyperlight_host::sandbox_state::transition::Noop;
@@ -139,10 +138,10 @@ fn run_example() -> Result<()> {
139138
uuid = %id,
140139
);
141140
let _entered = span.enter();
142-
let mut ctx = multiuse_sandbox.new_call_context();
143141
barrier.wait();
144-
ctx.call::<()>("Spin", ()).unwrap_err();
145-
multiuse_sandbox = ctx.finish().unwrap();
142+
multiuse_sandbox
143+
.call_guest_function_by_name::<()>("Spin", ())
144+
.unwrap_err();
146145
}
147146

148147
for join_handle in join_handles {

0 commit comments

Comments
 (0)