Skip to content

Commit 54fbc95

Browse files
committed
fix(libsql-sys): support non-Unix when rusqlite feature is disabled
Currently the codepath used when rusqlite is disabled, is Unix-platform-dependent. This patch is adding a platform-independant branch.
1 parent 9b04f1d commit 54fbc95

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

libsql-sys/src/connection.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,22 @@ impl<W: Wal> Connection<W> {
273273

274274
#[cfg(not(feature = "rusqlite"))]
275275
let conn = unsafe {
276-
use std::os::unix::ffi::OsStrExt;
277-
let path = std::ffi::CString::new(path.as_ref().as_os_str().as_bytes())
278-
.map_err(|_| crate::error::Error::Bug("invalid database path"))?;
276+
#[cfg(unix)]
277+
let path = {
278+
use std::os::unix::ffi::OsStrExt;
279+
std::ffi::CString::new(path.as_ref().as_os_str().as_bytes())
280+
.map_err(|_| crate::error::Error::Bug("invalid database path"))
281+
};
282+
#[cfg(not(unix))]
283+
let path = path
284+
.to_str()
285+
.ok_or_else(|| crate::error::Error::Bug("datbase path is not valid unicode"))
286+
.and_then(|x| {
287+
std::ffi::CString::new(x).map_err(|_| {
288+
crate::error::Error::Bug("invalid database contains an internal nul byte")
289+
})
290+
})?;
291+
279292
let mut conn: *mut crate::ffi::sqlite3 = std::ptr::null_mut();
280293
// We pass a pointer to the WAL methods data to the database connection. This means
281294
// that the reference must outlive the connection. This is guaranteed by the marker in

0 commit comments

Comments
 (0)