Skip to content

Commit 4cb3e1e

Browse files
Defer wasmtime_component_linker_instance()
1 parent 6b34255 commit 4cb3e1e

File tree

3 files changed

+1
-74
lines changed

3 files changed

+1
-74
lines changed

crates/c-api/include/wasmtime/component/linker.h

-33
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ extern "C" {
1616

1717
typedef struct wasmtime_component_linker_t wasmtime_component_linker_t;
1818

19-
typedef struct wasmtime_component_linker_instance_t
20-
wasmtime_component_linker_instance_t;
21-
2219
/**
2320
* \brief Creates a new #wasmtime_component_linker_t for the specified engine.
2421
*
@@ -29,27 +26,6 @@ typedef struct wasmtime_component_linker_instance_t
2926
WASM_API_EXTERN wasmtime_component_linker_t *
3027
wasmtime_component_linker_new(const wasm_engine_t *engine);
3128

32-
/**
33-
* \brief Creates a builder, #wasmtime_component_linker_instance_t, for the
34-
* specified named instance
35-
*
36-
* \param linker the linker in which to build out the instance in
37-
* \param name the instance name
38-
* \param linker_instance_out on success, the
39-
* #wasmtime_component_linker_instance_t
40-
*
41-
* \return wasmtime_error_t* on success `NULL` is returned, otherwise an error
42-
* is returned which describes why the build failed.
43-
*
44-
* \note This mutably borrows the provided linker, meaning nothing else should
45-
* access the linker until the returned #wasmtime_component_linker_instance_t is
46-
* deleted. The linker also needs to stay alive as long as the returned
47-
* #wasmtime_component_linker_instance_t is alive.
48-
*/
49-
WASM_API_EXTERN wasmtime_error_t *wasmtime_component_linker_instance(
50-
wasmtime_component_linker_t *linker, const char *name,
51-
wasmtime_component_linker_instance_t **linker_instance_out);
52-
5329
/**
5430
* \brief Instantiates a component instance in a given #wasmtime_context_t
5531
*
@@ -78,15 +54,6 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_component_linker_instantiate(
7854
WASM_API_EXTERN void
7955
wasmtime_component_linker_delete(wasmtime_component_linker_t *linker);
8056

81-
/**
82-
* \brief Deletes a #wasmtime_component_linker_instance_t created by
83-
* #wasmtime_component_linker_instance
84-
*
85-
* \param linker_instance the #wasmtime_component_linker_instance_t to delete
86-
*/
87-
WASM_API_EXTERN void wasmtime_component_linker_instance_delete(
88-
wasmtime_component_linker_instance_t *linker_instance);
89-
9057
#ifdef __cplusplus
9158
} // extern "C"
9259
#endif

crates/c-api/src/component/linker.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::ffi::{c_char, CStr};
2-
3-
use anyhow::Context;
4-
use wasmtime::component::{Instance, Linker, LinkerInstance};
1+
use wasmtime::component::{Instance, Linker};
52

63
use crate::{wasm_engine_t, wasmtime_error_t, WasmtimeStoreContextMut, WasmtimeStoreData};
74

@@ -12,11 +9,6 @@ pub struct wasmtime_component_linker_t {
129
pub(crate) linker: Linker<WasmtimeStoreData>,
1310
}
1411

15-
#[repr(transparent)]
16-
pub struct wasmtime_component_linker_instance_t<'a> {
17-
pub(crate) linker_instance: LinkerInstance<'a, WasmtimeStoreData>,
18-
}
19-
2012
#[unsafe(no_mangle)]
2113
pub unsafe extern "C" fn wasmtime_component_linker_new(
2214
engine: &wasm_engine_t,
@@ -26,24 +18,6 @@ pub unsafe extern "C" fn wasmtime_component_linker_new(
2618
})
2719
}
2820

29-
#[unsafe(no_mangle)]
30-
pub unsafe extern "C" fn wasmtime_component_linker_instance<'a>(
31-
linker: &'a mut wasmtime_component_linker_t,
32-
name: *const c_char,
33-
linker_instance_out: &mut *mut wasmtime_component_linker_instance_t<'a>,
34-
) -> Option<Box<wasmtime_error_t>> {
35-
let name = unsafe { CStr::from_ptr(name) };
36-
let result = name
37-
.to_str()
38-
.context("input name is not valid utf-8")
39-
.and_then(|name| linker.linker.instance(name));
40-
crate::handle_result(result, |linker_instance| {
41-
*linker_instance_out = Box::into_raw(Box::new(wasmtime_component_linker_instance_t {
42-
linker_instance,
43-
}));
44-
})
45-
}
46-
4721
#[unsafe(no_mangle)]
4822
pub unsafe extern "C" fn wasmtime_component_linker_instantiate(
4923
linker: &wasmtime_component_linker_t,
@@ -60,9 +34,3 @@ pub unsafe extern "C" fn wasmtime_component_linker_delete(
6034
_linker: Box<wasmtime_component_linker_t>,
6135
) {
6236
}
63-
64-
#[unsafe(no_mangle)]
65-
pub unsafe extern "C" fn wasmtime_component_linker_instance_delete(
66-
_linker_instance: Box<wasmtime_component_linker_instance_t>,
67-
) {
68-
}

crates/c-api/tests/component/instantiate.cc

-8
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ TEST(component, instantiate) {
3030
const auto linker = wasmtime_component_linker_new(engine);
3131
EXPECT_NE(linker, nullptr);
3232

33-
wasmtime_component_linker_instance_t *linker_instance = nullptr;
34-
error = wasmtime_component_linker_instance(linker, "a:b/c", &linker_instance);
35-
36-
EXPECT_EQ(error, nullptr);
37-
EXPECT_NE(linker_instance, nullptr);
38-
39-
wasmtime_component_linker_instance_delete(linker_instance);
40-
4133
wasmtime_component_instance_t instance = {};
4234
error = wasmtime_component_linker_instantiate(linker, context, component,
4335
&instance);

0 commit comments

Comments
 (0)