All internal library functions should be prefixed
This commit is contained in:
parent
27c40c3244
commit
d9ef6c7806
@ -26,8 +26,8 @@ pub mod string;
|
|||||||
// `ffi.keep(obj)`.
|
// `ffi.keep(obj)`.
|
||||||
//
|
//
|
||||||
// https://github.com/LuaJIT/LuaJIT/issues/1167
|
// https://github.com/LuaJIT/LuaJIT/issues/1167
|
||||||
pub(crate) const KEEP_FN: &str = "luaffi_keep";
|
pub(crate) const KEEP_FN: &str = "__lf_keep";
|
||||||
#[unsafe(export_name = "luaffi_keep")]
|
#[unsafe(export_name = "__lf_keep")]
|
||||||
extern "C" fn __keep(_ptr: *const c_void) {}
|
extern "C" fn __keep(_ptr: *const c_void) {}
|
||||||
export![__keep];
|
export![__keep];
|
||||||
|
|
||||||
@ -577,22 +577,22 @@ impl<'r, 'm> MetatypeFunctionBuilder<'r, 'm> {
|
|||||||
if T::Into::ty() == TypeType::Void {
|
if T::Into::ty() == TypeType::Void {
|
||||||
write!(lua, "__C.{func}({cargs}); {postlude}end").unwrap();
|
write!(lua, "__C.{func}({cargs}); {postlude}end").unwrap();
|
||||||
} else {
|
} else {
|
||||||
let check = T::postlude("__ret");
|
let check = T::postlude("ret");
|
||||||
write!(lua, "local __ret = __C.{func}({cargs}); ").unwrap();
|
write!(lua, "local ret = __C.{func}({cargs}); ").unwrap();
|
||||||
write!(lua, "{check}{postlude}return __ret; end").unwrap();
|
write!(lua, "{check}{postlude}return ret; end").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(cdef, "{};", T::Into::cdecl(display!("{func}({cparams})"))).unwrap();
|
writeln!(cdef, "{};", T::Into::cdecl(display!("{func}({cparams})"))).unwrap();
|
||||||
}
|
}
|
||||||
FfiReturnConvention::ByOutParam => {
|
FfiReturnConvention::ByOutParam => {
|
||||||
let ct = T::Into::name();
|
let ct = T::Into::name();
|
||||||
let check = T::postlude("__out");
|
let check = T::postlude("__ret");
|
||||||
write!(lua, "local __out = __new(__ct.{ct}); __C.{func}(__out").unwrap();
|
write!(lua, "local __ret = __new(__ct.{ct}); __C.{func}(__ret").unwrap();
|
||||||
if !cargs.is_empty() {
|
if !cargs.is_empty() {
|
||||||
write!(lua, ", {cargs}").unwrap();
|
write!(lua, ", {cargs}").unwrap();
|
||||||
}
|
}
|
||||||
write!(lua, "); {check}{postlude}return __out; end").unwrap();
|
write!(lua, "); {check}{postlude}return __ret; end").unwrap();
|
||||||
write!(cdef, "void {func}({}", <*mut T::Into>::cdecl("out")).unwrap();
|
write!(cdef, "void {func}({}", <*mut T::Into>::cdecl("__out")).unwrap();
|
||||||
if !cparams.is_empty() {
|
if !cparams.is_empty() {
|
||||||
write!(cdef, ", {cparams}").unwrap();
|
write!(cdef, ", {cparams}").unwrap();
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,16 @@ use bstr::{BStr, BString};
|
|||||||
use luaffi_impl::{cdef, metatype};
|
use luaffi_impl::{cdef, metatype};
|
||||||
use std::{fmt::Display, mem::ManuallyDrop, slice};
|
use std::{fmt::Display, mem::ManuallyDrop, slice};
|
||||||
|
|
||||||
pub(crate) const IS_UTF8_FN: &str = "luaffi_is_utf8";
|
pub(crate) const IS_UTF8_FN: &str = "__lf_is_utf8";
|
||||||
pub(crate) const DROP_BUFFER_FN: &str = "luaffi_drop_buffer";
|
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 {
|
unsafe extern "C" fn __is_utf8(ptr: *const u8, len: usize) -> bool {
|
||||||
debug_assert!(!ptr.is_null());
|
debug_assert!(!ptr.is_null());
|
||||||
simdutf8::basic::from_utf8(unsafe { slice::from_raw_parts(ptr, len) }).is_ok()
|
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) {
|
unsafe extern "C" fn __drop_buffer(buf: *mut lua_buffer) {
|
||||||
debug_assert!(!buf.is_null());
|
debug_assert!(!buf.is_null());
|
||||||
debug_assert!(!unsafe { (*buf).__ptr.is_null() });
|
debug_assert!(!unsafe { (*buf).__ptr.is_null() });
|
||||||
|
@ -701,7 +701,7 @@ fn inject_merged_drop(registry: &mut Registry, lua: Option<&LuaFunction>) -> Res
|
|||||||
let luaify = quote!(#ffi::__internal::luaify!);
|
let luaify = quote!(#ffi::__internal::luaify!);
|
||||||
let ty = ®istry.ty;
|
let ty = ®istry.ty;
|
||||||
let shim_name = format_ident!("__ffi_drop");
|
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();
|
let c_name_str = c_name.to_string();
|
||||||
|
|
||||||
if let Some(lua) = lua {
|
if let Some(lua) = lua {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user