#![allow(unsafe_code)]
use crate::engine::EngineError;
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__discover(
thd: *const sys::THD,
db: *const u8,
db_len: usize,
name: *const u8,
name_len: usize,
) -> i32 {
FfiBoundary::run(|| {
let db_str = match unsafe { FfiPtr::bytes_to_str(db, db_len) } {
Ok(s) => s,
Err(e) => return Err(e),
};
let name_str = match unsafe { FfiPtr::bytes_to_str(name, name_len) } {
Ok(s) => s,
Err(e) => return Err(e),
};
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.discover(thd_ref, db_str, name_str),
None => Err(EngineError::Unsupported),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__find_files(
thd: *const sys::THD,
db: *const u8,
db_len: usize,
path: *const u8,
path_len: usize,
wild: *const u8,
wild_len: usize,
dir: bool,
) -> i32 {
FfiBoundary::run(|| {
let db_str = match unsafe { FfiPtr::bytes_to_str(db, db_len) } {
Ok(s) => s,
Err(e) => return Err(e),
};
let path_str = match unsafe { FfiPtr::bytes_to_str(path, path_len) } {
Ok(s) => s,
Err(e) => return Err(e),
};
let wild_str = if wild.is_null() {
None
} else {
match unsafe { FfiPtr::bytes_to_str(wild, wild_len) } {
Ok(s) => Some(s),
Err(e) => return Err(e),
}
};
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.find_files(thd_ref, db_str, path_str, wild_str, dir),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__table_exists_in_engine(
thd: *const sys::THD,
db: *const u8,
db_len: usize,
name: *const u8,
name_len: usize,
) -> bool {
FfiBoundary::run_default(false, || {
let db_str = match unsafe { FfiPtr::bytes_to_str(db, db_len) } {
Ok(s) => s,
Err(_) => return false,
};
let name_str = match unsafe { FfiPtr::bytes_to_str(name, name_len) } {
Ok(s) => s,
Err(_) => return false,
};
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.table_exists_in_engine(thd_ref, db_str, name_str),
None => false,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__is_supported_system_table(
db: *const u8,
db_len: usize,
name: *const u8,
name_len: usize,
is_sql_layer_system_table: bool,
) -> bool {
FfiBoundary::run_default(false, || {
let db_str = match unsafe { FfiPtr::bytes_to_str(db, db_len) } {
Ok(s) => s,
Err(_) => return false,
};
let name_str = match unsafe { FfiPtr::bytes_to_str(name, name_len) } {
Ok(s) => s,
Err(_) => return false,
};
match runtime::handlerton() {
Some(h) => h.is_supported_system_table(db_str, name_str, is_sql_layer_system_table),
None => false,
}
})
}