#![allow(unsafe_code)]
use crate::hton::result::result_to_error;
use crate::panic_guard::FfiBoundary;
use crate::runtime;
use crate::runtime::FfiPtr;
use crate::sys;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_create(tablespace: *const sys::DdTablespace) -> bool {
FfiBoundary::run_default(true, || {
let ts = unsafe { tablespace.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_create(ts)),
None => true,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_drop(tablespace: *const sys::DdTablespace) -> bool {
FfiBoundary::run_default(true, || {
let ts = unsafe { tablespace.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_drop(ts)),
None => true,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_get_keys(
tablespace: *const sys::DdTablespace,
vector: *const sys::SdiVector,
) -> bool {
FfiBoundary::run_default(true, || {
let ts = unsafe { tablespace.as_ref() };
let vec_ref = unsafe { vector.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_get_keys(ts, vec_ref)),
None => true,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_get(
tablespace: *const sys::DdTablespace,
key: *const sys::SdiKey,
sdi: *mut u8,
sdi_capacity: u64,
len_out: *mut u64,
) -> bool {
FfiBoundary::run_default(true, || {
let cap = match usize::try_from(sdi_capacity) {
Ok(v) => v,
Err(_) => return true,
};
let buf: &mut [u8] = if sdi.is_null() {
&mut []
} else {
unsafe { FfiPtr::slice_mut(sdi, cap) }
};
let mut local = sdi_capacity;
let ts = unsafe { tablespace.as_ref() };
let key_ref = unsafe { key.as_ref() };
let err = match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_get(ts, key_ref, buf, &mut local)),
None => true,
};
if !len_out.is_null() {
unsafe { len_out.write(local) };
}
err
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_set(
tablespace: *const sys::DdTablespace,
table: *const sys::DdTable,
key: *const sys::SdiKey,
payload: *const u8,
payload_len: u64,
) -> bool {
FfiBoundary::run_default(true, || {
let len = match usize::try_from(payload_len) {
Ok(v) => v,
Err(_) => return true,
};
let bytes: &[u8] = if payload.is_null() {
&[]
} else {
unsafe { FfiPtr::slice_const(payload, len) }
};
let ts = unsafe { tablespace.as_ref() };
let tab = unsafe { table.as_ref() };
let key_ref = unsafe { key.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_set(ts, tab, key_ref, bytes)),
None => true,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__sdi_delete(
tablespace: *const sys::DdTablespace,
table: *const sys::DdTable,
key: *const sys::SdiKey,
) -> bool {
FfiBoundary::run_default(true, || {
let ts = unsafe { tablespace.as_ref() };
let tab = unsafe { table.as_ref() };
let key_ref = unsafe { key.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.sdi_delete(ts, tab, key_ref)),
None => true,
}
})
}