refactor: Change to Rust's CStr
This commit is contained in:
1 parent
78f050e20c
commit
21c90abd44
9 files changed
+41
-54
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
use crate::sys;
|
||||
use cstr_core::CStr;
|
||||
use core::ffi::CStr;
|
||||
|
||||
mod console;
|
||||
pub use console::Console;
|
||||
|
||||
+5
-8
@@ -1,7 +1,6 @@
|
||||
use crate::dll::DLL;
|
||||
use core::ffi::CStr;
|
||||
use core::mem::transmute;
|
||||
use cstr_core::cstr;
|
||||
use cstr_core::CStr;
|
||||
|
||||
pub struct Console {
|
||||
con_init: extern "stdcall" fn(u32, u32, u32, u32, *const u8),
|
||||
@@ -11,16 +10,14 @@ pub struct Console {
|
||||
|
||||
impl Console {
|
||||
pub fn import(path: Option<&CStr>) -> Result<Self, &str> {
|
||||
let lib = DLL::load_dll(path.unwrap_or(cstr!("/sys/lib/console.obj")));
|
||||
let lib = DLL::load_dll(path.unwrap_or(c"/sys/lib/console.obj"));
|
||||
match lib {
|
||||
Err(e) => return Err(e),
|
||||
Ok(dll) => unsafe {
|
||||
Ok(Console {
|
||||
con_init: transmute(dll.get_func(cstr!("con_init")).ok().unwrap()),
|
||||
con_write_string: transmute(
|
||||
dll.get_func(cstr!("con_write_string")).ok().unwrap(),
|
||||
),
|
||||
con_exit: transmute(dll.get_func(cstr!("con_exit")).ok().unwrap()),
|
||||
con_init: transmute(dll.get_func(c"con_init").ok().unwrap()),
|
||||
con_write_string: transmute(dll.get_func(c"con_write_string").ok().unwrap()),
|
||||
con_exit: transmute(dll.get_func(c"con_exit").ok().unwrap()),
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sys;
|
||||
use cstr_core::CStr;
|
||||
use core::ffi::CStr;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Color(u8, u8, u8);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::sys;
|
||||
use crate::throw_new;
|
||||
use alloc::string::String;
|
||||
use cstr_core::CStr;
|
||||
use core::ffi::CStr;
|
||||
|
||||
trait Debuggable {
|
||||
fn data_iter(self) -> impl Iterator<Item = u8>;
|
||||
|
||||
+10
-11
@@ -2,7 +2,8 @@ use crate::graphics::{Color, Dot, Size};
|
||||
use crate::sys;
|
||||
use crate::system::debug_write;
|
||||
use crate::throw_new;
|
||||
use cstr_core::{cstr, CStr};
|
||||
use alloc::ffi::CString;
|
||||
use core::ffi::CStr;
|
||||
|
||||
#[repr(u32)]
|
||||
pub enum WindowKind {
|
||||
@@ -16,12 +17,12 @@ pub enum WindowKind {
|
||||
pub struct WindowParams<'a> {
|
||||
pub color: Color,
|
||||
pub kind: WindowKind,
|
||||
pub title: Option<&'a cstr_core::CStr>,
|
||||
pub title: Option<&'a CStr>,
|
||||
}
|
||||
|
||||
pub const CLOSE_BUTTON: u32 = 1;
|
||||
|
||||
pub fn define_window(start: Dot, size: Size, params: WindowParams<'_>) {
|
||||
pub fn define_window(start: Dot, size: Size, params: WindowParams) {
|
||||
const RELATIVE_FLAG: u32 = 0x20;
|
||||
|
||||
unsafe {
|
||||
@@ -60,14 +61,12 @@ pub fn define_button(
|
||||
crate::graphics::display_message(
|
||||
Dot { x: 10, y: 200 },
|
||||
Color::rgb(255, 0, 0),
|
||||
CStr::from_bytes_with_nul(
|
||||
format!(
|
||||
"x:{:?} y:{:?} w:{:?} h:{:?}\n\0",
|
||||
start.x, start.y, size.width, size.height
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap_or(cstr!("String error")),
|
||||
CString::new(format!(
|
||||
"x:{:?} y:{:?} w:{:?} h:{:?}\n",
|
||||
start.x, start.y, size.width, size.height
|
||||
))
|
||||
.expect("CString error")
|
||||
.as_c_str(),
|
||||
None,
|
||||
);
|
||||
throw_new!(format!(
|
||||
|
||||
Reference in new issue
Block a user