mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 13:58:55 +08:00 
			
		
		
		
	Make VTab / VTabCursor unsafe trait as implmenting them on the wrong type is unsound
				
					
				
			This commit is contained in:
		
				
					committed by
					
						 Thom Chiovoloni
						Thom Chiovoloni
					
				
			
			
				
	
			
			
			
						parent
						
							3c6b57fe1b
						
					
				
				
					commit
					c9ef5bd63c
				
			| @@ -71,7 +71,7 @@ struct ArrayTab { | ||||
|     base: ffi::sqlite3_vtab, | ||||
| } | ||||
|  | ||||
| impl VTab for ArrayTab { | ||||
| unsafe impl VTab for ArrayTab { | ||||
|     type Aux = (); | ||||
|     type Cursor = ArrayTabCursor; | ||||
|  | ||||
| @@ -149,7 +149,7 @@ impl ArrayTabCursor { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| impl VTabCursor for ArrayTabCursor { | ||||
| unsafe impl VTabCursor for ArrayTabCursor { | ||||
|     fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { | ||||
|         if idx_num > 0 { | ||||
|             self.ptr = args.get_array(0)?; | ||||
|   | ||||
| @@ -95,7 +95,7 @@ impl CSVTab { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl VTab for CSVTab { | ||||
| unsafe impl VTab for CSVTab { | ||||
|     type Aux = (); | ||||
|     type Cursor = CSVTabCursor; | ||||
|  | ||||
| @@ -296,7 +296,7 @@ impl CSVTabCursor { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl VTabCursor for CSVTabCursor { | ||||
| unsafe impl VTabCursor for CSVTabCursor { | ||||
|     // Only a full table scan is supported.  So `filter` simply rewinds to | ||||
|     // the beginning. | ||||
|     fn filter( | ||||
|   | ||||
| @@ -189,7 +189,11 @@ impl VTabConnection { | ||||
|  | ||||
| /// `feature = "vtab"` Virtual table instance trait. | ||||
| /// | ||||
| /// Implementations must be like: | ||||
| /// # Safety | ||||
| /// | ||||
| /// The first item in a struct implementing VTab must be | ||||
| /// `rusqlite::sqlite3_vtab`, and the struct must be `#[repr(C)]`. | ||||
| /// | ||||
| /// ```rust,ignore | ||||
| /// #[repr(C)] | ||||
| /// struct MyTab { | ||||
| @@ -200,7 +204,7 @@ impl VTabConnection { | ||||
| /// ``` | ||||
| /// | ||||
| /// (See [SQLite doc](https://sqlite.org/c3ref/vtab.html)) | ||||
| pub trait VTab: Sized { | ||||
| pub unsafe trait VTab: Sized { | ||||
|     type Aux; | ||||
|     type Cursor: VTabCursor; | ||||
|  | ||||
| @@ -465,7 +469,7 @@ impl OrderBy<'_> { | ||||
| /// ``` | ||||
| /// | ||||
| /// (See [SQLite doc](https://sqlite.org/c3ref/vtab_cursor.html)) | ||||
| pub trait VTabCursor: Sized { | ||||
| pub unsafe trait VTabCursor: Sized { | ||||
|     /// Begin a search of a virtual table. | ||||
|     /// (See [SQLite doc](https://sqlite.org/vtab.html#the_xfilter_method)) | ||||
|     fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values<'_>) -> Result<()>; | ||||
|   | ||||
| @@ -49,7 +49,7 @@ struct SeriesTab { | ||||
|     base: ffi::sqlite3_vtab, | ||||
| } | ||||
|  | ||||
| impl VTab for SeriesTab { | ||||
| unsafe impl VTab for SeriesTab { | ||||
|     type Aux = (); | ||||
|     type Cursor = SeriesTabCursor; | ||||
|  | ||||
| @@ -181,7 +181,7 @@ impl SeriesTabCursor { | ||||
|         SeriesTabCursor::default() | ||||
|     } | ||||
| } | ||||
| impl VTabCursor for SeriesTabCursor { | ||||
| unsafe impl VTabCursor for SeriesTabCursor { | ||||
|     fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { | ||||
|         let idx_num = QueryPlanFlags::from_bits_truncate(idx_num); | ||||
|         let mut i = 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user