mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
Add free test (#243)
This commit is contained in:
parent
c45773770a
commit
809fd566a1
8 changed files with 28 additions and 3 deletions
|
@ -24,7 +24,6 @@ See [tests/ffi](../../tests/ffi/README.md)
|
||||||
|
|
||||||
- Add varargs support
|
- Add varargs support
|
||||||
- Array argument in cfn
|
- Array argument in cfn
|
||||||
- Ref boundary fix
|
|
||||||
|
|
||||||
## Code structure
|
## Code structure
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ Define C-ABI type information and provide conversion and casting
|
||||||
- [**Struct ` CArrInfo`:**](./src/c/struct_info.rs) Represents C Array type
|
- [**Struct ` CArrInfo`:**](./src/c/struct_info.rs) Represents C Array type
|
||||||
- [**Struct ` CPtrInfo`:**](./src/c/ptr_info.rs) Represents C Pointer type
|
- [**Struct ` CPtrInfo`:**](./src/c/ptr_info.rs) Represents C Pointer type
|
||||||
- [**Struct ` CFnInfo`:**](./src/c/fn_info.rs) Represents C Function signature
|
- [**Struct ` CFnInfo`:**](./src/c/fn_info.rs) Represents C Function signature
|
||||||
> provide CallableData and ClosureData creation
|
> provide `CallableData` and `ClosureData` creator
|
||||||
- [**Struct ` CStructInfo`:**](./src/c/struct_info.rs) Represents C Struct type
|
- [**Struct ` CStructInfo`:**](./src/c/struct_info.rs) Represents C Struct type
|
||||||
- [**Struct ` CTypeInfo<T>`:**](./src/c/type_info.rs) Represents C type, extended in `/c/types`
|
- [**Struct ` CTypeInfo<T>`:**](./src/c/type_info.rs) Represents C type, extended in `/c/types`
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ impl FfiSize for CArrInfo {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiConvert for CArrInfo {
|
impl FfiConvert for CArrInfo {
|
||||||
unsafe fn value_into_data<'lua>(
|
unsafe fn value_into_data<'lua>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -43,6 +43,7 @@ impl FfiSignedness for CFnInfo {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiSize for CFnInfo {
|
impl FfiSize for CFnInfo {
|
||||||
fn get_size(&self) -> usize {
|
fn get_size(&self) -> usize {
|
||||||
SIZE_OF_POINTER
|
SIZE_OF_POINTER
|
||||||
|
|
|
@ -25,11 +25,13 @@ impl FfiSignedness for CPtrInfo {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiSize for CPtrInfo {
|
impl FfiSize for CPtrInfo {
|
||||||
fn get_size(&self) -> usize {
|
fn get_size(&self) -> usize {
|
||||||
SIZE_OF_POINTER
|
SIZE_OF_POINTER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiConvert for CPtrInfo {
|
impl FfiConvert for CPtrInfo {
|
||||||
// Convert luavalue into data, then write into ptr
|
// Convert luavalue into data, then write into ptr
|
||||||
unsafe fn value_into_data<'lua>(
|
unsafe fn value_into_data<'lua>(
|
||||||
|
|
|
@ -116,11 +116,13 @@ impl FfiSize for CStructInfo {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiSignedness for CStructInfo {
|
impl FfiSignedness for CStructInfo {
|
||||||
fn get_signedness(&self) -> bool {
|
fn get_signedness(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiConvert for CStructInfo {
|
impl FfiConvert for CStructInfo {
|
||||||
unsafe fn value_into_data<'lua>(
|
unsafe fn value_into_data<'lua>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -12,6 +12,7 @@ impl FfiSignedness for CVoidInfo {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FfiSize for CVoidInfo {
|
impl FfiSize for CVoidInfo {
|
||||||
fn get_size(&self) -> usize {
|
fn get_size(&self) -> usize {
|
||||||
0
|
0
|
||||||
|
|
|
@ -31,7 +31,7 @@ macro_rules! create_tests {
|
||||||
// The rest of the test logic can continue as normal
|
// The rest of the test logic can continue as normal
|
||||||
let full_name = format!("{}/tests/{}.luau", workspace_dir.display(), $value);
|
let full_name = format!("{}/tests/{}.luau", workspace_dir.display(), $value);
|
||||||
let script = read_to_string(&full_name).await?;
|
let script = read_to_string(&full_name).await?;
|
||||||
let mut lune = Runtime::new().with_args(
|
let mut lune = Runtime::new().set_unsafe_library_enabled(true).with_args(
|
||||||
ARGS
|
ARGS
|
||||||
.clone()
|
.clone()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -111,6 +111,7 @@ create_tests! {
|
||||||
ffi_external_print_hello_world: "ffi/external_print/helloWorld",
|
ffi_external_print_hello_world: "ffi/external_print/helloWorld",
|
||||||
ffi_external_struct_ab: "ffi/external_struct/ab",
|
ffi_external_struct_ab: "ffi/external_struct/ab",
|
||||||
ffi_cast: "ffi/cast",
|
ffi_cast: "ffi/cast",
|
||||||
|
ffi_free: "ffi/free",
|
||||||
ffi_is_integer: "ffi/isInteger",
|
ffi_is_integer: "ffi/isInteger",
|
||||||
ffi_pretty_print: "ffi/prettyPrint",
|
ffi_pretty_print: "ffi/prettyPrint",
|
||||||
ffi_read_boundary: "ffi/readBoundary",
|
ffi_read_boundary: "ffi/readBoundary",
|
||||||
|
|
18
tests/ffi/free.luau
Normal file
18
tests/ffi/free.luau
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
--!nocheck
|
||||||
|
--!nolint
|
||||||
|
local ffi = require("@lune/ffi")
|
||||||
|
|
||||||
|
local box = ffi.box(ffi.i32.size)
|
||||||
|
local ref = box:leak()
|
||||||
|
|
||||||
|
box = nil
|
||||||
|
|
||||||
|
collectgarbage("collect")
|
||||||
|
collectgarbage("collect")
|
||||||
|
collectgarbage("collect")
|
||||||
|
|
||||||
|
ffi.free(ref)
|
||||||
|
|
||||||
|
collectgarbage("collect")
|
||||||
|
collectgarbage("collect")
|
||||||
|
collectgarbage("collect")
|
Loading…
Add table
Reference in a new issue