Skip to content

Commit

Permalink
vtab::Free is no longer needed
Browse files Browse the repository at this point in the history
BindInfo and InitInfo will be dropped in the usual way when freed by duckdb core. Any necessary destructors can be in Drop impls.
  • Loading branch information
sourcefrog committed Dec 21, 2024
1 parent 5947f6d commit 4103139
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
6 changes: 1 addition & 5 deletions crates/duckdb/examples/hello-ext/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 2 additions & 14 deletions crates/duckdb/src/vtab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@ unsafe extern "C" fn drop_boxed<T>(v: *mut c_void) {
drop(unsafe { Box::from_raw(v.cast::<T>()) });
}

/// 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
/// <https://duckdb.org/docs/api/c/table_functions>
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<Self::BindData, Box<dyn std::error::Error>>;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4103139

Please sign in to comment.