Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions smoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ sqlite3mc-src = { path = ".." }
[build-dependencies]
cc = "1.2.27"
sqlite3mc-src = { path = ".." }

[lints.rust]
missing_docs = "forbid"
unsafe_op_in_unsafe_fn = "deny"
rust_2018_idioms = { level = "warn", priority = -1 }
unreachable_pub = "warn"

[lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
allow_attributes = "deny"
allow_attributes_without_reason = "deny"
2 changes: 2 additions & 0 deletions smoke/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Compiles the vendored amalgamation for the native smoke binaries.

fn main() {
let source = sqlite3mc_src::source_dir().join(sqlite3mc_src::SOURCE_FILE);
println!("cargo:rerun-if-changed={}", source.display());
Expand Down
46 changes: 29 additions & 17 deletions smoke/src/bin/interop.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,65 @@
//! `write DIR` creates `native-<cipher>.db` for every cipher, `read DIR PREFIX` checks the `PREFIX-<cipher>.db` Wasm wrote.

#[expect(
unreachable_pub,
reason = "The Wasm crate exports this shared module to its integration tests"
)]
#[path = "../exchange.rs"]
mod exchange;

#[expect(
non_camel_case_types,
reason = "SQLite's C names, as sqlite-wasm-rs spells them"
clippy::redundant_pub_crate,
reason = "Restricted FFI visibility satisfies `unreachable_pub` in this binary"
)]
mod ffi {
use std::ffi::{c_char, c_int, c_uchar, c_void};

pub enum sqlite3 {}
pub enum sqlite3_stmt {}
#[repr(C)]
pub(super) struct sqlite3 {
_private: [u8; 0],
}

#[repr(C)]
pub(super) struct sqlite3_stmt {
_private: [u8; 0],
}

pub const SQLITE_OK: c_int = 0;
pub const SQLITE_NOTADB: c_int = 26;
pub const SQLITE_ROW: c_int = 100;
pub const SQLITE_OPEN_READWRITE: c_int = 2;
pub const SQLITE_OPEN_CREATE: c_int = 4;
pub(super) const SQLITE_OK: c_int = 0;
pub(super) const SQLITE_NOTADB: c_int = 26;
pub(super) const SQLITE_ROW: c_int = 100;
pub(super) const SQLITE_OPEN_READWRITE: c_int = 2;
pub(super) const SQLITE_OPEN_CREATE: c_int = 4;

type ExecCallback =
unsafe extern "C" fn(*mut c_void, c_int, *mut *mut c_char, *mut *mut c_char) -> c_int;

unsafe extern "C" {
pub fn sqlite3_open_v2(
pub(super) fn sqlite3_open_v2(
filename: *const c_char,
db: *mut *mut sqlite3,
flags: c_int,
vfs: *const c_char,
) -> c_int;
pub fn sqlite3_close(db: *mut sqlite3) -> c_int;
pub fn sqlite3_exec(
pub(super) fn sqlite3_close(db: *mut sqlite3) -> c_int;
pub(super) fn sqlite3_exec(
db: *mut sqlite3,
sql: *const c_char,
callback: Option<ExecCallback>,
arg: *mut c_void,
errmsg: *mut *mut c_char,
) -> c_int;
pub fn sqlite3_prepare_v2(
pub(super) fn sqlite3_prepare_v2(
db: *mut sqlite3,
sql: *const c_char,
bytes: c_int,
stmt: *mut *mut sqlite3_stmt,
tail: *mut *const c_char,
) -> c_int;
pub fn sqlite3_step(stmt: *mut sqlite3_stmt) -> c_int;
pub fn sqlite3_column_text(stmt: *mut sqlite3_stmt, column: c_int) -> *const c_uchar;
pub fn sqlite3_finalize(stmt: *mut sqlite3_stmt) -> c_int;
pub fn sqlite3_errmsg(db: *mut sqlite3) -> *const c_char;
pub(super) fn sqlite3_step(stmt: *mut sqlite3_stmt) -> c_int;
pub(super) fn sqlite3_column_text(stmt: *mut sqlite3_stmt, column: c_int)
-> *const c_uchar;
pub(super) fn sqlite3_finalize(stmt: *mut sqlite3_stmt) -> c_int;
pub(super) fn sqlite3_errmsg(db: *mut sqlite3) -> *const c_char;
}
}

Expand Down
13 changes: 10 additions & 3 deletions smoke/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ impl Db {
let mut handle = std::ptr::null_mut();
let flags = ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE;
// `c_name` outlives the call, and SQLite copies it.
let rc =
unsafe { ffi::sqlite3_open_v2(c_name.as_ptr(), &mut handle, flags, std::ptr::null()) };
let rc = unsafe {
ffi::sqlite3_open_v2(c_name.as_ptr(), &raw mut handle, flags, std::ptr::null())
};
let db = Self(handle, name.to_owned());
assert_eq!(rc, ffi::SQLITE_OK, "{name}: {}", db.error());
for pragma in pragmas {
Expand Down Expand Up @@ -80,7 +81,13 @@ impl Db {
let mut stmt = std::ptr::null_mut();
// `c_sql` outlives the call, which reads it up to its NUL.
let rc = unsafe {
ffi::sqlite3_prepare_v2(self.0, c_sql.as_ptr(), -1, &mut stmt, std::ptr::null_mut())
ffi::sqlite3_prepare_v2(
self.0,
c_sql.as_ptr(),
-1,
&raw mut stmt,
std::ptr::null_mut(),
)
};
assert_eq!(rc, ffi::SQLITE_OK, "{}: {sql}: {}", self.1, self.error());
// `stmt` was just prepared, and the text is copied before it is finalized.
Expand Down
Loading