mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 03:04:20 +01:00
add missing method to add builtin vfs to ext api
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1043,10 +1043,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi 0.13.3+wasi-0.2.2",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
@@ -1713,7 +1711,7 @@ name = "limbo_ext"
|
||||
version = "0.0.16"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"getrandom 0.3.1",
|
||||
"getrandom 0.2.15",
|
||||
"limbo_macros",
|
||||
]
|
||||
|
||||
|
||||
@@ -13,5 +13,5 @@ static = []
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.40"
|
||||
getrandom = { version = "0.3.1", features = ["wasm_js"] }
|
||||
getrandom = { version = "0.2.15", features = ["js"] }
|
||||
limbo_macros = { workspace = true }
|
||||
|
||||
@@ -29,6 +29,26 @@ pub struct ExtensionApiRef {
|
||||
pub api: *const ExtensionApi,
|
||||
}
|
||||
|
||||
impl ExtensionApi {
|
||||
/// Since we want the option to build in extensions at compile time as well,
|
||||
/// we add a slice of VfsImpls to the extension API, and this is called with any
|
||||
/// libraries that we load staticly that will add their VFS implementations to the list.
|
||||
pub fn add_builtin_vfs(&mut self, vfs: *const VfsImpl) -> ResultCode {
|
||||
if vfs.is_null() || self.builtin_vfs.is_null() {
|
||||
return ResultCode::Error;
|
||||
}
|
||||
let mut new = unsafe {
|
||||
let slice =
|
||||
std::slice::from_raw_parts_mut(self.builtin_vfs, self.builtin_vfs_count as usize);
|
||||
Vec::from(slice)
|
||||
};
|
||||
new.push(vfs);
|
||||
self.builtin_vfs = Box::into_raw(new.into_boxed_slice()) as *mut *const VfsImpl;
|
||||
self.builtin_vfs_count += 1;
|
||||
ResultCode::OK
|
||||
}
|
||||
}
|
||||
|
||||
pub type ExtensionEntryPoint = unsafe extern "C" fn(api: *const ExtensionApi) -> ResultCode;
|
||||
|
||||
pub type ScalarFunction = unsafe extern "C" fn(argc: i32, *const Value) -> Value;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub trait VfsExtension: Default + Send + Sync {
|
||||
}
|
||||
fn generate_random_number(&self) -> i64 {
|
||||
let mut buf = [0u8; 8];
|
||||
getrandom::fill(&mut buf).unwrap();
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
fn get_current_time(&self) -> String {
|
||||
|
||||
Reference in New Issue
Block a user