change logger message format so it doesn't mutate the string

This commit is contained in:
koniifer 2024-10-20 12:11:29 +01:00
parent 41d9c0b82a
commit 2ba2dcb464
3 changed files with 11 additions and 8 deletions

View file

@ -9,12 +9,16 @@ use log::Record;
pub fn log_msg_handler(_vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
let msg_vec = block_read(mem_addr, length);
let log_level = msg_vec.last().unwrap();
let log_level = msg_vec[0];
let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap());
let strlen = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize;
let str = block_read(strptr, strlen);
let file_name = "None";
let line_number = 0;
match core::str::from_utf8(&msg_vec[..msg_vec.len() - 1]) {
match core::str::from_utf8(&str) {
Ok(strr) => {
use log::Level::*;
let log_level = match log_level {

View file

@ -1,10 +1,9 @@
string := @use("string.hb")
log := fn($Level: u8, message: ^u8): void {
message_length := @inline(string.length, message);
*(message + message_length) = Level
LogMsg := packed struct {level: u8, string: ^u8, strlen: uint}
return @eca(3, 1, message, message_length + 1)
log := fn($Level: u8, message: ^u8): void {
return @eca(3, 1, LogMsg.(Level, message, @inline(string.length, message)), @sizeof(LogMsg))
}
error := fn(message: ^u8): void return @inline(log, 0, message)

View file

@ -1,5 +1,5 @@
length := fn(ptr: ^u8): int {
len := 0
length := fn(ptr: ^u8): uint {
len := @as(uint, 0)
loop if *(ptr + len) == 0 break else len += 1
return len
}