From 6300deb77f888665bc5504a308be2adbb42064d5 Mon Sep 17 00:00:00 2001 From: Piotr Rzysko Date: Wed, 28 May 2025 08:55:41 +0200 Subject: [PATCH] Move VTabOpaqueCursor to vtab module --- core/types.rs | 3 ++- core/vdbe/mod.rs | 32 -------------------------------- core/vtab.rs | 32 +++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/core/types.rs b/core/types.rs index 52f87cd1a..bdc8d6f88 100644 --- a/core/types.rs +++ b/core/types.rs @@ -10,7 +10,8 @@ use crate::storage::sqlite3_ondisk::write_varint; use crate::translate::collate::CollationSeq; use crate::translate::plan::IterationDirection; use crate::vdbe::sorter::Sorter; -use crate::vdbe::{Register, VTabOpaqueCursor}; +use crate::vdbe::Register; +use crate::vtab::VTabOpaqueCursor; use crate::Result; use std::fmt::Display; diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 435bbd80c..e8d768209 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -53,7 +53,6 @@ use regex::Regex; use std::{ cell::{Cell, RefCell}, collections::HashMap, - ffi::c_void, num::NonZero, ops::Deref, rc::{Rc, Weak}, @@ -203,37 +202,6 @@ impl Bitfield { } } -type VTabOpaqueCursorCloseFn = unsafe extern "C" fn(*const c_void) -> limbo_ext::ResultCode; - -pub struct VTabOpaqueCursor { - cursor: *const c_void, - close: VTabOpaqueCursorCloseFn, -} - -impl VTabOpaqueCursor { - pub fn new(cursor: *const c_void, close: VTabOpaqueCursorCloseFn) -> Result { - if cursor.is_null() { - return Err(LimboError::InternalError( - "VTabOpaqueCursor: cursor is null".into(), - )); - } - Ok(Self { cursor, close }) - } - - pub fn as_ptr(&self) -> *const c_void { - self.cursor - } -} - -impl Drop for VTabOpaqueCursor { - fn drop(&mut self) { - let result = unsafe { (self.close)(self.cursor) }; - if !result.is_ok() { - tracing::error!("Failed to close virtual table cursor"); - } - } -} - #[derive(Copy, Clone, PartialEq, Eq)] /// The commit state of the program. /// There are two states: diff --git a/core/vtab.rs b/core/vtab.rs index 0fcb40335..62a001a37 100644 --- a/core/vtab.rs +++ b/core/vtab.rs @@ -1,6 +1,5 @@ use crate::schema::Column; use crate::util::columns_from_create_table_body; -use crate::vdbe::VTabOpaqueCursor; use crate::{Connection, LimboError, SymbolTable, Value}; use fallible_iterator::FallibleIterator; use limbo_ext::{ConstraintInfo, IndexInfo, OrderByInfo, ResultCode, VTabKind, VTabModuleImpl}; @@ -200,3 +199,34 @@ impl VirtualTable { } } } + +type VTabOpaqueCursorCloseFn = unsafe extern "C" fn(*const c_void) -> limbo_ext::ResultCode; + +pub struct VTabOpaqueCursor { + cursor: *const c_void, + close: VTabOpaqueCursorCloseFn, +} + +impl VTabOpaqueCursor { + pub fn new(cursor: *const c_void, close: VTabOpaqueCursorCloseFn) -> crate::Result { + if cursor.is_null() { + return Err(LimboError::InternalError( + "VTabOpaqueCursor: cursor is null".into(), + )); + } + Ok(Self { cursor, close }) + } + + pub fn as_ptr(&self) -> *const c_void { + self.cursor + } +} + +impl Drop for VTabOpaqueCursor { + fn drop(&mut self) { + let result = unsafe { (self.close)(self.cursor) }; + if !result.is_ok() { + tracing::error!("Failed to close virtual table cursor"); + } + } +}