add heap_move_ok and heap_move_some helpers
This commit is contained in:
parent
0eedbf4a7f
commit
84adf166a9
9 changed files with 55 additions and 89 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, ByteSlice};
|
||||
use crate::{
|
||||
heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice,
|
||||
};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
|
|
@ -32,11 +34,7 @@ pub unsafe extern "C" fn sp_char_grid_load(
|
|||
data: ByteSlice,
|
||||
) -> *mut CharGrid {
|
||||
let data = unsafe { data.as_slice() };
|
||||
if let Ok(grid) = CharGrid::load_utf8(width, height, data.to_vec()) {
|
||||
heap_move(grid)
|
||||
} else {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
|
||||
}
|
||||
|
||||
/// Clones a [CharGrid].
|
||||
|
|
@ -145,11 +143,8 @@ pub unsafe extern "C" fn sp_char_grid_into_packet(
|
|||
y: usize,
|
||||
) -> *mut Packet {
|
||||
let grid = unsafe { heap_remove(grid) };
|
||||
match Packet::try_from(CharGridCommand {
|
||||
heap_move_ok(Packet::try_from(CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
}) {
|
||||
Ok(packet) => heap_move(packet),
|
||||
Err(_) => std::ptr::null_mut(),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue