diff --git a/src/blob/mod.rs b/src/blob/mod.rs index f221d61..81c6098 100644 --- a/src/blob/mod.rs +++ b/src/blob/mod.rs @@ -321,8 +321,7 @@ impl io::Read for Blob<'_> { if n <= 0 { return Ok(0); } - let rc = - unsafe { ffi::sqlite3_blob_read(self.blob, buf.as_mut_ptr() as *mut _, n, self.pos) }; + let rc = unsafe { ffi::sqlite3_blob_read(self.blob, buf.as_mut_ptr().cast(), n, self.pos) }; self.conn .decode_result(rc) .map(|_| { diff --git a/src/blob/pos_io.rs b/src/blob/pos_io.rs index 01f9c34..ecc7d65 100644 --- a/src/blob/pos_io.rs +++ b/src/blob/pos_io.rs @@ -47,7 +47,7 @@ impl<'conn> Blob<'conn> { self.conn.decode_result(unsafe { ffi::sqlite3_blob_write( self.blob, - buf.as_ptr() as *const _, + buf.as_ptr().cast(), buf.len() as i32, write_start as i32, ) @@ -84,7 +84,7 @@ impl<'conn> Blob<'conn> { // Safety: this is safe because `raw_read_at` never stores uninitialized // data into `as_uninit`. let as_uninit: &mut [MaybeUninit] = - unsafe { from_raw_parts_mut(buf.as_mut_ptr() as *mut _, buf.len()) }; + unsafe { from_raw_parts_mut(buf.as_mut_ptr().cast(), buf.len()) }; self.raw_read_at(as_uninit, read_start).map(|s| s.len()) } @@ -119,7 +119,7 @@ impl<'conn> Blob<'conn> { // We could return `Ok(&mut [])`, but it seems confusing that the // pointers don't match, so fabricate a empty slice of u8 with the // same base pointer as `buf`. - let empty = unsafe { from_raw_parts_mut(buf.as_mut_ptr() as *mut u8, 0) }; + let empty = unsafe { from_raw_parts_mut(buf.as_mut_ptr().cast::(), 0) }; return Ok(empty); } @@ -152,12 +152,12 @@ impl<'conn> Blob<'conn> { unsafe { self.conn.decode_result(ffi::sqlite3_blob_read( self.blob, - buf.as_mut_ptr() as *mut _, + buf.as_mut_ptr().cast(), read_len as i32, read_start as i32, ))?; - Ok(from_raw_parts_mut(buf.as_mut_ptr() as *mut u8, read_len)) + Ok(from_raw_parts_mut(buf.as_mut_ptr().cast::(), read_len)) } } diff --git a/src/collation.rs b/src/collation.rs index 7a24ad7..c1fe3f7 100644 --- a/src/collation.rs +++ b/src/collation.rs @@ -10,7 +10,7 @@ use crate::{str_to_cstring, Connection, InnerConnection, Result}; // FIXME copy/paste from function.rs unsafe extern "C" fn free_boxed_value(p: *mut c_void) { - drop(Box::from_raw(p as *mut T)); + drop(Box::from_raw(p.cast::())); } impl Connection { @@ -57,14 +57,14 @@ impl InnerConnection { C: Fn(&str, &str) -> Ordering, { let r = catch_unwind(|| { - let boxed_f: *mut C = arg1 as *mut C; + let boxed_f: *mut C = arg1.cast::(); assert!(!boxed_f.is_null(), "Internal error - null function pointer"); let s1 = { - let c_slice = slice::from_raw_parts(arg3 as *const u8, arg2 as usize); + let c_slice = slice::from_raw_parts(arg3.cast::(), arg2 as usize); String::from_utf8_lossy(c_slice) }; let s2 = { - let c_slice = slice::from_raw_parts(arg5 as *const u8, arg4 as usize); + let c_slice = slice::from_raw_parts(arg5.cast::(), arg4 as usize); String::from_utf8_lossy(c_slice) }; (*boxed_f)(s1.as_ref(), s2.as_ref()) @@ -91,7 +91,7 @@ impl InnerConnection { self.db(), c_name.as_ptr(), flags, - boxed_f as *mut c_void, + boxed_f.cast::(), Some(call_boxed_closure::), Some(free_boxed_value::), ) diff --git a/src/context.rs b/src/context.rs index b37159c..5f935fa 100644 --- a/src/context.rs +++ b/src/context.rs @@ -62,7 +62,7 @@ pub(super) unsafe fn set_result(ctx: *mut sqlite3_context, result: &ToSqlOutput< } else { ffi::sqlite3_result_blob( ctx, - b.as_ptr() as *const c_void, + b.as_ptr().cast::(), length as c_int, ffi::SQLITE_TRANSIENT(), ); diff --git a/src/functions.rs b/src/functions.rs index e6f7e0f..e613182 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -98,7 +98,7 @@ unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) { } unsafe extern "C" fn free_boxed_value(p: *mut c_void) { - drop(Box::from_raw(p as *mut T)); + drop(Box::from_raw(p.cast::())); } /// Context is a wrapper for the SQLite function @@ -198,7 +198,7 @@ impl Context<'_> { ffi::sqlite3_set_auxdata( self.ctx, arg, - raw as *mut _, + raw.cast(), Some(free_boxed_value::), ); }; @@ -477,7 +477,7 @@ impl InnerConnection { T: ToSql, { let r = catch_unwind(|| { - let boxed_f: *mut F = ffi::sqlite3_user_data(ctx) as *mut F; + let boxed_f: *mut F = ffi::sqlite3_user_data(ctx).cast::(); assert!(!boxed_f.is_null(), "Internal error - null function pointer"); let ctx = Context { ctx, @@ -509,7 +509,7 @@ impl InnerConnection { c_name.as_ptr(), n_arg, flags.bits(), - boxed_f as *mut c_void, + boxed_f.cast::(), Some(call_boxed_closure::), None, None, @@ -539,7 +539,7 @@ impl InnerConnection { c_name.as_ptr(), n_arg, flags.bits(), - boxed_aggr as *mut c_void, + boxed_aggr.cast::(), None, Some(call_boxed_step::), Some(call_boxed_final::), @@ -570,7 +570,7 @@ impl InnerConnection { c_name.as_ptr(), n_arg, flags.bits(), - boxed_aggr as *mut c_void, + boxed_aggr.cast::(), Some(call_boxed_step::), Some(call_boxed_final::), Some(call_boxed_value::), @@ -625,7 +625,7 @@ unsafe extern "C" fn call_boxed_step( }; let r = catch_unwind(|| { - let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx) as *mut D; + let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx).cast::(); assert!( !boxed_aggr.is_null(), "Internal error - null aggregate pointer" @@ -672,7 +672,7 @@ unsafe extern "C" fn call_boxed_inverse( }; let r = catch_unwind(|| { - let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx) as *mut W; + let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx).cast::(); assert!( !boxed_aggr.is_null(), "Internal error - null aggregate pointer" @@ -717,7 +717,7 @@ where }; let r = catch_unwind(|| { - let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx) as *mut D; + let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx).cast::(); assert!( !boxed_aggr.is_null(), "Internal error - null aggregate pointer" @@ -762,7 +762,7 @@ where }; let r = catch_unwind(|| { - let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx) as *mut W; + let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx).cast::(); assert!( !boxed_aggr.is_null(), "Internal error - null aggregate pointer" diff --git a/src/hooks.rs b/src/hooks.rs index 52c0f86..f0ae1f3 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -425,7 +425,7 @@ impl InnerConnection { F: FnMut() -> bool, { let r = catch_unwind(|| { - let boxed_hook: *mut F = p_arg as *mut F; + let boxed_hook: *mut F = p_arg.cast::(); (*boxed_hook)() }); if let Ok(true) = r { @@ -451,7 +451,7 @@ impl InnerConnection { ffi::sqlite3_commit_hook( self.db(), Some(call_boxed_closure::), - boxed_hook as *mut _, + boxed_hook.cast(), ) } } @@ -474,7 +474,7 @@ impl InnerConnection { F: FnMut(), { drop(catch_unwind(|| { - let boxed_hook: *mut F = p_arg as *mut F; + let boxed_hook: *mut F = p_arg.cast::(); (*boxed_hook)(); })); } @@ -492,7 +492,7 @@ impl InnerConnection { ffi::sqlite3_rollback_hook( self.db(), Some(call_boxed_closure::), - boxed_hook as *mut _, + boxed_hook.cast(), ) } } @@ -521,7 +521,7 @@ impl InnerConnection { { let action = Action::from(action_code); drop(catch_unwind(|| { - let boxed_hook: *mut F = p_arg as *mut F; + let boxed_hook: *mut F = p_arg.cast::(); (*boxed_hook)( action, expect_utf8(p_db_name, "database name"), @@ -544,7 +544,7 @@ impl InnerConnection { ffi::sqlite3_update_hook( self.db(), Some(call_boxed_closure::), - boxed_hook as *mut _, + boxed_hook.cast(), ) } } @@ -567,7 +567,7 @@ impl InnerConnection { F: FnMut() -> bool, { let r = catch_unwind(|| { - let boxed_handler: *mut F = p_arg as *mut F; + let boxed_handler: *mut F = p_arg.cast::(); (*boxed_handler)() }); if let Ok(true) = r { @@ -623,7 +623,7 @@ impl InnerConnection { "accessor (inner-most trigger or view)", ), }; - let boxed_hook: *mut F = p_arg as *mut F; + let boxed_hook: *mut F = p_arg.cast::(); (*boxed_hook)(auth_ctx) }) .map_or_else(|_| ffi::SQLITE_ERROR, Authorization::into_raw) @@ -661,7 +661,7 @@ impl InnerConnection { } unsafe fn free_boxed_hook(p: *mut c_void) { - drop(Box::from_raw(p as *mut F)); + drop(Box::from_raw(p.cast::())); } unsafe fn expect_utf8<'a>(p_str: *const c_char, description: &'static str) -> &'a str { diff --git a/src/inner_connection.rs b/src/inner_connection.rs index b3b1bcd..f57541d 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -208,7 +208,7 @@ impl InnerConnection { Ok(()) } else { let message = super::errmsg_to_string(errmsg); - ffi::sqlite3_free(errmsg as *mut ::std::os::raw::c_void); + ffi::sqlite3_free(errmsg.cast::<::std::os::raw::c_void>()); Err(error_from_sqlite_code(r, Some(message))) } } diff --git a/src/lib.rs b/src/lib.rs index ac91720..cbd0677 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,10 +258,10 @@ fn str_to_cstring(s: &str) -> Result { fn str_for_sqlite(s: &[u8]) -> Result<(*const c_char, c_int, ffi::sqlite3_destructor_type)> { let len = len_as_c_int(s.len())?; let (ptr, dtor_info) = if len != 0 { - (s.as_ptr() as *const c_char, ffi::SQLITE_TRANSIENT()) + (s.as_ptr().cast::(), ffi::SQLITE_TRANSIENT()) } else { // Return a pointer guaranteed to live forever - ("".as_ptr() as *const c_char, ffi::SQLITE_STATIC()) + ("".as_ptr().cast::(), ffi::SQLITE_STATIC()) }; Ok((ptr, len, dtor_info)) } diff --git a/src/statement.rs b/src/statement.rs index 04c71ef..35f608f 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -717,7 +717,7 @@ impl Statement<'_> { ffi::sqlite3_bind_blob( ptr, col as c_int, - b.as_ptr() as *const c_void, + b.as_ptr().cast::(), length, ffi::SQLITE_TRANSIENT(), ) @@ -875,7 +875,7 @@ impl Statement<'_> { !text.is_null(), "unexpected SQLITE_TEXT column type with NULL data" ); - from_raw_parts(text as *const u8, len as usize) + from_raw_parts(text.cast::(), len as usize) }; ValueRef::Text(s) @@ -897,7 +897,7 @@ impl Statement<'_> { !blob.is_null(), "unexpected SQLITE_BLOB column type with NULL data" ); - ValueRef::Blob(unsafe { from_raw_parts(blob as *const u8, len as usize) }) + ValueRef::Blob(unsafe { from_raw_parts(blob.cast::(), len as usize) }) } else { // The return value from sqlite3_column_blob() for a zero-length BLOB // is a NULL pointer. diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index f25335c..c0d81ca 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -229,7 +229,7 @@ impl<'a> ValueRef<'a> { !text.is_null(), "unexpected SQLITE_TEXT value type with NULL data" ); - let s = from_raw_parts(text as *const u8, len as usize); + let s = from_raw_parts(text.cast::(), len as usize); ValueRef::Text(s) } ffi::SQLITE_BLOB => { @@ -247,7 +247,7 @@ impl<'a> ValueRef<'a> { !blob.is_null(), "unexpected SQLITE_BLOB value type with NULL data" ); - ValueRef::Blob(from_raw_parts(blob as *const u8, len as usize)) + ValueRef::Blob(from_raw_parts(blob.cast::(), len as usize)) } else { // The return value from sqlite3_value_blob() for a zero-length BLOB // is a NULL pointer. diff --git a/src/util/sqlite_string.rs b/src/util/sqlite_string.rs index ce492b1..3cdf109 100644 --- a/src/util/sqlite_string.rs +++ b/src/util/sqlite_string.rs @@ -120,7 +120,7 @@ impl SqliteMallocString { // `>` because we added 1. debug_assert!(len_to_alloc > 0); debug_assert_eq!((len_to_alloc - 1) as usize, src_len); - NonNull::new(ffi::sqlite3_malloc(len_to_alloc) as *mut c_char) + NonNull::new(ffi::sqlite3_malloc(len_to_alloc).cast::()) }) .unwrap_or_else(|| { use std::alloc::{handle_alloc_error, Layout}; @@ -138,7 +138,7 @@ impl SqliteMallocString { // Note: This call does not return. handle_alloc_error(layout); }); - let buf: *mut c_char = res_ptr.as_ptr() as *mut c_char; + let buf: *mut c_char = res_ptr.as_ptr().cast::(); src_ptr.copy_to_nonoverlapping(buf, src_len); buf.add(src_len).write(0); debug_assert_eq!(std::ffi::CStr::from_ptr(res_ptr.as_ptr()).to_bytes(), bytes); diff --git a/src/vtab/array.rs b/src/vtab/array.rs index 0a494a3..adfd9c9 100644 --- a/src/vtab/array.rs +++ b/src/vtab/array.rs @@ -41,7 +41,7 @@ use crate::{Connection, Result}; // http://sqlite.org/bindptr.html -pub(crate) const ARRAY_TYPE: *const c_char = b"rarray\0" as *const u8 as *const c_char; +pub(crate) const ARRAY_TYPE: *const c_char = (b"rarray\0" as *const u8).cast::(); pub(crate) unsafe extern "C" fn free_array(p: *mut c_void) { drop(Rc::from_raw(p as *const Vec)); diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 367e20d..0e9881f 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -712,7 +712,7 @@ impl InnerConnection { self.db(), c_name.as_ptr(), &module.base, - boxed_aux as *mut c_void, + boxed_aux.cast::(), Some(free_boxed_value::), ) } @@ -782,7 +782,7 @@ pub fn parse_boolean(s: &str) -> Option { // FIXME copy/paste from function.rs unsafe extern "C" fn free_boxed_value(p: *mut c_void) { - let _: Box = Box::from_raw(p as *mut T); + drop(Box::from_raw(p.cast::())); } unsafe extern "C" fn rust_create<'vtab, T>( @@ -799,7 +799,7 @@ where use std::ffi::CStr; let mut conn = VTabConnection(db); - let aux = aux as *mut T::Aux; + let aux = aux.cast::(); let args = slice::from_raw_parts(argv, argc as usize); let vec = args .iter() @@ -811,7 +811,7 @@ where let rc = ffi::sqlite3_declare_vtab(db, c_sql.as_ptr()); if rc == ffi::SQLITE_OK { let boxed_vtab: *mut T = Box::into_raw(Box::new(vtab)); - *pp_vtab = boxed_vtab as *mut ffi::sqlite3_vtab; + *pp_vtab = boxed_vtab.cast::(); ffi::SQLITE_OK } else { let err = error_from_sqlite_code(rc, None); @@ -851,7 +851,7 @@ where use std::ffi::CStr; let mut conn = VTabConnection(db); - let aux = aux as *mut T::Aux; + let aux = aux.cast::(); let args = slice::from_raw_parts(argv, argc as usize); let vec = args .iter() @@ -863,7 +863,7 @@ where let rc = ffi::sqlite3_declare_vtab(db, c_sql.as_ptr()); if rc == ffi::SQLITE_OK { let boxed_vtab: *mut T = Box::into_raw(Box::new(vtab)); - *pp_vtab = boxed_vtab as *mut ffi::sqlite3_vtab; + *pp_vtab = boxed_vtab.cast::(); ffi::SQLITE_OK } else { let err = error_from_sqlite_code(rc, None); @@ -896,7 +896,7 @@ unsafe extern "C" fn rust_best_index<'vtab, T>( where T: VTab<'vtab>, { - let vt = vtab as *mut T; + let vt = vtab.cast::(); let mut idx_info = IndexInfo(info); match (*vt).best_index(&mut idx_info) { Ok(_) => ffi::SQLITE_OK, @@ -920,8 +920,8 @@ where if vtab.is_null() { return ffi::SQLITE_OK; } - let vtab = vtab as *mut T; - let _: Box = Box::from_raw(vtab); + let vtab = vtab.cast::(); + drop(Box::from_raw(vtab)); ffi::SQLITE_OK } @@ -932,7 +932,7 @@ where if vtab.is_null() { return ffi::SQLITE_OK; } - let vt = vtab as *mut T; + let vt = vtab.cast::(); match (*vt).destroy() { Ok(_) => { drop(Box::from_raw(vt)); @@ -958,11 +958,11 @@ unsafe extern "C" fn rust_open<'vtab, T: 'vtab>( where T: VTab<'vtab>, { - let vt = vtab as *mut T; + let vt = vtab.cast::(); match (*vt).open() { Ok(cursor) => { let boxed_cursor: *mut T::Cursor = Box::into_raw(Box::new(cursor)); - *pp_cursor = boxed_cursor as *mut ffi::sqlite3_vtab_cursor; + *pp_cursor = boxed_cursor.cast::(); ffi::SQLITE_OK } Err(Error::SqliteFailure(err, s)) => { @@ -982,8 +982,8 @@ unsafe extern "C" fn rust_close(cursor: *mut ffi::sqlite3_vtab_cursor) -> c_i where C: VTabCursor, { - let cr = cursor as *mut C; - let _: Box = Box::from_raw(cr); + let cr = cursor.cast::(); + drop(Box::from_raw(cr)); ffi::SQLITE_OK } @@ -1023,7 +1023,7 @@ unsafe extern "C" fn rust_eof(cursor: *mut ffi::sqlite3_vtab_cursor) -> c_int where C: VTabCursor, { - let cr = cursor as *mut C; + let cr = cursor.cast::(); (*cr).eof() as c_int } @@ -1035,7 +1035,7 @@ unsafe extern "C" fn rust_column( where C: VTabCursor, { - let cr = cursor as *mut C; + let cr = cursor.cast::(); let mut ctxt = Context(ctx); result_error(ctx, (*cr).column(&mut ctxt, i)) } @@ -1047,7 +1047,7 @@ unsafe extern "C" fn rust_rowid( where C: VTabCursor, { - let cr = cursor as *mut C; + let cr = cursor.cast::(); match (*cr).rowid() { Ok(rowid) => { *p_rowid = rowid; @@ -1081,7 +1081,7 @@ unsafe fn cursor_error(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result< #[cold] unsafe fn set_err_msg(vtab: *mut ffi::sqlite3_vtab, err_msg: &str) { if !(*vtab).zErrMsg.is_null() { - ffi::sqlite3_free((*vtab).zErrMsg as *mut c_void); + ffi::sqlite3_free((*vtab).zErrMsg.cast::()); } (*vtab).zErrMsg = alloc(err_msg); }