Skip to content

Commit ea895ee

Browse files
test: fix rust warm example build
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent f07578b commit ea895ee

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

crates/parser/src/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ impl ModuleReader {
158158
validator.end(offset)?;
159159
self.end_reached = true;
160160
}
161-
Payload::CustomSection(reader) => {
161+
Payload::CustomSection(_reader) => {
162162
debug!("Found custom section");
163-
debug!("Skipping custom section: {:?}", reader.name());
163+
debug!("Skipping custom section: {:?}", _reader.name());
164164
}
165165
Payload::UnknownSection { .. } => return Err(ParseError::UnsupportedSection("Unknown section".into())),
166166
section => return Err(ParseError::UnsupportedSection(format!("Unsupported section: {section:?}"))),

examples/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ edition="2021"
1212
[dependencies]
1313
tinywasm={path="../../crates/tinywasm", default-features=false, features=["parser", "archive"]}
1414
argon2={version="0.5"}
15-
lol_alloc="0.4.1"
15+
dlmalloc={version="0.2", features=["global"]}
1616

1717
[features]
1818
default=["std"]

examples/rust/src/tinywasm.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@ pub extern "C" fn hello() {
1414
fn run() -> tinywasm::Result<()> {
1515
let module = tinywasm::Module::parse_stream(&include_bytes!("./print.wasm")[..])?;
1616
let mut store = tinywasm::Store::default();
17+
18+
let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
19+
unsafe { printi32(v) }
20+
Ok(())
21+
});
22+
1723
let mut imports = tinywasm::Imports::new();
24+
imports.define("env", "printi32", printi32);
1825

19-
imports.define(
20-
"env",
21-
"printi32",
22-
HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
23-
unsafe { printi32(v) }
24-
Ok(())
25-
}),
26-
)?;
2726
let instance = module.instantiate(&mut store, Some(imports))?;
28-
29-
let add_and_print = instance.func_typed::<(i32, i32), ()>(&store, "add_and_print")?;
27+
let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?;
3028
add_and_print.call(&mut store, (1, 2))?;
3129
Ok(())
3230
}
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#![no_main]
22
#![no_std]
3-
use lol_alloc::{AssumeSingleThreaded, FreeListAllocator};
3+
use dlmalloc::GlobalDlmalloc;
44
use tinywasm::{FuncContext, HostFunction};
55

66
extern crate alloc;
77

8+
#[global_allocator]
9+
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;
10+
811
#[cfg(not(feature = "std"))]
912
#[panic_handler]
1013
fn panic(_info: &core::panic::PanicInfo) -> ! {
1114
loop {}
1215
}
1316

14-
#[global_allocator]
15-
static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> =
16-
unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) };
17-
1817
#[link(wasm_import_module = "env")]
1918
unsafe extern "C" {
2019
fn printi32(x: i32);
@@ -33,17 +32,14 @@ fn run() -> tinywasm::Result<()> {
3332
let twasm = res.serialize_twasm()?;
3433
let module = tinywasm::Module::parse_bytes(&twasm)?;
3534

36-
imports.define(
37-
"env",
38-
"printi32",
39-
HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
40-
unsafe { printi32(v) }
41-
Ok(())
42-
}),
43-
)?;
44-
let instance = module.instantiate(&mut store, Some(imports))?;
35+
let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
36+
unsafe { printi32(v) }
37+
Ok(())
38+
});
4539

46-
let add_and_print = instance.func_typed::<(i32, i32), ()>(&store, "add_and_print")?;
40+
imports.define("env", "printi32", printi32);
41+
let instance = module.instantiate(&mut store, Some(imports))?;
42+
let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?;
4743
add_and_print.call(&mut store, (1, 2))?;
4844
Ok(())
4945
}

0 commit comments

Comments
 (0)