wip update to next servicepoint version

This commit is contained in:
Vinzenz Schroeter 2025-04-11 21:40:49 +02:00
commit 57d9e90b0f
13 changed files with 242 additions and 235 deletions

View file

@ -69,13 +69,15 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
height: usize,
data: *const u8,
data_length: usize,
) -> NonNull<SPCp437Grid> {
) -> *mut SPCp437Grid {
assert!(data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let result = Box::new(SPCp437Grid(servicepoint::Cp437Grid::load(
width, height, data,
)));
NonNull::from(Box::leak(result))
let data = unsafe{std::slice::from_raw_parts(data, data_length)};
let grid = servicepoint::Cp437Grid::load( width, height, data, );
if let Some(grid ) = grid {
Box::leak(Box::new(SPCp437Grid(grid)))
} else {
std::ptr::null_mut()
}
}
/// Clones a [SPCp437Grid].
@ -99,7 +101,7 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
cp437_grid: *const SPCp437Grid,
) -> NonNull<SPCp437Grid> {
assert!(!cp437_grid.is_null());
let result = Box::new((*cp437_grid).clone());
let result = Box::new(unsafe {(*cp437_grid).clone()});
NonNull::from(Box::leak(result))
}
@ -121,7 +123,7 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_free(cp437_grid: *mut SPCp437Grid) {
assert!(!cp437_grid.is_null());
_ = Box::from_raw(cp437_grid);
_ = unsafe {Box::from_raw(cp437_grid)};
}
/// Gets the current value at the specified position.
@ -149,7 +151,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
y: usize,
) -> u8 {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.get(x, y)
unsafe{(*cp437_grid).0.get(x, y)}
}
/// Sets the value of the specified position in the [SPCp437Grid].
@ -183,7 +185,7 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
value: u8,
) {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.set(x, y, value);
unsafe {(*cp437_grid).0.set(x, y, value)};
}
/// Sets the value of all cells in the [SPCp437Grid].
@ -209,7 +211,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
value: u8,
) {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.fill(value);
unsafe {(*cp437_grid).0.fill(value)};
}
/// Gets the width of the [SPCp437Grid] instance.
@ -232,7 +234,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
cp437_grid: *const SPCp437Grid,
) -> usize {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.width()
unsafe {(*cp437_grid).0.width()}
}
/// Gets the height of the [SPCp437Grid] instance.
@ -255,7 +257,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
cp437_grid: *const SPCp437Grid,
) -> usize {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.height()
unsafe {(*cp437_grid).0.height()}
}
/// Gets an unsafe reference to the data of the [SPCp437Grid] instance.
@ -277,7 +279,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
cp437_grid: *mut SPCp437Grid,
) -> SPByteSlice {
let data = (*cp437_grid).0.data_ref_mut();
let data = unsafe {(*cp437_grid).0.data_ref_mut()};
SPByteSlice {
start: NonNull::new(data.as_mut_ptr_range().start).unwrap(),
length: data.len(),