Skip to content

Commit

Permalink
feat: finalize fn
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem committed May 3, 2024
1 parent db46b2d commit e647279
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions hermes/bin/src/runtime_extensions/hermes/sqlite/statement/host.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! `SQLite` statement host implementation for WASM runtime.

use libsqlite3_sys::*;

use crate::{
runtime_context::HermesRuntimeContext,
runtime_extensions::bindings::hermes::sqlite::api::{Errno, HostStatement, Statement, Value},
Expand Down Expand Up @@ -58,9 +60,17 @@ impl HostStatement for HermesRuntimeContext {
/// it has been finalized can result in undefined and undesirable behavior such as
/// segfaults and heap corruption.
fn finalize(
&mut self, _resource: wasmtime::component::Resource<Statement>,
&mut self, resource: wasmtime::component::Resource<Statement>,
) -> wasmtime::Result<Result<(), Errno>> {
todo!()
let stmt_ptr: *mut sqlite3_stmt = resource.rep() as *mut _;

let result = unsafe { sqlite3_finalize(stmt_ptr) };

if result != SQLITE_OK {
Ok(Err(result.into()))
} else {
Ok(Ok(()))
}
}

fn drop(&mut self, _rep: wasmtime::component::Resource<Statement>) -> wasmtime::Result<()> {
Expand Down

0 comments on commit e647279

Please sign in to comment.