mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Fix ChangesetIter::start_strm
The input reference must still be alive after the function returns
This commit is contained in:
parent
b57fd14b26
commit
de9f06f142
@ -305,14 +305,13 @@ pub struct ChangesetIter<'changeset> {
|
|||||||
|
|
||||||
impl ChangesetIter<'_> {
|
impl ChangesetIter<'_> {
|
||||||
/// Create an iterator on `input`
|
/// Create an iterator on `input`
|
||||||
pub fn start_strm<'input>(input: &'input mut dyn Read) -> Result<ChangesetIter<'input>> {
|
pub fn start_strm<'input>(input: &&'input mut dyn Read) -> Result<ChangesetIter<'input>> {
|
||||||
let input_ref = &input;
|
|
||||||
let mut it = MaybeUninit::uninit();
|
let mut it = MaybeUninit::uninit();
|
||||||
check!(unsafe {
|
check!(unsafe {
|
||||||
ffi::sqlite3changeset_start_strm(
|
ffi::sqlite3changeset_start_strm(
|
||||||
it.as_mut_ptr(),
|
it.as_mut_ptr(),
|
||||||
Some(x_input),
|
Some(x_input),
|
||||||
input_ref as *const &mut dyn Read as *mut c_void,
|
input as *const &mut dyn Read as *mut c_void,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let it: *mut ffi::sqlite3_changeset_iter = unsafe { it.assume_init() };
|
let it: *mut ffi::sqlite3_changeset_iter = unsafe { it.assume_init() };
|
||||||
@ -743,7 +742,7 @@ unsafe extern "C" fn x_output(p_out: *mut c_void, data: *const c_void, len: c_in
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use fallible_streaming_iterator::FallibleStreamingIterator;
|
use fallible_streaming_iterator::FallibleStreamingIterator;
|
||||||
use std::io::Cursor;
|
use std::io::Read;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use super::{Changeset, ChangesetIter, ConflictAction, ConflictType, Session};
|
use super::{Changeset, ChangesetIter, ConflictAction, ConflictType, Session};
|
||||||
@ -809,8 +808,8 @@ mod test {
|
|||||||
assert!(!output.is_empty());
|
assert!(!output.is_empty());
|
||||||
assert_eq!(14, output.len());
|
assert_eq!(14, output.len());
|
||||||
|
|
||||||
let mut input = Cursor::new(output);
|
let input: &mut dyn Read = &mut output.as_slice();
|
||||||
let mut iter = ChangesetIter::start_strm(&mut input).unwrap();
|
let mut iter = ChangesetIter::start_strm(&input).unwrap();
|
||||||
let item = iter.next().unwrap();
|
let item = iter.next().unwrap();
|
||||||
assert!(item.is_some());
|
assert!(item.is_some());
|
||||||
}
|
}
|
||||||
@ -868,7 +867,7 @@ mod test {
|
|||||||
db.execute_batch("CREATE TABLE foo(t TEXT PRIMARY KEY NOT NULL);")
|
db.execute_batch("CREATE TABLE foo(t TEXT PRIMARY KEY NOT NULL);")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut input = Cursor::new(output);
|
let mut input = output.as_slice();
|
||||||
db.apply_strm(
|
db.apply_strm(
|
||||||
&mut input,
|
&mut input,
|
||||||
None::<fn(&str) -> bool>,
|
None::<fn(&str) -> bool>,
|
||||||
|
Loading…
Reference in New Issue
Block a user