|
3 | 3 |
|
4 | 4 | #![expect(clippy::missing_safety_doc)] |
5 | 5 |
|
6 | | -use std::ffi::CStr; |
7 | 6 | use std::ffi::c_char; |
| 7 | +use std::ffi::c_void; |
8 | 8 | use std::sync::LazyLock; |
9 | 9 | use std::sync::OnceLock; |
10 | 10 |
|
@@ -79,40 +79,23 @@ pub fn initialize(db: &DatabaseRef) -> VortexResult<()> { |
79 | 79 | db.register_copy_function() |
80 | 80 | } |
81 | 81 |
|
82 | | -/// Global symbol visibility in the Vortex extension: |
83 | | -/// - Rust functions use C ABI with "_rust" suffix (e.g., vortex_init_rust) |
84 | | -/// - C++ wrapper functions have the expected name without suffix (e.g., vortex_init) |
85 | | -/// - C++ wrappers are annotated with DUCKDB_EXTENSION_API to ensure global visibility |
86 | | -/// - C++ wrappers call the corresponding Rust functions |
87 | | -/// |
88 | | -/// This ensures DuckDB can find the symbols when loading the extension. |
89 | | -/// |
90 | | -/// The DuckDB extension ABI initialization function. |
91 | | -#[unsafe(no_mangle)] |
92 | | -pub unsafe extern "C" fn vortex_init_rust(db: cpp::duckdb_database) { |
| 82 | +/// Initialize the DuckDB extension from a raw DuckDB database pointer. |
| 83 | +pub unsafe fn initialize_extension_from_raw(db: *mut c_void) { |
93 | 84 | init_tracing(); |
94 | | - let database = unsafe { Database::borrow(db) }; |
| 85 | + let database = unsafe { Database::borrow(db.cast()) }; |
95 | 86 |
|
96 | 87 | database |
97 | 88 | .register_vortex_scan_replacement() |
98 | 89 | .vortex_expect("failed to register vortex scan replacement"); |
99 | 90 | initialize(database).vortex_expect("Failed to initialize Vortex extension"); |
100 | 91 | } |
101 | 92 |
|
102 | | -/// The DuckDB extension ABI version function. |
103 | | -/// This function returns the version of the DuckDB library the extension is built against. |
104 | | -#[unsafe(no_mangle)] |
105 | | -pub extern "C" fn vortex_version_rust() -> *const c_char { |
| 93 | +/// Returns the version of the DuckDB library the extension is built against. |
| 94 | +pub fn duckdb_library_version() -> *const c_char { |
106 | 95 | unsafe { cpp::duckdb_library_version() } |
107 | 96 | } |
108 | 97 |
|
109 | | -/// An additional function we export to expose the version of the extension itself to C++ code. |
110 | | -#[unsafe(no_mangle)] |
111 | | -pub extern "C" fn vortex_extension_version_rust() -> *const c_char { |
112 | | - // We do some fiddly macros here to get ourselves a _static_ C-style string. |
113 | | - // Otherwise, we'd be leaking memory. |
114 | | - unsafe { |
115 | | - CStr::from_bytes_with_nul_unchecked(concat!(env!("CARGO_PKG_VERSION"), "\0").as_bytes()) |
116 | | - } |
117 | | - .as_ptr() |
| 98 | +/// Returns the version of the Vortex DuckDB extension. |
| 99 | +pub fn extension_version() -> *const c_char { |
| 100 | + concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr().cast() |
118 | 101 | } |
0 commit comments