Skip to content

Commit 5bab35d

Browse files
committed
add unsafe block
1 parent ab4f473 commit 5bab35d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/bin/toy.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn run_hello(jit: &mut jit::JIT) -> Result<isize, String> {
4242
///
4343
/// This function is unsafe since it relies on the caller to provide it with the correct
4444
/// input and output types. Using incorrect types at this point may corrupt the program's state.
45-
unsafe fn run_code<I, O>(jit: &mut jit::JIT, code: &str, input: I) -> Result<O, String> {
45+
unsafe fn run_code<I, O>(jit: &mut jit::JIT, code: &str, input: I) -> Result<O, String> { unsafe {
4646
// Pass the string to the JIT, and it returns a raw pointer to machine code.
4747
let code_ptr = jit.compile(code)?;
4848
// Cast the raw pointer to a typed function pointer. This is unsafe, because
@@ -51,7 +51,7 @@ unsafe fn run_code<I, O>(jit: &mut jit::JIT, code: &str, input: I) -> Result<O,
5151
let code_fn = mem::transmute::<_, fn(I) -> O>(code_ptr);
5252
// And now we can call it!
5353
Ok(code_fn(input))
54-
}
54+
}}
5555

5656
// A small test function.
5757
//

0 commit comments

Comments
 (0)