Skip to content

Commit c06acf9

Browse files
committed
1. Resources managed by sqlite should be left alone with Box::into
2. sqlite3, has a naming convention: sqlite3_xxx_init, where xxx cannot contain underscores although the function itself may contain an underscore in sqlite3 itself
1 parent f0eca51 commit c06acf9

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

examples/sum_int.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub fn x_inverse(context: *mut sqlite3_context, values: &[*mut sqlite3_value]) -
3939
}
4040

4141
#[sqlite_entrypoint]
42-
pub fn sqlite3_sum_int_init(db: *mut sqlite3) -> Result<()> {
42+
pub fn sqlite3_sumint_init(db: *mut sqlite3) -> Result<()> {
4343
let flags = FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC;
44-
define_window_function(db, "sum_int", -1, flags,
44+
define_window_function(db, "sumint", -1, flags,
4545
WindowFunctionCallbacks::new(x_step, x_final, x_value, x_inverse))?;
4646
Ok(())
4747
}

src/window.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn define_window_function_with_aux<T>(
129129
let aux = (*x).1;
130130
// .collect slows things waaaay down, so stick with slice for now
131131
let args = slice::from_raw_parts(argv, argc as usize);
132-
let b = Box::from_raw(aux);
132+
let b: Box<T> = Box::from_raw(aux);
133133
match boxed_function(context, args, &*b) {
134134
Ok(()) => (),
135135
Err(e) => {
@@ -180,6 +180,7 @@ pub fn define_window_function_with_aux<T>(
180180
}
181181
}
182182
}
183+
Box::into_raw(b);
183184
}
184185

185186
unsafe extern "C" fn x_value_wrapper<T>(
@@ -198,6 +199,7 @@ pub fn define_window_function_with_aux<T>(
198199
}
199200
}
200201
}
202+
Box::into_raw(b);
201203
}
202204

203205
create_window_function(

tests/test_sum_int.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub fn x_inverse(context: *mut sqlite3_context, values: &[*mut sqlite3_value]) -
3636
}
3737

3838
#[sqlite_entrypoint]
39-
pub fn sqlite3_sum_int_init(db: *mut sqlite3) -> Result<()> {
39+
pub fn sqlite3_sumint_init(db: *mut sqlite3) -> Result<()> {
4040
let flags = FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC;
41-
define_window_function(db, "sum_int", -1, flags,
41+
define_window_function(db, "sumint", -1, flags,
4242
WindowFunctionCallbacks::new(x_step, x_final, x_value, x_inverse))?;
4343
Ok(())
4444
}
@@ -54,7 +54,7 @@ mod tests {
5454
#[test]
5555
fn test_rusqlite_auto_extension() {
5656
unsafe {
57-
sqlite3_auto_extension(Some(std::mem::transmute(sqlite3_sum_int_init as *const ())));
57+
sqlite3_auto_extension(Some(std::mem::transmute(sqlite3_sumint_init as *const ())));
5858
}
5959

6060
let conn = Connection::open_in_memory().unwrap();
@@ -65,7 +65,7 @@ mod tests {
6565
let _ = conn
6666
.execute("INSERT INTO t3 VALUES ('a', 4), ('b', 5), ('c', 3), ('d', 8), ('e', 1)", ());
6767

68-
let result: sqlite3_int64 = conn.query_row("SELECT x, sum_int(y) OVER (
68+
let result: sqlite3_int64 = conn.query_row("SELECT x, sumint(y) OVER (
6969
ORDER BY x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
7070
) AS sum_y
7171
FROM t3 ORDER BY x", (), |x| x.get(1)).unwrap();

0 commit comments

Comments
 (0)