From 4103139d9d0a310d5f496bc449d6a034334d8aed Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sat, 21 Dec 2024 09:07:36 -0800 Subject: [PATCH] vtab::Free is no longer needed BindInfo and InitInfo will be dropped in the usual way when freed by duckdb core. Any necessary destructors can be in Drop impls. --- crates/duckdb/examples/hello-ext/main.rs | 6 +----- crates/duckdb/src/vtab/mod.rs | 16 ++-------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/crates/duckdb/examples/hello-ext/main.rs b/crates/duckdb/examples/hello-ext/main.rs index 3f19e69e..f8ba43d9 100644 --- a/crates/duckdb/examples/hello-ext/main.rs +++ b/crates/duckdb/examples/hello-ext/main.rs @@ -6,7 +6,7 @@ extern crate libduckdb_sys; use duckdb::{ core::{DataChunkHandle, Inserter, LogicalTypeHandle, LogicalTypeId}, - vtab::{BindInfo, Free, FunctionInfo, InitInfo, VTab}, + vtab::{BindInfo, FunctionInfo, InitInfo, VTab}, Connection, Result, }; use duckdb_loadable_macros::duckdb_entrypoint; @@ -20,16 +20,12 @@ struct HelloBindData { name: String, } -impl Free for HelloBindData {} - struct HelloInitData { done: bool, } struct HelloVTab; -impl Free for HelloInitData {} - impl VTab for HelloVTab { type InitData = HelloInitData; type BindData = HelloBindData; diff --git a/crates/duckdb/src/vtab/mod.rs b/crates/duckdb/src/vtab/mod.rs index 06bf541f..b6fc940f 100644 --- a/crates/duckdb/src/vtab/mod.rs +++ b/crates/duckdb/src/vtab/mod.rs @@ -34,23 +34,15 @@ unsafe extern "C" fn drop_boxed(v: *mut c_void) { drop(unsafe { Box::from_raw(v.cast::()) }); } -/// Free trait for the bind and init data -pub trait Free { - /// Free the data - fn free(&mut self) {} -} - /// Duckdb table function trait /// /// See to the HelloVTab example for more details /// pub trait VTab: Sized { /// The data type of the bind data - type InitData: Sized + Free; + type InitData: Sized; /// The data type of the init data - type BindData: Sized + Free; // TODO: and maybe Send + Sync as this might be called from multiple threads? - - // TODO: Get rid of Free, just use Drop? + type BindData: Sized; // TODO: and maybe Send + Sync as this might be called from multiple threads? /// Bind data to the table function fn bind(bind: &BindInfo) -> Result>; @@ -186,16 +178,12 @@ mod test { name: String, } - impl Free for HelloBindData {} - struct HelloInitData { done: bool, } struct HelloVTab; - impl Free for HelloInitData {} - impl VTab for HelloVTab { type InitData = HelloInitData; type BindData = HelloBindData;