Clippy: fix warnings

This commit is contained in:
gwenn
2019-07-10 21:10:12 +02:00
parent 94d378692e
commit 208f3c084b
9 changed files with 107 additions and 58 deletions

View File

@@ -1,12 +1,12 @@
use std::ffi::CString;
use std::mem;
use std::mem::MaybeUninit;
use std::os::raw::c_int;
#[cfg(feature = "load_extension")]
use std::path::Path;
use std::ptr;
use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex, Once, ONCE_INIT};
use std::sync::{Arc, Mutex, Once};
use super::ffi;
use super::{str_for_sqlite, str_to_cstring};
@@ -78,8 +78,10 @@ impl InnerConnection {
}
unsafe {
let mut db: *mut ffi::sqlite3 = mem::uninitialized();
let r = ffi::sqlite3_open_v2(c_path.as_ptr(), &mut db, flags.bits(), ptr::null());
let mut db = MaybeUninit::uninit();
let r =
ffi::sqlite3_open_v2(c_path.as_ptr(), db.as_mut_ptr(), flags.bits(), ptr::null());
let db: *mut ffi::sqlite3 = db.assume_init();
if r != ffi::SQLITE_OK {
let e = if db.is_null() {
error_from_sqlite_code(r, None)
@@ -180,21 +182,27 @@ impl InnerConnection {
let dylib_str = super::path_to_cstring(dylib_path)?;
unsafe {
let mut errmsg: *mut c_char = mem::uninitialized();
let mut errmsg = MaybeUninit::uninit();
let r = if let Some(entry_point) = entry_point {
let c_entry = str_to_cstring(entry_point)?;
ffi::sqlite3_load_extension(
self.db,
dylib_str.as_ptr(),
c_entry.as_ptr(),
&mut errmsg,
errmsg.as_mut_ptr(),
)
} else {
ffi::sqlite3_load_extension(self.db, dylib_str.as_ptr(), ptr::null(), &mut errmsg)
ffi::sqlite3_load_extension(
self.db,
dylib_str.as_ptr(),
ptr::null(),
errmsg.as_mut_ptr(),
)
};
if r == ffi::SQLITE_OK {
Ok(())
} else {
let errmsg: *mut c_char = errmsg.assume_init();
let message = super::errmsg_to_string(&*errmsg);
ffi::sqlite3_free(errmsg as *mut ::std::os::raw::c_void);
Err(error_from_sqlite_code(r, Some(message)))
@@ -207,7 +215,7 @@ impl InnerConnection {
}
pub fn prepare<'a>(&mut self, conn: &'a Connection, sql: &str) -> Result<Statement<'a>> {
let mut c_stmt: *mut ffi::sqlite3_stmt = unsafe { mem::uninitialized() };
let mut c_stmt = MaybeUninit::uninit();
let (c_sql, len, _) = str_for_sqlite(sql)?;
let r = unsafe {
if cfg!(feature = "unlock_notify") {
@@ -217,7 +225,7 @@ impl InnerConnection {
self.db(),
c_sql,
len,
&mut c_stmt,
c_stmt.as_mut_ptr(),
ptr::null_mut(),
);
if !unlock_notify::is_locked(self.db, rc) {
@@ -230,9 +238,10 @@ impl InnerConnection {
}
rc
} else {
ffi::sqlite3_prepare_v2(self.db(), c_sql, len, &mut c_stmt, ptr::null_mut())
ffi::sqlite3_prepare_v2(self.db(), c_sql, len, c_stmt.as_mut_ptr(), ptr::null_mut())
}
};
let c_stmt: *mut ffi::sqlite3_stmt = unsafe { c_stmt.assume_init() };
self.decode_result(r)
.map(|_| Statement::new(conn, RawStatement::new(c_stmt)))
}
@@ -280,7 +289,7 @@ impl Drop for InnerConnection {
}
#[cfg(not(feature = "bundled"))]
static SQLITE_VERSION_CHECK: Once = ONCE_INIT;
static SQLITE_VERSION_CHECK: Once = Once::new();
#[cfg(not(feature = "bundled"))]
pub static BYPASS_VERSION_CHECK: AtomicBool = AtomicBool::new(false);
@@ -328,7 +337,7 @@ rusqlite was built against SQLite {} but the runtime SQLite version is {}. To fi
});
}
static SQLITE_INIT: Once = ONCE_INIT;
static SQLITE_INIT: Once = Once::new();
pub static BYPASS_SQLITE_INIT: AtomicBool = AtomicBool::new(false);
fn ensure_safe_sqlite_threading_mode() -> Result<()> {