#![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;
fn write_empty_string_view(out_ptr: *mut *const u8, out_len: *mut usize) {
if !out_ptr.is_null() {
unsafe { out_ptr.write(core::ptr::null()) };
}
if !out_len.is_null() {
unsafe { out_len.write(0) };
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__get_secondary_engine_offload_or_exec_fail_reason(
_thd: *const sys::THD,
out_ptr: *mut *const u8,
out_len: *mut usize,
) -> bool {
FfiBoundary::run_default(false, || {
write_empty_string_view(out_ptr, out_len);
true
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__find_secondary_engine_offload_fail_reason(
_thd: *const sys::THD,
out_ptr: *mut *const u8,
out_len: *mut usize,
) -> bool {
FfiBoundary::run_default(false, || {
write_empty_string_view(out_ptr, out_len);
true
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__set_secondary_engine_offload_fail_reason(
thd: *const sys::THD,
reason: *const u8,
reason_len: usize,
) -> bool {
FfiBoundary::run_default(true, || {
let thd_ref = unsafe { thd.as_ref() };
let reason_str = if reason.is_null() {
""
} else {
match unsafe { FfiPtr::bytes_to_str(reason, reason_len) } {
Ok(s) => s,
Err(_) => return true,
}
};
match runtime::handlerton() {
Some(h) => {
result_to_error(h.set_secondary_engine_offload_fail_reason(thd_ref, reason_str))
}
None => false,
}
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn write_empty_string_view_writes_null_and_zero() {
let mut p: *const u8 = std::ptr::dangling::<u8>();
let mut l: usize = 7;
write_empty_string_view(&raw mut p, &raw mut l);
assert!(p.is_null());
assert_eq!(l, 0);
}
#[test]
fn write_empty_string_view_tolerates_null_outs() {
write_empty_string_view(core::ptr::null_mut(), core::ptr::null_mut());
}
}