Skip to content

Commit

Permalink
Remove unused codes and strange safety features (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Oct 13, 2024
1 parent c656a48 commit 11bf0b6
Show file tree
Hide file tree
Showing 28 changed files with 191 additions and 312 deletions.
11 changes: 4 additions & 7 deletions crates/lune-std-ffi/src/c/c_arr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
};
use crate::ffi::{
ffi_association::{get_association, set_association},
FfiBox, GetNativeDataHandle, NativeConvert, NativeDataHandle, NativeSize,
FfiBox, GetNativeData, NativeConvert, NativeData, NativeSize,
};

// This is a series of some type.
Expand Down Expand Up @@ -110,7 +110,7 @@ impl NativeConvert for CArr {
&self,
lua: &'lua Lua,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let LuaValue::Table(ref table) = value else {
Expand All @@ -134,7 +134,7 @@ impl NativeConvert for CArr {
&self,
lua: &'lua Lua,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let table = lua.create_table_with_capacity(self.length, 0)?;
for i in 0..self.length {
Expand Down Expand Up @@ -187,9 +187,6 @@ impl LuaUserData for CArr {
if !data_handle.check_boundary(offset, this.get_size()) {
return Err(LuaError::external("Out of bounds"));
}
if !data_handle.check_readable(offset, this.get_size()) {
return Err(LuaError::external("Unreadable data handle"));
}

unsafe { this.luavalue_from(lua, offset, data_handle) }
},
Expand All @@ -203,7 +200,7 @@ impl LuaUserData for CArr {
if !data_handle.check_boundary(offset, this.size) {
return Err(LuaError::external("Out of bounds"));
}
if !data_handle.checek_writable(offset, this.size) {
if !data_handle.is_writable() {
return Err(LuaError::external("Unwritable data handle"));
}

Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/c_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
};
use crate::ffi::{
ffi_association::{get_association, set_association},
FfiBox, GetNativeDataHandle, NativeConvert, NativeDataHandle, NativeSignedness, NativeSize,
FfiBox, GetNativeData, NativeConvert, NativeData, NativeSignedness, NativeSize,
FFI_STATUS_NAMES,
};

Expand Down Expand Up @@ -135,7 +135,7 @@ impl NativeConvert for CStruct {
&self,
lua: &'lua Lua,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let LuaValue::Table(ref table) = value else {
Expand All @@ -156,7 +156,7 @@ impl NativeConvert for CStruct {
&self,
lua: &'lua Lua,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let table = lua.create_table_with_capacity(self.conv.len(), 0)?;
for (i, conv) in self.conv.iter().enumerate() {
Expand Down
12 changes: 6 additions & 6 deletions crates/lune-std-ffi/src/c/c_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use num::cast::AsPrimitive;

use super::{association_names::CTYPE_STATIC, c_helper::get_ensured_size, CArr, CPtr};
use crate::ffi::{
ffi_association::set_association, native_num_cast, FfiBox, GetNativeDataHandle, NativeConvert,
NativeDataHandle, NativeSignedness, NativeSize,
ffi_association::set_association, native_num_cast, FfiBox, GetNativeData, NativeConvert,
NativeData, NativeSignedness, NativeSize,
};

// We can't get a CType<T> through mlua, something like
Expand Down Expand Up @@ -42,8 +42,8 @@ pub trait CTypeCast {
fn try_cast_num<T, U>(
&self,
ctype: &LuaAnyUserData,
from: &Ref<dyn NativeDataHandle>,
into: &Ref<dyn NativeDataHandle>,
from: &Ref<dyn NativeData>,
into: &Ref<dyn NativeData>,
) -> LuaResult<Option<()>>
where
T: AsPrimitive<U>,
Expand All @@ -62,8 +62,8 @@ pub trait CTypeCast {
&self,
from_ctype: &LuaAnyUserData,
into_ctype: &LuaAnyUserData,
_from: &Ref<dyn NativeDataHandle>,
_into: &Ref<dyn NativeDataHandle>,
_from: &Ref<dyn NativeData>,
_into: &Ref<dyn NativeData>,
) -> LuaResult<()> {
Err(Self::cast_failed_with(self, from_ctype, into_ctype))
}
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<f32> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<f32> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: f32 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<f32> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<f32>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<f64> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<f64> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: f64 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<f64> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<f64>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/i128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<i128> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<i128> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: i128 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<i128> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<i128>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<i16> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<i16> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: i16 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<i16> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<i16>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<i32> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<i32> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: i32 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<i32> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<i32>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<i64> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<i64> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: i64 = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<i64> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<i64>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<i8> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<i8> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: i8 = match value {
Expand All @@ -42,7 +42,7 @@ impl NativeConvert for CType<i8> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<i8>()).into_lua(lua)? };
Ok(value)
Expand Down
6 changes: 3 additions & 3 deletions crates/lune-std-ffi/src/c/types/isize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use num::cast::AsPrimitive;

use super::super::c_type::CType;
use crate::ffi::{NativeConvert, NativeDataHandle, NativeSignedness};
use crate::ffi::{NativeConvert, NativeData, NativeSignedness};

impl NativeSignedness for CType<isize> {
fn get_signedness(&self) -> bool {
Expand All @@ -19,7 +19,7 @@ impl NativeConvert for CType<isize> {
_lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
value: LuaValue<'lua>,
) -> LuaResult<()> {
let value: isize = match value {
Expand All @@ -46,7 +46,7 @@ impl NativeConvert for CType<isize> {
lua: &'lua Lua,
// _type_userdata: &LuaAnyUserData<'lua>,
offset: isize,
data_handle: &Ref<dyn NativeDataHandle>,
data_handle: &Ref<dyn NativeData>,
) -> LuaResult<LuaValue<'lua>> {
let value = unsafe { (*data_handle.get_pointer(offset).cast::<isize>()).into_lua(lua)? };
Ok(value)
Expand Down
Loading

0 comments on commit 11bf0b6

Please sign in to comment.