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