replace usages of 'this' as parameter name
This commit is contained in:
parent
3e3a933ecb
commit
e46391ca5f
9 changed files with 506 additions and 427 deletions
|
@ -81,15 +81,15 @@ pub unsafe extern "C" fn sp_bit_vec_load(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` is not written to concurrently
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_bit_vec_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_clone(
|
||||
this: *const SPBitVec,
|
||||
bit_vec: *const SPBitVec,
|
||||
) -> *mut SPBitVec {
|
||||
Box::into_raw(Box::new((*this).clone()))
|
||||
Box::into_raw(Box::new((*bit_vec).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `SPBitVec`.
|
||||
|
@ -98,19 +98,19 @@ pub unsafe extern "C" fn sp_bit_vec_clone(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` is not used concurrently or after this call
|
||||
/// - `bit_vec` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_free(this: *mut SPBitVec) {
|
||||
_ = Box::from_raw(this);
|
||||
pub unsafe extern "C" fn sp_bit_vec_free(bit_vec: *mut SPBitVec) {
|
||||
_ = Box::from_raw(bit_vec);
|
||||
}
|
||||
|
||||
/// Gets the value of a bit from the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `bit_vec`: instance to read from
|
||||
/// - `index`: the bit index to read
|
||||
///
|
||||
/// returns: value of the bit
|
||||
|
@ -123,21 +123,21 @@ pub unsafe extern "C" fn sp_bit_vec_free(this: *mut SPBitVec) {
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` is not written to concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_get(
|
||||
this: *const SPBitVec,
|
||||
bit_vec: *const SPBitVec,
|
||||
index: usize,
|
||||
) -> bool {
|
||||
*(*this).0.get(index).unwrap()
|
||||
*(*bit_vec).0.get(index).unwrap()
|
||||
}
|
||||
|
||||
/// Sets the value of a bit in the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `bit_vec`: instance to write to
|
||||
/// - `index`: the bit index to edit
|
||||
/// - `value`: the value to set the bit to
|
||||
///
|
||||
|
@ -151,72 +151,85 @@ pub unsafe extern "C" fn sp_bit_vec_get(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_set(
|
||||
this: *mut SPBitVec,
|
||||
bit_vec: *mut SPBitVec,
|
||||
index: usize,
|
||||
value: bool,
|
||||
) {
|
||||
(*this).0.set(index, value)
|
||||
(*bit_vec).0.set(index, value)
|
||||
}
|
||||
|
||||
/// Sets the value of all bits in the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
/// - `value`: the value to set all bits to
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_fill(this: *mut SPBitVec, value: bool) {
|
||||
(*this).0.fill(value)
|
||||
pub unsafe extern "C" fn sp_bit_vec_fill(bit_vec: *mut SPBitVec, value: bool) {
|
||||
(*bit_vec).0.fill(value)
|
||||
}
|
||||
|
||||
/// Gets the length of the `SPBitVec` in bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_len(this: *const SPBitVec) -> usize {
|
||||
(*this).0.len()
|
||||
pub unsafe extern "C" fn sp_bit_vec_len(bit_vec: *const SPBitVec) -> usize {
|
||||
(*bit_vec).0.len()
|
||||
}
|
||||
|
||||
/// Returns true if length is 0.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_is_empty(this: *const SPBitVec) -> bool {
|
||||
(*this).0.is_empty()
|
||||
pub unsafe extern "C" fn sp_bit_vec_is_empty(bit_vec: *const SPBitVec) -> bool {
|
||||
(*bit_vec).0.is_empty()
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the `SPBitVec` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
///
|
||||
/// ## Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `bit_vec` points to a valid `SPBitVec`
|
||||
/// - the returned memory range is never accessed after the passed `SPBitVec` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `SPBitVec` or directly
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_unsafe_data_ref(
|
||||
this: *mut SPBitVec,
|
||||
bit_vec: *mut SPBitVec,
|
||||
) -> SPByteSlice {
|
||||
let data = (*this).0.as_raw_mut_slice();
|
||||
let data = (*bit_vec).0.as_raw_mut_slice();
|
||||
SPByteSlice {
|
||||
start: data.as_mut_ptr_range().start,
|
||||
length: data.len(),
|
||||
|
|
|
@ -21,15 +21,11 @@ use std::intrinsics::transmute;
|
|||
/// SPCommand command = sp_command_char_brightness(grid);
|
||||
/// sp_connection_free(connection);
|
||||
/// ```
|
||||
pub struct SPBrightnessGrid {
|
||||
pub(crate) actual: servicepoint::BrightnessGrid,
|
||||
}
|
||||
pub struct SPBrightnessGrid(pub(crate) servicepoint::BrightnessGrid);
|
||||
|
||||
impl Clone for SPBrightnessGrid {
|
||||
fn clone(&self) -> Self {
|
||||
SPBrightnessGrid {
|
||||
actual: self.actual.clone(),
|
||||
}
|
||||
SPBrightnessGrid(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,9 +44,9 @@ pub unsafe extern "C" fn sp_brightness_grid_new(
|
|||
width: usize,
|
||||
height: usize,
|
||||
) -> *mut SPBrightnessGrid {
|
||||
Box::into_raw(Box::new(SPBrightnessGrid {
|
||||
actual: servicepoint::BrightnessGrid::new(width, height),
|
||||
}))
|
||||
Box::into_raw(Box::new(SPBrightnessGrid(
|
||||
servicepoint::BrightnessGrid::new(width, height),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Loads a `SPBrightnessGrid` with the specified dimensions from the provided data.
|
||||
|
@ -78,47 +74,55 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
|||
let grid = PrimitiveGrid::load(width, height, data);
|
||||
let grid = servicepoint::BrightnessGrid::try_from(grid)
|
||||
.expect("invalid brightness value");
|
||||
Box::into_raw(Box::new(SPBrightnessGrid { actual: grid }))
|
||||
Box::into_raw(Box::new(SPBrightnessGrid(grid)))
|
||||
}
|
||||
|
||||
/// Clones a `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` is not written to concurrently
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_brightness_grid_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_clone(
|
||||
this: *const SPBrightnessGrid,
|
||||
brightness_grid: *const SPBrightnessGrid,
|
||||
) -> *mut SPBrightnessGrid {
|
||||
Box::into_raw(Box::new((*this).clone()))
|
||||
Box::into_raw(Box::new((*brightness_grid).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` is not used concurrently or after this call
|
||||
/// - `brightness_grid` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_free(
|
||||
this: *mut SPBrightnessGrid,
|
||||
brightness_grid: *mut SPBrightnessGrid,
|
||||
) {
|
||||
_ = Box::from_raw(this);
|
||||
_ = Box::from_raw(brightness_grid);
|
||||
}
|
||||
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `brightness_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -129,22 +133,22 @@ pub unsafe extern "C" fn sp_brightness_grid_free(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` is not written to concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_get(
|
||||
this: *const SPBrightnessGrid,
|
||||
brightness_grid: *const SPBrightnessGrid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> u8 {
|
||||
(*this).actual.get(x, y).into()
|
||||
(*brightness_grid).0.get(x, y).into()
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `brightness_grid`: instance to write to
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
|
@ -159,25 +163,25 @@ pub unsafe extern "C" fn sp_brightness_grid_get(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `brightness_grid` points to a valid `SPBitVec`
|
||||
/// - `brightness_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_set(
|
||||
this: *mut SPBrightnessGrid,
|
||||
brightness_grid: *mut SPBrightnessGrid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: u8,
|
||||
) {
|
||||
let brightness =
|
||||
Brightness::try_from(value).expect("invalid brightness value");
|
||||
(*this).actual.set(x, y, brightness);
|
||||
(*brightness_grid).0.set(x, y, brightness);
|
||||
}
|
||||
|
||||
/// Sets the value of all cells in the `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `brightness_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -188,70 +192,74 @@ pub unsafe extern "C" fn sp_brightness_grid_set(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_fill(
|
||||
this: *mut SPBrightnessGrid,
|
||||
brightness_grid: *mut SPBrightnessGrid,
|
||||
value: u8,
|
||||
) {
|
||||
let brightness =
|
||||
Brightness::try_from(value).expect("invalid brightness value");
|
||||
(*this).actual.fill(brightness);
|
||||
(*brightness_grid).0.fill(brightness);
|
||||
}
|
||||
|
||||
/// Gets the width of the `SPBrightnessGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_width(
|
||||
this: *const SPBrightnessGrid,
|
||||
brightness_grid: *const SPBrightnessGrid,
|
||||
) -> usize {
|
||||
(*this).actual.width()
|
||||
(*brightness_grid).0.width()
|
||||
}
|
||||
|
||||
/// Gets the height of the `SPBrightnessGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_height(
|
||||
this: *const SPBrightnessGrid,
|
||||
brightness_grid: *const SPBrightnessGrid,
|
||||
) -> usize {
|
||||
(*this).actual.height()
|
||||
(*brightness_grid).0.height()
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the `SPBrightnessGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// ## Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
/// - `brightness_grid` points to a valid `SPBrightnessGrid`
|
||||
/// - the returned memory range is never accessed after the passed `SPBrightnessGrid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `SPBrightnessGrid` or directly
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref(
|
||||
this: *mut SPBrightnessGrid,
|
||||
brightness_grid: *mut SPBrightnessGrid,
|
||||
) -> SPByteSlice {
|
||||
assert_eq!(std::mem::size_of::<Brightness>(), 1);
|
||||
assert_eq!(core::mem::size_of::<Brightness>(), 1);
|
||||
|
||||
let data = (*this).actual.data_ref_mut();
|
||||
let data = (*brightness_grid).0.data_ref_mut();
|
||||
let data: &mut [u8] = transmute(data);
|
||||
SPByteSlice {
|
||||
start: data.as_mut_ptr_range().start,
|
||||
|
|
|
@ -63,15 +63,15 @@ pub unsafe extern "C" fn sp_command_try_from_packet(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid instance of `SPCommand`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `command` points to a valid instance of `SPCommand`
|
||||
/// - `command` is not written to concurrently
|
||||
/// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_command_clone(
|
||||
original: *const SPCommand,
|
||||
command: *const SPCommand,
|
||||
) -> *mut SPCommand {
|
||||
Box::into_raw(Box::new((*original).clone()))
|
||||
Box::into_raw(Box::new((*command).clone()))
|
||||
}
|
||||
|
||||
/// Set all pixels to the off state.
|
||||
|
@ -177,7 +177,7 @@ pub unsafe extern "C" fn sp_command_char_brightness(
|
|||
let byte_grid = *Box::from_raw(grid);
|
||||
Box::into_raw(Box::new(SPCommand(servicepoint::Command::CharBrightness(
|
||||
Origin::new(x, y),
|
||||
byte_grid.actual,
|
||||
byte_grid.0,
|
||||
))))
|
||||
}
|
||||
|
||||
|
@ -394,10 +394,10 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCommand`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `this` was not passed to another consuming function, e.g. to create a `SPPacket`
|
||||
/// - `command` points to a valid `SPCommand`
|
||||
/// - `command` is not used concurrently or after this call
|
||||
/// - `command` was not passed to another consuming function, e.g. to create a `SPPacket`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_command_free(ptr: *mut SPCommand) {
|
||||
_ = Box::from_raw(ptr);
|
||||
pub unsafe extern "C" fn sp_command_free(command: *mut SPCommand) {
|
||||
_ = Box::from_raw(command);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub unsafe extern "C" fn sp_connection_open(
|
|||
|
||||
/// Sends a `SPPacket` to the display using the `SPConnection`.
|
||||
///
|
||||
/// The passed `SPPacket` gets consumed.
|
||||
/// The passed `packet` gets consumed.
|
||||
///
|
||||
/// returns: true in case of success
|
||||
///
|
||||
|
@ -55,9 +55,9 @@ pub unsafe extern "C" fn sp_connection_open(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `SPConnection` points to a valid instance of `SPConnection`
|
||||
/// - `SPPacket` points to a valid instance of `SPPacket`
|
||||
/// - `SPPacket` is not used concurrently or after this call
|
||||
/// - `connection` points to a valid instance of `SPConnection`
|
||||
/// - `packet` points to a valid instance of `SPPacket`
|
||||
/// - `packet` is not used concurrently or after this call
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_connection_send_packet(
|
||||
connection: *const SPConnection,
|
||||
|
@ -69,7 +69,7 @@ pub unsafe extern "C" fn sp_connection_send_packet(
|
|||
|
||||
/// Sends a `SPCommand` to the display using the `SPConnection`.
|
||||
///
|
||||
/// The passed `SPCommand` gets consumed.
|
||||
/// The passed `command` gets consumed.
|
||||
///
|
||||
/// returns: true in case of success
|
||||
///
|
||||
|
@ -95,9 +95,9 @@ pub unsafe extern "C" fn sp_connection_send_command(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPConnection`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `connection` points to a valid `SPConnection`
|
||||
/// - `connection` is not used concurrently or after this call
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_connection_free(ptr: *mut SPConnection) {
|
||||
_ = Box::from_raw(ptr);
|
||||
pub unsafe extern "C" fn sp_connection_free(connection: *mut SPConnection) {
|
||||
_ = Box::from_raw(connection);
|
||||
}
|
||||
|
|
|
@ -86,15 +86,15 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` is not written to concurrently
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_cp437_grid_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_clone(
|
||||
this: *const SPCp437Grid,
|
||||
cp437_grid: *const SPCp437Grid,
|
||||
) -> *mut SPCp437Grid {
|
||||
Box::into_raw(Box::new((*this).clone()))
|
||||
Box::into_raw(Box::new((*cp437_grid).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `SPCp437Grid`.
|
||||
|
@ -103,19 +103,19 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` is not used concurrently or after cp437_grid call
|
||||
/// - `cp437_grid` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_free(this: *mut SPCp437Grid) {
|
||||
_ = Box::from_raw(this);
|
||||
pub unsafe extern "C" fn sp_cp437_grid_free(cp437_grid: *mut SPCp437Grid) {
|
||||
_ = Box::from_raw(cp437_grid);
|
||||
}
|
||||
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `cp437_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -126,22 +126,22 @@ pub unsafe extern "C" fn sp_cp437_grid_free(this: *mut SPCp437Grid) {
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` is not written to concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_get(
|
||||
this: *const SPCp437Grid,
|
||||
cp437_grid: *const SPCp437Grid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> u8 {
|
||||
(*this).actual.get(x, y)
|
||||
(*cp437_grid).actual.get(x, y)
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `SPCp437Grid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `cp437_grid`: instance to write to
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
|
@ -155,70 +155,73 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `cp437_grid` points to a valid `SPBitVec`
|
||||
/// - `cp437_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_set(
|
||||
this: *mut SPCp437Grid,
|
||||
cp437_grid: *mut SPCp437Grid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: u8,
|
||||
) {
|
||||
(*this).actual.set(x, y, value);
|
||||
(*cp437_grid).actual.set(x, y, value);
|
||||
}
|
||||
|
||||
/// Sets the value of all cells in the `SPCp437Grid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `cp437_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut SPCp437Grid, value: u8) {
|
||||
(*this).actual.fill(value);
|
||||
pub unsafe extern "C" fn sp_cp437_grid_fill(
|
||||
cp437_grid: *mut SPCp437Grid,
|
||||
value: u8,
|
||||
) {
|
||||
(*cp437_grid).actual.fill(value);
|
||||
}
|
||||
|
||||
/// Gets the width of the `SPCp437Grid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `cp437_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_width(
|
||||
this: *const SPCp437Grid,
|
||||
cp437_grid: *const SPCp437Grid,
|
||||
) -> usize {
|
||||
(*this).actual.width()
|
||||
(*cp437_grid).actual.width()
|
||||
}
|
||||
|
||||
/// Gets the height of the `SPCp437Grid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `cp437_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_height(
|
||||
this: *const SPCp437Grid,
|
||||
cp437_grid: *const SPCp437Grid,
|
||||
) -> usize {
|
||||
(*this).actual.height()
|
||||
(*cp437_grid).actual.height()
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the `SPCp437Grid` instance.
|
||||
|
@ -229,14 +232,14 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
/// - `cp437_grid` points to a valid `SPCp437Grid`
|
||||
/// - the returned memory range is never accessed after the passed `SPCp437Grid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `SPCp437Grid` or directly
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
|
||||
this: *mut SPCp437Grid,
|
||||
cp437_grid: *mut SPCp437Grid,
|
||||
) -> SPByteSlice {
|
||||
let data = (*this).actual.data_ref_mut();
|
||||
let data = (*cp437_grid).actual.data_ref_mut();
|
||||
SPByteSlice {
|
||||
start: data.as_mut_ptr_range().start,
|
||||
length: data.len(),
|
||||
|
|
|
@ -63,15 +63,15 @@ pub unsafe extern "C" fn sp_packet_try_load(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPacket`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `packet` points to a valid `SPPacket`
|
||||
/// - `packet` is not written to concurrently
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_packet_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_packet_clone(
|
||||
this: *const SPPacket,
|
||||
packet: *const SPPacket,
|
||||
) -> *mut SPPacket {
|
||||
Box::into_raw(Box::new(SPPacket((*this).0.clone())))
|
||||
Box::into_raw(Box::new(SPPacket((*packet).0.clone())))
|
||||
}
|
||||
|
||||
/// Deallocates a `SPPacket`.
|
||||
|
@ -80,9 +80,9 @@ pub unsafe extern "C" fn sp_packet_clone(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPacket`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `packet` points to a valid `SPPacket`
|
||||
/// - `packet` is not used concurrently or after this call
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_packet_free(this: *mut SPPacket) {
|
||||
_ = Box::from_raw(this)
|
||||
pub unsafe extern "C" fn sp_packet_free(packet: *mut SPPacket) {
|
||||
_ = Box::from_raw(packet)
|
||||
}
|
||||
|
|
|
@ -89,15 +89,15 @@ pub unsafe extern "C" fn sp_pixel_grid_load(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` is not written to concurrently
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_pixel_grid_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_clone(
|
||||
this: *const SPPixelGrid,
|
||||
pixel_grid: *const SPPixelGrid,
|
||||
) -> *mut SPPixelGrid {
|
||||
Box::into_raw(Box::new(SPPixelGrid((*this).0.clone())))
|
||||
Box::into_raw(Box::new(SPPixelGrid((*pixel_grid).0.clone())))
|
||||
}
|
||||
|
||||
/// Deallocates a `SPPixelGrid`.
|
||||
|
@ -106,19 +106,19 @@ pub unsafe extern "C" fn sp_pixel_grid_clone(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `this` is not used concurrently or after this call
|
||||
/// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` is not used concurrently or after pixel_grid call
|
||||
/// - `pixel_grid` was not passed to another consuming function, e.g. to create a `SPCommand`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_free(this: *mut SPPixelGrid) {
|
||||
_ = Box::from_raw(this);
|
||||
pub unsafe extern "C" fn sp_pixel_grid_free(pixel_grid: *mut SPPixelGrid) {
|
||||
_ = Box::from_raw(pixel_grid);
|
||||
}
|
||||
|
||||
/// Gets the current value at the specified position in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `pixel_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -129,22 +129,22 @@ pub unsafe extern "C" fn sp_pixel_grid_free(this: *mut SPPixelGrid) {
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `this` is not written to concurrently
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` is not written to concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_get(
|
||||
this: *const SPPixelGrid,
|
||||
pixel_grid: *const SPPixelGrid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> bool {
|
||||
(*this).0.get(x, y)
|
||||
(*pixel_grid).0.get(x, y)
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `pixel_grid`: instance to write to
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
|
@ -158,73 +158,73 @@ pub unsafe extern "C" fn sp_pixel_grid_get(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_set(
|
||||
this: *mut SPPixelGrid,
|
||||
pixel_grid: *mut SPPixelGrid,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: bool,
|
||||
) {
|
||||
(*this).0.set(x, y, value);
|
||||
(*pixel_grid).0.set(x, y, value);
|
||||
}
|
||||
|
||||
/// Sets the state of all pixels in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to write to
|
||||
/// - `pixel_grid`: instance to write to
|
||||
/// - `value`: the value to set all pixels to
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `this` is not written to or read from concurrently
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` is not written to or read from concurrently
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_fill(
|
||||
this: *mut SPPixelGrid,
|
||||
pixel_grid: *mut SPPixelGrid,
|
||||
value: bool,
|
||||
) {
|
||||
(*this).0.fill(value);
|
||||
(*pixel_grid).0.fill(value);
|
||||
}
|
||||
|
||||
/// Gets the width in pixels of the `SPPixelGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `pixel_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_width(
|
||||
this: *const SPPixelGrid,
|
||||
pixel_grid: *const SPPixelGrid,
|
||||
) -> usize {
|
||||
(*this).0.width()
|
||||
(*pixel_grid).0.width()
|
||||
}
|
||||
|
||||
/// Gets the height in pixels of the `SPPixelGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `this`: instance to read from
|
||||
/// - `pixel_grid`: instance to read from
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_height(
|
||||
this: *const SPPixelGrid,
|
||||
pixel_grid: *const SPPixelGrid,
|
||||
) -> usize {
|
||||
(*this).0.height()
|
||||
(*pixel_grid).0.height()
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the `SPPixelGrid` instance.
|
||||
|
@ -233,14 +233,14 @@ pub unsafe extern "C" fn sp_pixel_grid_height(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
/// - `pixel_grid` points to a valid `SPPixelGrid`
|
||||
/// - the returned memory range is never accessed after the passed `SPPixelGrid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `SPPixelGrid` or directly
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_unsafe_data_ref(
|
||||
this: *mut SPPixelGrid,
|
||||
pixel_grid: *mut SPPixelGrid,
|
||||
) -> SPByteSlice {
|
||||
let data = (*this).0.data_ref_mut();
|
||||
let data = (*pixel_grid).0.data_ref_mut();
|
||||
SPByteSlice {
|
||||
start: data.as_mut_ptr_range().start,
|
||||
length: data.len(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue