Skip to content

Commit

Permalink
Expose Engine::clone to c-api (#8907)
Browse files Browse the repository at this point in the history
  • Loading branch information
CGamesPlay authored Jul 8, 2024
1 parent b8872ed commit 9e22c4e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/c-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For more information you can find the documentation for this library
To use Wasmtime from a C or C++ project, you can use Cargo to build the Wasmtime C bindings. From the root of the Wasmtime repository, run the following command:

```
cargo build --release wasmtime-c-api
cargo build --release -p wasmtime-c-api
```

This will create static and dynamic libraries called `libwasmtime` in the `target/release` directory.
Expand Down
8 changes: 8 additions & 0 deletions crates/c-api/include/wasmtime/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
extern "C" {
#endif

/**
* \brief Create a new reference to the same underlying engine.
*
* This function clones the reference-counted pointer to the internal object,
* and must be freed using #wasm_engine_delete.
*/
WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine);

/**
* \brief Increments the engine-local epoch variable.
*
Expand Down
8 changes: 8 additions & 0 deletions crates/c-api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {

#[no_mangle]
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
#[cfg(feature = "logging")]
drop(env_logger::try_init());

let config = c.config;
Box::new(wasm_engine_t {
engine: Engine::new(&config).unwrap(),
})
}

#[no_mangle]
pub extern "C" fn wasmtime_engine_clone(engine: &wasm_engine_t) -> Box<wasm_engine_t> {
Box::new(engine.clone())
}

#[no_mangle]
pub extern "C" fn wasmtime_engine_increment_epoch(engine: &wasm_engine_t) {
engine.engine.increment_epoch();
Expand Down

0 comments on commit 9e22c4e

Please sign in to comment.