All internal library functions should be prefixed

This commit is contained in:
lumi 2025-06-28 06:03:12 +10:00
parent 27c40c3244
commit d9ef6c7806
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
3 changed files with 14 additions and 14 deletions

View File

@ -26,8 +26,8 @@ pub mod string;
// `ffi.keep(obj)`.
//
// https://github.com/LuaJIT/LuaJIT/issues/1167
pub(crate) const KEEP_FN: &str = "luaffi_keep";
#[unsafe(export_name = "luaffi_keep")]
pub(crate) const KEEP_FN: &str = "__lf_keep";
#[unsafe(export_name = "__lf_keep")]
extern "C" fn __keep(_ptr: *const c_void) {}
export![__keep];
@ -577,22 +577,22 @@ impl<'r, 'm> MetatypeFunctionBuilder<'r, 'm> {
if T::Into::ty() == TypeType::Void {
write!(lua, "__C.{func}({cargs}); {postlude}end").unwrap();
} else {
let check = T::postlude("__ret");
write!(lua, "local __ret = __C.{func}({cargs}); ").unwrap();
write!(lua, "{check}{postlude}return __ret; end").unwrap();
let check = T::postlude("ret");
write!(lua, "local ret = __C.{func}({cargs}); ").unwrap();
write!(lua, "{check}{postlude}return ret; end").unwrap();
}
writeln!(cdef, "{};", T::Into::cdecl(display!("{func}({cparams})"))).unwrap();
}
FfiReturnConvention::ByOutParam => {
let ct = T::Into::name();
let check = T::postlude("__out");
write!(lua, "local __out = __new(__ct.{ct}); __C.{func}(__out").unwrap();
let check = T::postlude("__ret");
write!(lua, "local __ret = __new(__ct.{ct}); __C.{func}(__ret").unwrap();
if !cargs.is_empty() {
write!(lua, ", {cargs}").unwrap();
}
write!(lua, "); {check}{postlude}return __out; end").unwrap();
write!(cdef, "void {func}({}", <*mut T::Into>::cdecl("out")).unwrap();
write!(lua, "); {check}{postlude}return __ret; end").unwrap();
write!(cdef, "void {func}({}", <*mut T::Into>::cdecl("__out")).unwrap();
if !cparams.is_empty() {
write!(cdef, ", {cparams}").unwrap();
}

View File

@ -6,16 +6,16 @@ use bstr::{BStr, BString};
use luaffi_impl::{cdef, metatype};
use std::{fmt::Display, mem::ManuallyDrop, slice};
pub(crate) const IS_UTF8_FN: &str = "luaffi_is_utf8";
pub(crate) const DROP_BUFFER_FN: &str = "luaffi_drop_buffer";
pub(crate) const IS_UTF8_FN: &str = "__lf_is_utf8";
pub(crate) const DROP_BUFFER_FN: &str = "__lf_drop_buffer";
#[unsafe(export_name = "luaffi_is_utf8")]
#[unsafe(export_name = "__lf_is_utf8")]
unsafe extern "C" fn __is_utf8(ptr: *const u8, len: usize) -> bool {
debug_assert!(!ptr.is_null());
simdutf8::basic::from_utf8(unsafe { slice::from_raw_parts(ptr, len) }).is_ok()
}
#[unsafe(export_name = "luaffi_drop_buffer")]
#[unsafe(export_name = "__lf_drop_buffer")]
unsafe extern "C" fn __drop_buffer(buf: *mut lua_buffer) {
debug_assert!(!buf.is_null());
debug_assert!(!unsafe { (*buf).__ptr.is_null() });

View File

@ -701,7 +701,7 @@ fn inject_merged_drop(registry: &mut Registry, lua: Option<&LuaFunction>) -> Res
let luaify = quote!(#ffi::__internal::luaify!);
let ty = &registry.ty;
let shim_name = format_ident!("__ffi_drop");
let c_name = format_ident!("{}_drop", ty.unraw());
let c_name = format_ident!("__{}_drop", ty.unraw());
let c_name_str = c_name.to_string();
if let Some(lua) = lua {