Fix Clippy warnings

This commit is contained in:
gwenn 2018-05-06 08:45:56 +02:00
parent 1e3dc542a4
commit 5fa3810a4b
5 changed files with 27 additions and 29 deletions

View File

@ -63,22 +63,22 @@ use types::{ToSql, ToSqlOutput, FromSql, FromSqlError, ValueRef};
use {Result, Error, Connection, str_to_cstring, InnerConnection};
pub fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
pub unsafe fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
let value = match *result {
ToSqlOutput::Borrowed(v) => v,
ToSqlOutput::Owned(ref v) => ValueRef::from(v),
#[cfg(feature = "blob")]
ToSqlOutput::ZeroBlob(len) => {
return unsafe { ffi::sqlite3_result_zeroblob(ctx, len) };
return ffi::sqlite3_result_zeroblob(ctx, len);
}
};
match value {
ValueRef::Null => unsafe { ffi::sqlite3_result_null(ctx) },
ValueRef::Integer(i) => unsafe { ffi::sqlite3_result_int64(ctx, i) },
ValueRef::Real(r) => unsafe { ffi::sqlite3_result_double(ctx, r) },
ValueRef::Text(s) => unsafe {
ValueRef::Null => ffi::sqlite3_result_null(ctx),
ValueRef::Integer(i) => ffi::sqlite3_result_int64(ctx, i),
ValueRef::Real(r) => ffi::sqlite3_result_double(ctx, r),
ValueRef::Text(s) => {
let length = s.len();
if length > ::std::i32::MAX as usize {
ffi::sqlite3_result_error_toobig(ctx);
@ -96,7 +96,7 @@ pub fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
ffi::sqlite3_result_text(ctx, c_str.as_ptr(), length as c_int, destructor);
}
},
ValueRef::Blob(b) => unsafe {
ValueRef::Blob(b) => {
let length = b.len();
if length > ::std::i32::MAX as usize {
ffi::sqlite3_result_error_toobig(ctx);

View File

@ -58,7 +58,7 @@ impl CSVTab {
}
impl VTab<CSVTabCursor> for CSVTab {
fn connect(db: *mut ffi::sqlite3, _aux: *mut c_void, args: &[&[u8]]) -> Result<CSVTab> {
unsafe fn connect(db: *mut ffi::sqlite3, _aux: *mut c_void, args: &[&[u8]]) -> Result<CSVTab> {
if args.len() < 4 {
return Err(Error::ModuleError("no CSV file specified".to_owned()));
}
@ -159,7 +159,7 @@ impl CSVTabCursor {
fn new(reader: csv::Reader<File>) -> CSVTabCursor {
CSVTabCursor {
base: Default::default(),
reader: reader,
reader,
row_number: 0,
cols: Vec::new(),
eof: false,
@ -168,8 +168,8 @@ impl CSVTabCursor {
}
impl VTabCursor<CSVTab> for CSVTabCursor {
fn vtab(&self) -> &mut CSVTab {
unsafe { &mut *(self.base.pVtab as *mut CSVTab) }
fn vtab(&self) -> &CSVTab {
unsafe { & *(self.base.pVtab as *const CSVTab) }
}
fn filter(&mut self,

View File

@ -2,7 +2,6 @@
//! Port of C ["intarray"](http://www.sqlite.org/cgi/src/finfo?name=src/test_intarray.h).
use std::cell::RefCell;
use std::default::Default;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::rc::Rc;
@ -61,14 +60,14 @@ struct IntArrayVTab {
}
impl VTab<IntArrayVTabCursor> for IntArrayVTab {
fn connect(db: *mut ffi::sqlite3,
unsafe fn connect(db: *mut ffi::sqlite3,
aux: *mut c_void,
_args: &[&[u8]])
-> Result<IntArrayVTab> {
let array = unsafe { mem::transmute(aux) };
let array = aux as *const Rc<RefCell<Vec<i64>>>;
let vtab = IntArrayVTab {
base: Default::default(),
array: array,
array,
};
try!(declare_vtab(db, "CREATE TABLE x(value INTEGER PRIMARY KEY)"));
Ok(vtab)
@ -102,8 +101,8 @@ impl IntArrayVTabCursor {
}
impl VTabCursor<IntArrayVTab> for IntArrayVTabCursor {
fn vtab(&self) -> &mut IntArrayVTab {
unsafe { &mut *(self.base.pVtab as *mut IntArrayVTab) }
fn vtab(&self) -> &IntArrayVTab {
unsafe { & *(self.base.pVtab as *const IntArrayVTab) }
}
fn filter(&mut self,
_idx_num: c_int,

View File

@ -2,7 +2,6 @@
//! (See http://sqlite.org/vtab.html)
use std::borrow::Cow::{self, Borrowed, Owned};
use std::ffi::CString;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
use std::slice;
@ -46,12 +45,12 @@ pub trait VTab<C: VTabCursor<Self>>: Sized {
/// Create a new instance of a virtual table in response to a CREATE VIRTUAL TABLE statement.
/// The `db` parameter is a pointer to the SQLite database connection that is executing
/// the CREATE VIRTUAL TABLE statement.
fn create(db: *mut ffi::sqlite3, aux: *mut c_void, args: &[&[u8]]) -> Result<Self> {
unsafe fn create(db: *mut ffi::sqlite3, aux: *mut c_void, args: &[&[u8]]) -> Result<Self> {
Self::connect(db, aux, args)
}
/// Similar to `create`. The difference is that `connect` is called to establish a new connection
/// to an _existing_ virtual table whereas `create` is called to create a new virtual table from scratch.
fn connect(db: *mut ffi::sqlite3, aux: *mut c_void, args: &[&[u8]]) -> Result<Self>;
unsafe fn connect(db: *mut ffi::sqlite3, aux: *mut c_void, args: &[&[u8]]) -> Result<Self>;
/// Determine the best way to access the virtual table.
fn best_index(&self, info: &mut IndexInfo) -> Result<()>;
/// Create a new cursor used for accessing a virtual table.
@ -183,7 +182,7 @@ impl<'a> IndexConstraintUsage<'a> {
/// Virtual table cursor trait.
pub trait VTabCursor<V: VTab<Self>>: Sized {
/// Accessor to the associated virtual table.
fn vtab(&self) -> &mut V;
fn vtab(&self) -> &V;
/// Begin a search of a virtual table.
fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values) -> Result<()>;
/// Advance cursor to the next row of a result set initiated by `filter`.
@ -206,7 +205,7 @@ impl Context {
pub fn set_result<T: ToSql>(&mut self, value: &T) {
let t = value.to_sql();
match t {
Ok(ref value) => set_result(self.0, value),
Ok(ref value) => unsafe { set_result(self.0, value) },
Err(err) => unsafe { report_error(self.0, &err) },
}
}
@ -296,7 +295,7 @@ impl InnerConnection {
ffi::sqlite3_create_module_v2(self.db(),
c_name.as_ptr(),
module,
mem::transmute(boxed_aux),
boxed_aux as *mut c_void,
Some(free_boxed_value::<A>))
}
}
@ -313,9 +312,9 @@ impl InnerConnection {
}
/// Declare the schema of a virtual table.
pub fn declare_vtab(db: *mut ffi::sqlite3, sql: &str) -> Result<()> {
pub unsafe fn declare_vtab(db: *mut ffi::sqlite3, sql: &str) -> Result<()> {
let c_sql = try!(CString::new(sql));
let rc = unsafe { ffi::sqlite3_declare_vtab(db, c_sql.as_ptr()) };
let rc = ffi::sqlite3_declare_vtab(db, c_sql.as_ptr());
if rc == ffi::SQLITE_OK {
Ok(())
} else {
@ -335,7 +334,7 @@ pub fn escape_double_quote(identifier: &str) -> Cow<str> {
// FIXME copy/paste from function.rs
unsafe extern "C" fn free_boxed_value<T>(p: *mut c_void) {
let _: Box<T> = Box::from_raw(mem::transmute(p));
let _: Box<T> = Box::from_raw(p as *mut T);
}
#[macro_export]

View File

@ -61,7 +61,7 @@ struct SeriesTab {
impl VTab<SeriesTabCursor> for SeriesTab {
fn connect(db: *mut ffi::sqlite3,
unsafe fn connect(db: *mut ffi::sqlite3,
_aux: *mut c_void,
_args: &[&[u8]])
-> Result<SeriesTab> {
@ -172,8 +172,8 @@ impl SeriesTabCursor {
}
}
impl VTabCursor<SeriesTab> for SeriesTabCursor {
fn vtab(&self) -> &mut SeriesTab {
unsafe { &mut *(self.base.pVtab as *mut SeriesTab) }
fn vtab(&self) -> &SeriesTab {
unsafe { & *(self.base.pVtab as *const SeriesTab) }
}
fn filter(&mut self,
idx_num: c_int,