Update extension ownership cleanups for new vtab module

This commit is contained in:
PThorpe92 2025-02-27 13:40:20 -05:00
parent 04abb200a7
commit 5b8efd92a4
No known key found for this signature in database
GPG key ID: 66DB3FBACBDD05CC
3 changed files with 12 additions and 17 deletions

View file

@ -28,7 +28,7 @@ use fallible_iterator::FallibleIterator;
use libloading::{Library, Symbol};
#[cfg(not(target_family = "wasm"))]
use limbo_ext::{ExtensionApi, ExtensionEntryPoint};
use limbo_ext::{ResultCode, VTabKind, VTabModuleImpl, Value as ExtValue};
use limbo_ext::{ResultCode, VTabKind, VTabModuleImpl};
use limbo_sqlite3_parser::{ast, ast::Cmd, lexer::sql::Parser};
use parking_lot::RwLock;
use schema::{Column, Schema};
@ -497,7 +497,7 @@ impl Statement {
}
pub fn bind_at(&mut self, index: NonZero<usize>, value: OwnedValue) {
self.state.bind_at(index, value.into());
self.state.bind_at(index, value);
}
pub fn reset(&mut self) {
@ -582,22 +582,16 @@ impl VirtualTable {
let mut filter_args = Vec::with_capacity(arg_count);
for i in 0..arg_count {
let ownedvalue_arg = args.get(i).unwrap();
let extvalue_arg: ExtValue = match ownedvalue_arg {
OwnedValue::Null => Ok(ExtValue::null()),
OwnedValue::Integer(i) => Ok(ExtValue::from_integer(*i)),
OwnedValue::Float(f) => Ok(ExtValue::from_float(*f)),
OwnedValue::Text(t) => Ok(ExtValue::from_text(t.as_str().to_string())),
OwnedValue::Blob(b) => Ok(ExtValue::from_blob((**b).clone())),
other => Err(LimboError::ExtensionError(format!(
"Unsupported value type: {:?}",
other
))),
}?;
filter_args.push(extvalue_arg);
filter_args.push(ownedvalue_arg.to_ffi());
}
let rc = unsafe {
(self.implementation.filter)(cursor.as_ptr(), arg_count as i32, filter_args.as_ptr())
};
for arg in filter_args {
unsafe {
arg.__free_internal_type();
}
}
match rc {
ResultCode::OK => Ok(true),
ResultCode::EOF => Ok(false),
@ -634,7 +628,7 @@ impl VirtualTable {
};
for arg in ext_args {
unsafe {
arg.free();
arg.__free_internal_type();
}
}
match rc {

View file

@ -1863,7 +1863,7 @@ impl Program {
let argv_ptr = ext_values.as_ptr();
unsafe { step_fn(state_ptr, argc as i32, argv_ptr) };
for ext_value in ext_values {
unsafe { ext_value.free() };
unsafe { ext_value.__free_internal_type() };
}
}
}

View file

@ -73,6 +73,7 @@ pub struct VTabModuleImpl {
pub rowid: VtabRowIDFn,
}
#[cfg(feature = "core_only")]
impl VTabModuleImpl {
pub fn init_schema(&self, args: Vec<Value>) -> ExtResult<String> {
let schema = unsafe { (self.create_schema)(args.as_ptr(), args.len() as i32) };
@ -80,7 +81,7 @@ impl VTabModuleImpl {
return Err(ResultCode::InvalidArgs);
}
for arg in args {
unsafe { arg.free() };
unsafe { arg.__free_internal_type() };
}
let schema = unsafe { std::ffi::CString::from_raw(schema) };
Ok(schema.to_string_lossy().to_string())