rename _dealloc to _free

This commit is contained in:
Vinzenz Schroeter 2024-09-07 14:11:15 +02:00
parent f45c8090ec
commit aa359cc807
19 changed files with 389 additions and 410 deletions

View file

@ -28,8 +28,8 @@ int main(void) {
SPPacket *packet = sp_packet_from_command(command); SPPacket *packet = sp_packet_from_command(command);
while (sp_connection_send(connection, sp_packet_clone(packet))); while (sp_connection_send(connection, sp_packet_clone(packet)));
sp_packet_dealloc(packet); sp_packet_free(packet);
sp_connection_dealloc(connection); sp_connection_free(connection);
return 0; return 0;
} }
``` ```

View file

@ -13,7 +13,7 @@ int main(void) {
SPPacket *packet = sp_packet_from_command(command); SPPacket *packet = sp_packet_from_command(command);
while (sp_connection_send(connection, sp_packet_clone(packet))); while (sp_connection_send(connection, sp_packet_clone(packet)));
sp_packet_dealloc(packet); sp_packet_free(packet);
sp_connection_dealloc(connection); sp_connection_free(connection);
return 0; return 0;
} }

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `BitVec`s //! C functions for interacting with `SPBitVec`s
//! //!
//! prefix `sp_bit_vec_` //! prefix `sp_bit_vec_`
@ -11,7 +11,7 @@ use servicepoint::bitvec::prelude::{BitVec, Msb0};
/// ```C /// ```C
/// SPBitVec vec = sp_bit_vec_new(8); /// SPBitVec vec = sp_bit_vec_new(8);
/// sp_bit_vec_set(vec, 5, true); /// sp_bit_vec_set(vec, 5, true);
/// sp_bit_vec_dealloc(vec); /// sp_bit_vec_free(vec);
/// ``` /// ```
pub struct SPBitVec(BitVec<u8, Msb0>); pub struct SPBitVec(BitVec<u8, Msb0>);
@ -33,13 +33,13 @@ impl Clone for SPBitVec {
} }
} }
/// Creates a new `BitVec` instance. /// Creates a new `SPBitVec` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
/// - `size`: size in bits. /// - `size`: size in bits.
/// ///
/// returns: `BitVec` with all bits set to false. /// returns: `SPBitVec` with all bits set to false.
/// ///
/// # Panics /// # Panics
/// ///
@ -50,13 +50,13 @@ impl Clone for SPBitVec {
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bit_vec_dealloc`. /// by explicitly calling `sp_bit_vec_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_new(size: usize) -> *mut SPBitVec { pub unsafe extern "C" fn sp_bit_vec_new(size: usize) -> *mut SPBitVec {
Box::into_raw(Box::new(SPBitVec(BitVec::repeat(false, size)))) Box::into_raw(Box::new(SPBitVec(BitVec::repeat(false, size))))
} }
/// Interpret the data as a series of bits and load then into a new `BitVec` instance. /// Interpret the data as a series of bits and load then into a new `SPBitVec` instance.
/// ///
/// # Safety /// # Safety
/// ///
@ -65,7 +65,7 @@ pub unsafe extern "C" fn sp_bit_vec_new(size: usize) -> *mut SPBitVec {
/// - `data` points to a valid memory location of at least `data_length` /// - `data` points to a valid memory location of at least `data_length`
/// bytes in size. /// bytes in size.
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bit_vec_dealloc`. /// by explicitly calling `sp_bit_vec_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_load( pub unsafe extern "C" fn sp_bit_vec_load(
data: *const u8, data: *const u8,
@ -75,16 +75,16 @@ pub unsafe extern "C" fn sp_bit_vec_load(
Box::into_raw(Box::new(SPBitVec(BitVec::from_slice(data)))) Box::into_raw(Box::new(SPBitVec(BitVec::from_slice(data))))
} }
/// Clones a `BitVec`. /// Clones a `SPBitVec`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bit_vec_dealloc`. /// by explicitly calling `sp_bit_vec_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_clone( pub unsafe extern "C" fn sp_bit_vec_clone(
this: *const SPBitVec, this: *const SPBitVec,
@ -92,21 +92,21 @@ pub unsafe extern "C" fn sp_bit_vec_clone(
Box::into_raw(Box::new((*this).clone())) Box::into_raw(Box::new((*this).clone()))
} }
/// Deallocates a `BitVec`. /// Deallocates a `SPBitVec`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
/// - `this` was not passed to another consuming function, e.g. to create a `Command` /// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_dealloc(this: *mut SPBitVec) { pub unsafe extern "C" fn sp_bit_vec_free(this: *mut SPBitVec) {
_ = Box::from_raw(this); _ = Box::from_raw(this);
} }
/// Gets the value of a bit from the `BitVec`. /// Gets the value of a bit from the `SPBitVec`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -123,7 +123,7 @@ pub unsafe extern "C" fn sp_bit_vec_dealloc(this: *mut SPBitVec) {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_get( pub unsafe extern "C" fn sp_bit_vec_get(
@ -133,7 +133,7 @@ pub unsafe extern "C" fn sp_bit_vec_get(
*(*this).0.get(index).unwrap() *(*this).0.get(index).unwrap()
} }
/// Sets the value of a bit in the `BitVec`. /// Sets the value of a bit in the `SPBitVec`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -151,7 +151,7 @@ pub unsafe extern "C" fn sp_bit_vec_get(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_set( pub unsafe extern "C" fn sp_bit_vec_set(
@ -162,7 +162,7 @@ pub unsafe extern "C" fn sp_bit_vec_set(
(*this).0.set(index, value) (*this).0.set(index, value)
} }
/// Sets the value of all bits in the `BitVec`. /// Sets the value of all bits in the `SPBitVec`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -172,20 +172,20 @@ pub unsafe extern "C" fn sp_bit_vec_set(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_fill(this: *mut SPBitVec, value: bool) { pub unsafe extern "C" fn sp_bit_vec_fill(this: *mut SPBitVec, value: bool) {
(*this).0.fill(value) (*this).0.fill(value)
} }
/// Gets the length of the `BitVec` in bits. /// Gets the length of the `SPBitVec` in bits.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_len(this: *const SPBitVec) -> usize { pub unsafe extern "C" fn sp_bit_vec_len(this: *const SPBitVec) -> usize {
(*this).0.len() (*this).0.len()
@ -197,21 +197,21 @@ pub unsafe extern "C" fn sp_bit_vec_len(this: *const SPBitVec) -> usize {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_is_empty(this: *const SPBitVec) -> bool { pub unsafe extern "C" fn sp_bit_vec_is_empty(this: *const SPBitVec) -> bool {
(*this).0.is_empty() (*this).0.is_empty()
} }
/// Gets an unsafe reference to the data of the `BitVec` instance. /// Gets an unsafe reference to the data of the `SPBitVec` instance.
/// ///
/// ## Safety /// ## Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - the returned memory range is never accessed after the passed `BitVec` has been freed /// - 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 `BitVec` or directly /// - the returned memory range is never accessed concurrently, either via the `SPBitVec` or directly
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bit_vec_unsafe_data_ref( pub unsafe extern "C" fn sp_bit_vec_unsafe_data_ref(
this: *mut SPBitVec, this: *mut SPBitVec,

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `BrightnessGrid`s //! C functions for interacting with `SPBrightnessGrid`s
//! //!
//! prefix `sp_brightness_grid_` //! prefix `sp_brightness_grid_`
@ -19,7 +19,7 @@ use std::intrinsics::transmute;
/// sp_brightness_grid_set(grid, 1, 1, 10); /// sp_brightness_grid_set(grid, 1, 1, 10);
/// ///
/// SPCommand command = sp_command_char_brightness(grid); /// SPCommand command = sp_command_char_brightness(grid);
/// sp_connection_dealloc(connection); /// sp_connection_free(connection);
/// ``` /// ```
pub struct SPBrightnessGrid { pub struct SPBrightnessGrid {
pub(crate) actual: servicepoint::BrightnessGrid, pub(crate) actual: servicepoint::BrightnessGrid,
@ -33,16 +33,16 @@ impl Clone for SPBrightnessGrid {
} }
} }
/// Creates a new `BrightnessGrid` with the specified dimensions. /// Creates a new `SPBrightnessGrid` with the specified dimensions.
/// ///
/// returns: `BrightnessGrid` initialized to 0. /// returns: `SPBrightnessGrid` initialized to 0.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_brightness_grid_dealloc`. /// by explicitly calling `sp_brightness_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_new( pub unsafe extern "C" fn sp_brightness_grid_new(
width: usize, width: usize,
@ -53,7 +53,7 @@ pub unsafe extern "C" fn sp_brightness_grid_new(
})) }))
} }
/// Loads a `BrightnessGrid` with the specified dimensions from the provided data. /// Loads a `SPBrightnessGrid` with the specified dimensions from the provided data.
/// ///
/// # Panics /// # Panics
/// ///
@ -66,7 +66,7 @@ pub unsafe extern "C" fn sp_brightness_grid_new(
/// - `data` points to a valid memory location of at least `data_length` /// - `data` points to a valid memory location of at least `data_length`
/// bytes in size. /// bytes in size.
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_brightness_grid_dealloc`. /// by explicitly calling `sp_brightness_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_load( pub unsafe extern "C" fn sp_brightness_grid_load(
width: usize, width: usize,
@ -81,16 +81,16 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
Box::into_raw(Box::new(SPBrightnessGrid { actual: grid })) Box::into_raw(Box::new(SPBrightnessGrid { actual: grid }))
} }
/// Clones a `BrightnessGrid`. /// Clones a `SPBrightnessGrid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_brightness_grid_dealloc`. /// by explicitly calling `sp_brightness_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_clone( pub unsafe extern "C" fn sp_brightness_grid_clone(
this: *const SPBrightnessGrid, this: *const SPBrightnessGrid,
@ -98,17 +98,17 @@ pub unsafe extern "C" fn sp_brightness_grid_clone(
Box::into_raw(Box::new((*this).clone())) Box::into_raw(Box::new((*this).clone()))
} }
/// Deallocates a `BrightnessGrid`. /// Deallocates a `SPBrightnessGrid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
/// - `this` was not passed to another consuming function, e.g. to create a `Command` /// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_dealloc( pub unsafe extern "C" fn sp_brightness_grid_free(
this: *mut SPBrightnessGrid, this: *mut SPBrightnessGrid,
) { ) {
_ = Box::from_raw(this); _ = Box::from_raw(this);
@ -129,7 +129,7 @@ pub unsafe extern "C" fn sp_brightness_grid_dealloc(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_get( pub unsafe extern "C" fn sp_brightness_grid_get(
@ -140,7 +140,7 @@ pub unsafe extern "C" fn sp_brightness_grid_get(
(*this).actual.get(x, y).into() (*this).actual.get(x, y).into()
} }
/// Sets the value of the specified position in the `BrightnessGrid`. /// Sets the value of the specified position in the `SPBrightnessGrid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -159,7 +159,7 @@ pub unsafe extern "C" fn sp_brightness_grid_get(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_set( pub unsafe extern "C" fn sp_brightness_grid_set(
@ -173,7 +173,7 @@ pub unsafe extern "C" fn sp_brightness_grid_set(
(*this).actual.set(x, y, brightness); (*this).actual.set(x, y, brightness);
} }
/// Sets the value of all cells in the `BrightnessGrid`. /// Sets the value of all cells in the `SPBrightnessGrid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -188,7 +188,7 @@ pub unsafe extern "C" fn sp_brightness_grid_set(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_fill( pub unsafe extern "C" fn sp_brightness_grid_fill(
@ -200,7 +200,7 @@ pub unsafe extern "C" fn sp_brightness_grid_fill(
(*this).actual.fill(brightness); (*this).actual.fill(brightness);
} }
/// Gets the width of the `BrightnessGrid` instance. /// Gets the width of the `SPBrightnessGrid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -210,7 +210,7 @@ pub unsafe extern "C" fn sp_brightness_grid_fill(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_width( pub unsafe extern "C" fn sp_brightness_grid_width(
this: *const SPBrightnessGrid, this: *const SPBrightnessGrid,
@ -218,7 +218,7 @@ pub unsafe extern "C" fn sp_brightness_grid_width(
(*this).actual.width() (*this).actual.width()
} }
/// Gets the height of the `BrightnessGrid` instance. /// Gets the height of the `SPBrightnessGrid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -228,7 +228,7 @@ pub unsafe extern "C" fn sp_brightness_grid_width(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_height( pub unsafe extern "C" fn sp_brightness_grid_height(
this: *const SPBrightnessGrid, this: *const SPBrightnessGrid,
@ -236,15 +236,15 @@ pub unsafe extern "C" fn sp_brightness_grid_height(
(*this).actual.height() (*this).actual.height()
} }
/// Gets an unsafe reference to the data of the `BrightnessGrid` instance. /// Gets an unsafe reference to the data of the `SPBrightnessGrid` instance.
/// ///
/// ## Safety /// ## Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BrightnessGrid` /// - `this` points to a valid `SPBrightnessGrid`
/// - the returned memory range is never accessed after the passed `BrightnessGrid` has been freed /// - 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 `BrightnessGrid` or directly /// - the returned memory range is never accessed concurrently, either via the `SPBrightnessGrid` or directly
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref( pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref(
this: *mut SPBrightnessGrid, this: *mut SPBrightnessGrid,

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `Command`s //! C functions for interacting with `SPCommand`s
//! //!
//! prefix `sp_command_` //! prefix `sp_command_`
@ -39,11 +39,11 @@ impl Clone for SPCommand {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `packet` points to a valid instance of `SPPacket` /// - `SPPacket` points to a valid instance of `SPPacket`
/// - `packet` is not used concurrently or after this call /// - `SPPacket` is not used concurrently or after this call
/// - the result is checked for NULL /// - the result is checked for NULL
/// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_try_from_packet( pub unsafe extern "C" fn sp_command_try_from_packet(
packet: *mut SPPacket, packet: *mut SPPacket,
@ -61,10 +61,10 @@ pub unsafe extern "C" fn sp_command_try_from_packet(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid instance of `Command` /// - `this` points to a valid instance of `SPCommand`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_clone( pub unsafe extern "C" fn sp_command_clone(
original: *const SPCommand, original: *const SPCommand,
@ -86,8 +86,8 @@ pub unsafe extern "C" fn sp_command_clone(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand { pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear))) Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear)))
@ -102,8 +102,8 @@ pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand { pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset))) Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset)))
@ -115,8 +115,8 @@ pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand { pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand {
Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut))) Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut)))
@ -134,7 +134,7 @@ pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand {
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_brightness( pub unsafe extern "C" fn sp_command_brightness(
brightness: u8, brightness: u8,
@ -157,8 +157,8 @@ pub unsafe extern "C" fn sp_command_brightness(
/// ///
/// - `grid` points to a valid instance of `SPBrightnessGrid` /// - `grid` points to a valid instance of `SPBrightnessGrid`
/// - `grid` is not used concurrently or after this call /// - `grid` is not used concurrently or after this call
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_char_brightness( pub unsafe extern "C" fn sp_command_char_brightness(
x: usize, x: usize,
@ -173,24 +173,24 @@ pub unsafe extern "C" fn sp_command_char_brightness(
} }
/// Allocates a new `Command::BitmapLinear` instance. /// Allocates a new `Command::BitmapLinear` instance.
/// The passed `BitVec` gets consumed. /// The passed `SPBitVec` gets consumed.
/// ///
/// Set pixel data starting at the pixel offset on screen. /// Set pixel data starting at the pixel offset on screen.
/// ///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning /// The screen will continuously overwrite more pixel data without regarding the offset, meaning
/// once the starting row is full, overwriting will continue on column 0. /// once the starting row is full, overwriting will continue on column 0.
/// ///
/// The contained `BitVec` is always uncompressed. /// The contained `SPBitVec` is always uncompressed.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `bit_vec` points to a valid instance of `BitVec` /// - `bit_vec` points to a valid instance of `SPBitVec`
/// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` is not used concurrently or after this call
/// - `compression` matches one of the allowed enum values /// - `compression` matches one of the allowed enum values
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear( pub unsafe extern "C" fn sp_command_bitmap_linear(
offset: usize, offset: usize,
@ -206,24 +206,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
} }
/// Allocates a new `Command::BitmapLinearAnd` instance. /// Allocates a new `Command::BitmapLinearAnd` instance.
/// The passed `BitVec` gets consumed. /// The passed `SPBitVec` gets consumed.
/// ///
/// Set pixel data according to an and-mask starting at the offset. /// Set pixel data according to an and-mask starting at the offset.
/// ///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning /// The screen will continuously overwrite more pixel data without regarding the offset, meaning
/// once the starting row is full, overwriting will continue on column 0. /// once the starting row is full, overwriting will continue on column 0.
/// ///
/// The contained `BitVec` is always uncompressed. /// The contained `SPBitVec` is always uncompressed.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `bit_vec` points to a valid instance of `BitVec` /// - `bit_vec` points to a valid instance of `SPBitVec`
/// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` is not used concurrently or after this call
/// - `compression` matches one of the allowed enum values /// - `compression` matches one of the allowed enum values
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_and( pub unsafe extern "C" fn sp_command_bitmap_linear_and(
offset: usize, offset: usize,
@ -239,24 +239,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
} }
/// Allocates a new `Command::BitmapLinearOr` instance. /// Allocates a new `Command::BitmapLinearOr` instance.
/// The passed `BitVec` gets consumed. /// The passed `SPBitVec` gets consumed.
/// ///
/// Set pixel data according to an or-mask starting at the offset. /// Set pixel data according to an or-mask starting at the offset.
/// ///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning /// The screen will continuously overwrite more pixel data without regarding the offset, meaning
/// once the starting row is full, overwriting will continue on column 0. /// once the starting row is full, overwriting will continue on column 0.
/// ///
/// The contained `BitVec` is always uncompressed. /// The contained `SPBitVec` is always uncompressed.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `bit_vec` points to a valid instance of `BitVec` /// - `bit_vec` points to a valid instance of `SPBitVec`
/// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` is not used concurrently or after this call
/// - `compression` matches one of the allowed enum values /// - `compression` matches one of the allowed enum values
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_or( pub unsafe extern "C" fn sp_command_bitmap_linear_or(
offset: usize, offset: usize,
@ -272,24 +272,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
} }
/// Allocates a new `Command::BitmapLinearXor` instance. /// Allocates a new `Command::BitmapLinearXor` instance.
/// The passed `BitVec` gets consumed. /// The passed `SPBitVec` gets consumed.
/// ///
/// Set pixel data according to a xor-mask starting at the offset. /// Set pixel data according to a xor-mask starting at the offset.
/// ///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning /// The screen will continuously overwrite more pixel data without regarding the offset, meaning
/// once the starting row is full, overwriting will continue on column 0. /// once the starting row is full, overwriting will continue on column 0.
/// ///
/// The contained `BitVec` is always uncompressed. /// The contained `SPBitVec` is always uncompressed.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `bit_vec` points to a valid instance of `BitVec` /// - `bit_vec` points to a valid instance of `SPBitVec`
/// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` is not used concurrently or after this call
/// - `compression` matches one of the allowed enum values /// - `compression` matches one of the allowed enum values
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_xor( pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
offset: usize, offset: usize,
@ -305,7 +305,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
} }
/// Allocates a new `Command::Cp437Data` instance. /// Allocates a new `Command::Cp437Data` instance.
/// The passed `ByteGrid` gets consumed. /// The passed `SPCp437Grid` gets consumed.
/// ///
/// Show text on the screen. /// Show text on the screen.
/// ///
@ -318,25 +318,25 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `byte_grid` points to a valid instance of `ByteGrid` /// - `grid` points to a valid instance of `SPCp437Grid`
/// - `byte_grid` is not used concurrently or after this call /// - `grid` is not used concurrently or after this call
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_cp437_data( pub unsafe extern "C" fn sp_command_cp437_data(
x: usize, x: usize,
y: usize, y: usize,
byte_grid: *mut SPCp437Grid, grid: *mut SPCp437Grid,
) -> *mut SPCommand { ) -> *mut SPCommand {
let byte_grid = *Box::from_raw(byte_grid); let grid = *Box::from_raw(grid);
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data( Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data(
Origin::new(x, y), Origin::new(x, y),
byte_grid.actual, grid.actual,
)))) ))))
} }
/// Allocates a new `Command::BitmapLinearWin` instance. /// Allocates a new `Command::BitmapLinearWin` instance.
/// The passed `PixelGrid` gets consumed. /// The passed `SPPixelGrid` gets consumed.
/// ///
/// Sets a window of pixels to the specified values /// Sets a window of pixels to the specified values
/// ///
@ -344,11 +344,11 @@ pub unsafe extern "C" fn sp_command_cp437_data(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `pixel_grid` points to a valid instance of `PixelGrid` /// - `pixel_grid` points to a valid instance of `SPPixelGrid`
/// - `pixel_grid` is not used concurrently or after this call /// - `pixel_grid` is not used concurrently or after this call
/// - `compression` matches one of the allowed enum values /// - `compression` matches one of the allowed enum values
/// - the returned `Command` instance is freed in some way, either by using a consuming function or /// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`. /// by explicitly calling `sp_command_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_win( pub unsafe extern "C" fn sp_command_bitmap_linear_win(
x: usize, x: usize,
@ -366,23 +366,23 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
)))) ))))
} }
/// Deallocates a `Command`. /// Deallocates a `SPCommand`.
/// ///
/// # Examples /// # Examples
/// ///
/// ```C /// ```C
/// SPCommand c = sp_command_clear(); /// SPCommand c = sp_command_clear();
/// sp_command_dealloc(c); /// sp_command_free(c);
/// ``` /// ```
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Command` /// - `this` points to a valid `SPCommand`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
/// - `this` was not passed to another consuming function, e.g. to create a `Packet` /// - `this` was not passed to another consuming function, e.g. to create a `SPPacket`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_command_dealloc(ptr: *mut SPCommand) { pub unsafe extern "C" fn sp_command_free(ptr: *mut SPCommand) {
_ = Box::from_raw(ptr); _ = Box::from_raw(ptr);
} }

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `Connection`s //! C functions for interacting with `SPConnection`s
//! //!
//! prefix `sp_connection_` //! prefix `sp_connection_`
@ -18,7 +18,7 @@ use crate::SPPacket;
/// ``` /// ```
pub struct SPConnection(pub(crate) servicepoint::Connection); pub struct SPConnection(pub(crate) servicepoint::Connection);
/// Creates a new instance of `Connection`. /// Creates a new instance of `SPConnection`.
/// ///
/// returns: NULL if connection fails, or connected instance /// returns: NULL if connection fails, or connected instance
/// ///
@ -31,7 +31,7 @@ pub struct SPConnection(pub(crate) servicepoint::Connection);
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_connection_dealloc`. /// by explicitly calling `sp_connection_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_connection_open( pub unsafe extern "C" fn sp_connection_open(
host: *const c_char, host: *const c_char,
@ -45,8 +45,8 @@ pub unsafe extern "C" fn sp_connection_open(
Box::into_raw(Box::new(SPConnection(connection))) Box::into_raw(Box::new(SPConnection(connection)))
} }
/// Sends a `Packet` to the display using the `Connection`. /// Sends a `SPPacket` to the display using the `SPConnection`.
/// The passed `Packet` gets consumed. /// The passed `SPPacket` gets consumed.
/// ///
/// returns: true in case of success /// returns: true in case of success
/// ///
@ -54,9 +54,9 @@ pub unsafe extern "C" fn sp_connection_open(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `connection` points to a valid instance of `Connection` /// - `SPConnection` points to a valid instance of `SPConnection`
/// - `packet` points to a valid instance of `Packet` /// - `SPPacket` points to a valid instance of `SPPacket`
/// - `packet` is not used concurrently or after this call /// - `SPPacket` is not used concurrently or after this call
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_connection_send( pub unsafe extern "C" fn sp_connection_send(
connection: *const SPConnection, connection: *const SPConnection,
@ -66,15 +66,15 @@ pub unsafe extern "C" fn sp_connection_send(
(*connection).0.send((*packet).0).is_ok() (*connection).0.send((*packet).0).is_ok()
} }
/// Closes and deallocates a `Connection`. /// Closes and deallocates a `SPConnection`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Connection` /// - `this` points to a valid `SPConnection`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_connection_dealloc(ptr: *mut SPConnection) { pub unsafe extern "C" fn sp_connection_free(ptr: *mut SPConnection) {
_ = Box::from_raw(ptr); _ = Box::from_raw(ptr);
} }

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `Cp437Grid`s //! C functions for interacting with `SPCp437Grid`s
//! //!
//! prefix `sp_cp437_grid_` //! prefix `sp_cp437_grid_`
@ -15,7 +15,7 @@ use servicepoint::{DataRef, Grid};
/// Cp437Grid grid = sp_cp437_grid_new(4, 3); /// Cp437Grid grid = sp_cp437_grid_new(4, 3);
/// sp_cp437_grid_fill(grid, '?'); /// sp_cp437_grid_fill(grid, '?');
/// sp_cp437_grid_set(grid, 0, 0, '!'); /// sp_cp437_grid_set(grid, 0, 0, '!');
/// sp_cp437_grid_dealloc(grid); /// sp_cp437_grid_free(grid);
/// ``` /// ```
pub struct SPCp437Grid { pub struct SPCp437Grid {
pub(crate) actual: servicepoint::Cp437Grid, pub(crate) actual: servicepoint::Cp437Grid,
@ -29,16 +29,16 @@ impl Clone for SPCp437Grid {
} }
} }
/// Creates a new `Cp437Grid` with the specified dimensions. /// Creates a new `SPCp437Grid` with the specified dimensions.
/// ///
/// returns: `Cp437Grid` initialized to 0. /// returns: `SPCp437Grid` initialized to 0.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_cp437_grid_dealloc`. /// by explicitly calling `sp_cp437_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_new( pub unsafe extern "C" fn sp_cp437_grid_new(
width: usize, width: usize,
@ -49,7 +49,7 @@ pub unsafe extern "C" fn sp_cp437_grid_new(
})) }))
} }
/// Loads a `Cp437Grid` with the specified dimensions from the provided data. /// Loads a `SPCp437Grid` with the specified dimensions from the provided data.
/// ///
/// # Panics /// # Panics
/// ///
@ -62,7 +62,7 @@ pub unsafe extern "C" fn sp_cp437_grid_new(
/// - `data` points to a valid memory location of at least `data_length` /// - `data` points to a valid memory location of at least `data_length`
/// bytes in size. /// bytes in size.
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_cp437_grid_dealloc`. /// by explicitly calling `sp_cp437_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_load( pub unsafe extern "C" fn sp_cp437_grid_load(
width: usize, width: usize,
@ -76,16 +76,16 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
})) }))
} }
/// Clones a `Cp437Grid`. /// Clones a `SPCp437Grid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_cp437_grid_dealloc`. /// by explicitly calling `sp_cp437_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_clone( pub unsafe extern "C" fn sp_cp437_grid_clone(
this: *const SPCp437Grid, this: *const SPCp437Grid,
@ -93,17 +93,17 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
Box::into_raw(Box::new((*this).clone())) Box::into_raw(Box::new((*this).clone()))
} }
/// Deallocates a `Cp437Grid`. /// Deallocates a `SPCp437Grid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
/// - `this` was not passed to another consuming function, e.g. to create a `Command` /// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_dealloc(this: *mut SPCp437Grid) { pub unsafe extern "C" fn sp_cp437_grid_free(this: *mut SPCp437Grid) {
_ = Box::from_raw(this); _ = Box::from_raw(this);
} }
@ -122,7 +122,7 @@ pub unsafe extern "C" fn sp_cp437_grid_dealloc(this: *mut SPCp437Grid) {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_get( pub unsafe extern "C" fn sp_cp437_grid_get(
@ -133,7 +133,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
(*this).actual.get(x, y) (*this).actual.get(x, y)
} }
/// Sets the value of the specified position in the `Cp437Grid`. /// Sets the value of the specified position in the `SPCp437Grid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -151,7 +151,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `BitVec` /// - `this` points to a valid `SPBitVec`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_set( pub unsafe extern "C" fn sp_cp437_grid_set(
@ -163,7 +163,7 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
(*this).actual.set(x, y, value); (*this).actual.set(x, y, value);
} }
/// Sets the value of all cells in the `Cp437Grid`. /// Sets the value of all cells in the `SPCp437Grid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -174,14 +174,14 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut SPCp437Grid, value: u8) { pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut SPCp437Grid, value: u8) {
(*this).actual.fill(value); (*this).actual.fill(value);
} }
/// Gets the width of the `Cp437Grid` instance. /// Gets the width of the `SPCp437Grid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -191,7 +191,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut SPCp437Grid, value: u8) {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_width( pub unsafe extern "C" fn sp_cp437_grid_width(
this: *const SPCp437Grid, this: *const SPCp437Grid,
@ -199,7 +199,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
(*this).actual.width() (*this).actual.width()
} }
/// Gets the height of the `Cp437Grid` instance. /// Gets the height of the `SPCp437Grid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -209,7 +209,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_height( pub unsafe extern "C" fn sp_cp437_grid_height(
this: *const SPCp437Grid, this: *const SPCp437Grid,
@ -217,15 +217,15 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
(*this).actual.height() (*this).actual.height()
} }
/// Gets an unsafe reference to the data of the `Cp437Grid` instance. /// Gets an unsafe reference to the data of the `SPCp437Grid` instance.
/// ///
/// ## Safety /// ## Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Cp437Grid` /// - `this` points to a valid `SPCp437Grid`
/// - the returned memory range is never accessed after the passed `Cp437Grid` has been freed /// - 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 `Cp437Grid` or directly /// - the returned memory range is never accessed concurrently, either via the `SPCp437Grid` or directly
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref( pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
this: *mut SPCp437Grid, this: *mut SPCp437Grid,

View file

@ -20,8 +20,8 @@
//! SPPacket *packet = sp_packet_from_command(command); //! SPPacket *packet = sp_packet_from_command(command);
//! while (sp_connection_send(connection, sp_packet_clone(packet))); //! while (sp_connection_send(connection, sp_packet_clone(packet)));
//! //!
//! sp_packet_dealloc(packet); //! sp_packet_free(packet);
//! sp_connection_dealloc(connection); //! sp_connection_free(connection);
//! return 0; //! return 0;
//! } //! }
//! ``` //! ```

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `Packet`s //! C functions for interacting with `SPPacket`s
//! //!
//! prefix `sp_packet_` //! prefix `sp_packet_`
@ -9,17 +9,17 @@ use crate::SPCommand;
/// The raw packet /// The raw packet
pub struct SPPacket(pub(crate) servicepoint::Packet); pub struct SPPacket(pub(crate) servicepoint::Packet);
/// Turns a `Command` into a `Packet`. /// Turns a `SPCommand` into a `SPPacket`.
/// The `Command` gets consumed. /// The `SPCommand` gets consumed.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `command` points to a valid instance of `Command` /// - `SPCommand` points to a valid instance of `SPCommand`
/// - `command` is not used concurrently or after this call /// - `SPCommand` is not used concurrently or after this call
/// - the returned `Packet` instance is freed in some way, either by using a consuming function or /// - the returned `SPPacket` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_dealloc`. /// by explicitly calling `sp_packet_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_packet_from_command( pub unsafe extern "C" fn sp_packet_from_command(
command: *mut SPCommand, command: *mut SPCommand,
@ -29,7 +29,7 @@ pub unsafe extern "C" fn sp_packet_from_command(
Box::into_raw(Box::new(packet)) Box::into_raw(Box::new(packet))
} }
/// Tries to load a `Packet` from the passed array with the specified length. /// Tries to load a `SPPacket` from the passed array with the specified length.
/// ///
/// returns: NULL in case of an error, pointer to the allocated packet otherwise /// returns: NULL in case of an error, pointer to the allocated packet otherwise
/// ///
@ -39,8 +39,8 @@ pub unsafe extern "C" fn sp_packet_from_command(
/// ///
/// - `data` points to a valid memory region of at least `length` bytes /// - `data` points to a valid memory region of at least `length` bytes
/// - `data` is not written to concurrently /// - `data` is not written to concurrently
/// - the returned `Packet` instance is freed in some way, either by using a consuming function or /// - the returned `SPPacket` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_dealloc`. /// by explicitly calling `sp_packet_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_packet_try_load( pub unsafe extern "C" fn sp_packet_try_load(
data: *const u8, data: *const u8,
@ -53,16 +53,16 @@ pub unsafe extern "C" fn sp_packet_try_load(
} }
} }
/// Clones a `Packet`. /// Clones a `SPPacket`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Packet` /// - `this` points to a valid `SPPacket`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_dealloc`. /// by explicitly calling `sp_packet_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_packet_clone( pub unsafe extern "C" fn sp_packet_clone(
this: *const SPPacket, this: *const SPPacket,
@ -70,15 +70,15 @@ pub unsafe extern "C" fn sp_packet_clone(
Box::into_raw(Box::new(SPPacket((*this).0.clone()))) Box::into_raw(Box::new(SPPacket((*this).0.clone())))
} }
/// Deallocates a `Packet`. /// Deallocates a `SPPacket`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `Packet` /// - `this` points to a valid `SPPacket`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_packet_dealloc(this: *mut SPPacket) { pub unsafe extern "C" fn sp_packet_free(this: *mut SPPacket) {
_ = Box::from_raw(this) _ = Box::from_raw(this)
} }

View file

@ -1,4 +1,4 @@
//! C functions for interacting with `PixelGrid`s //! C functions for interacting with `SPPixelGrid`s
//! //!
//! prefix `sp_pixel_grid_` //! prefix `sp_pixel_grid_`
@ -14,18 +14,18 @@ use crate::byte_slice::SPByteSlice;
/// Cp437Grid grid = sp_pixel_grid_new(8, 3); /// Cp437Grid grid = sp_pixel_grid_new(8, 3);
/// sp_pixel_grid_fill(grid, true); /// sp_pixel_grid_fill(grid, true);
/// sp_pixel_grid_set(grid, 0, 0, false); /// sp_pixel_grid_set(grid, 0, 0, false);
/// sp_pixel_grid_dealloc(grid); /// sp_pixel_grid_free(grid);
/// ``` /// ```
pub struct SPPixelGrid(pub(crate) servicepoint::PixelGrid); pub struct SPPixelGrid(pub(crate) servicepoint::PixelGrid);
/// Creates a new `PixelGrid` with the specified dimensions. /// Creates a new `SPPixelGrid` with the specified dimensions.
/// ///
/// # Arguments /// # Arguments
/// ///
/// - `width`: size in pixels in x-direction /// - `width`: size in pixels in x-direction
/// - `height`: size in pixels in y-direction /// - `height`: size in pixels in y-direction
/// ///
/// returns: `PixelGrid` initialized to all pixels off /// returns: `SPPixelGrid` initialized to all pixels off
/// ///
/// # Panics /// # Panics
/// ///
@ -36,7 +36,7 @@ pub struct SPPixelGrid(pub(crate) servicepoint::PixelGrid);
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_pixel_grid_dealloc`. /// by explicitly calling `sp_pixel_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_new( pub unsafe extern "C" fn sp_pixel_grid_new(
width: usize, width: usize,
@ -47,14 +47,14 @@ pub unsafe extern "C" fn sp_pixel_grid_new(
)))) ))))
} }
/// Loads a `PixelGrid` with the specified dimensions from the provided data. /// Loads a `SPPixelGrid` with the specified dimensions from the provided data.
/// ///
/// # Arguments /// # Arguments
/// ///
/// - `width`: size in pixels in x-direction /// - `width`: size in pixels in x-direction
/// - `height`: size in pixels in y-direction /// - `height`: size in pixels in y-direction
/// ///
/// returns: `PixelGrid` that contains a copy of the provided data /// returns: `SPPixelGrid` that contains a copy of the provided data
/// ///
/// # Panics /// # Panics
/// ///
@ -67,7 +67,7 @@ pub unsafe extern "C" fn sp_pixel_grid_new(
/// ///
/// - `data` points to a valid memory location of at least `data_length` bytes in size. /// - `data` points to a valid memory location of at least `data_length` bytes in size.
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_pixel_grid_dealloc`. /// by explicitly calling `sp_pixel_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_load( pub unsafe extern "C" fn sp_pixel_grid_load(
width: usize, width: usize,
@ -81,16 +81,16 @@ pub unsafe extern "C" fn sp_pixel_grid_load(
)))) ))))
} }
/// Clones a `PixelGrid`. /// Clones a `SPPixelGrid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or /// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_pixel_grid_dealloc`. /// by explicitly calling `sp_pixel_grid_free`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_clone( pub unsafe extern "C" fn sp_pixel_grid_clone(
this: *const SPPixelGrid, this: *const SPPixelGrid,
@ -98,21 +98,21 @@ pub unsafe extern "C" fn sp_pixel_grid_clone(
Box::into_raw(Box::new(SPPixelGrid((*this).0.clone()))) Box::into_raw(Box::new(SPPixelGrid((*this).0.clone())))
} }
/// Deallocates a `PixelGrid`. /// Deallocates a `SPPixelGrid`.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - `this` is not used concurrently or after this call /// - `this` is not used concurrently or after this call
/// - `this` was not passed to another consuming function, e.g. to create a `Command` /// - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_dealloc(this: *mut SPPixelGrid) { pub unsafe extern "C" fn sp_pixel_grid_free(this: *mut SPPixelGrid) {
_ = Box::from_raw(this); _ = Box::from_raw(this);
} }
/// Gets the current value at the specified position in the `PixelGrid`. /// Gets the current value at the specified position in the `SPPixelGrid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -127,7 +127,7 @@ pub unsafe extern "C" fn sp_pixel_grid_dealloc(this: *mut SPPixelGrid) {
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - `this` is not written to concurrently /// - `this` is not written to concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_get( pub unsafe extern "C" fn sp_pixel_grid_get(
@ -138,7 +138,7 @@ pub unsafe extern "C" fn sp_pixel_grid_get(
(*this).0.get(x, y) (*this).0.get(x, y)
} }
/// Sets the value of the specified position in the `PixelGrid`. /// Sets the value of the specified position in the `SPPixelGrid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -156,7 +156,7 @@ pub unsafe extern "C" fn sp_pixel_grid_get(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_set( pub unsafe extern "C" fn sp_pixel_grid_set(
@ -168,7 +168,7 @@ pub unsafe extern "C" fn sp_pixel_grid_set(
(*this).0.set(x, y, value); (*this).0.set(x, y, value);
} }
/// Sets the state of all pixels in the `PixelGrid`. /// Sets the state of all pixels in the `SPPixelGrid`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -179,7 +179,7 @@ pub unsafe extern "C" fn sp_pixel_grid_set(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - `this` is not written to or read from concurrently /// - `this` is not written to or read from concurrently
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_fill( pub unsafe extern "C" fn sp_pixel_grid_fill(
@ -189,7 +189,7 @@ pub unsafe extern "C" fn sp_pixel_grid_fill(
(*this).0.fill(value); (*this).0.fill(value);
} }
/// Gets the width in pixels of the `PixelGrid` instance. /// Gets the width in pixels of the `SPPixelGrid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -199,7 +199,7 @@ pub unsafe extern "C" fn sp_pixel_grid_fill(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_width( pub unsafe extern "C" fn sp_pixel_grid_width(
this: *const SPPixelGrid, this: *const SPPixelGrid,
@ -207,7 +207,7 @@ pub unsafe extern "C" fn sp_pixel_grid_width(
(*this).0.width() (*this).0.width()
} }
/// Gets the height in pixels of the `PixelGrid` instance. /// Gets the height in pixels of the `SPPixelGrid` instance.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -217,7 +217,7 @@ pub unsafe extern "C" fn sp_pixel_grid_width(
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_height( pub unsafe extern "C" fn sp_pixel_grid_height(
this: *const SPPixelGrid, this: *const SPPixelGrid,
@ -225,15 +225,15 @@ pub unsafe extern "C" fn sp_pixel_grid_height(
(*this).0.height() (*this).0.height()
} }
/// Gets an unsafe reference to the data of the `PixelGrid` instance. /// Gets an unsafe reference to the data of the `SPPixelGrid` instance.
/// ///
/// ## Safety /// ## Safety
/// ///
/// The caller has to make sure that: /// The caller has to make sure that:
/// ///
/// - `this` points to a valid `PixelGrid` /// - `this` points to a valid `SPPixelGrid`
/// - the returned memory range is never accessed after the passed `PixelGrid` has been freed /// - 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 `PixelGrid` or directly /// - the returned memory range is never accessed concurrently, either via the `SPPixelGrid` or directly
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_pixel_grid_unsafe_data_ref( pub unsafe extern "C" fn sp_pixel_grid_unsafe_data_ref(
this: *mut SPPixelGrid, this: *mut SPPixelGrid,

View file

@ -84,8 +84,5 @@ public sealed class BitVec : SpNativeInstance<BindGen.BitVec>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_bit_vec_free(Instance);
{
NativeMethods.sp_bit_vec_dealloc(Instance);
}
} }

View file

@ -96,8 +96,5 @@ public sealed class BrightnessGrid : SpNativeInstance<BindGen.BrightnessGrid>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_brightness_grid_free(Instance);
{
NativeMethods.sp_brightness_grid_dealloc(Instance);
}
} }

View file

@ -125,8 +125,5 @@ public sealed class Command : SpNativeInstance<BindGen.Command>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_command_free(Instance);
{
NativeMethods.sp_command_dealloc(Instance);
}
} }

View file

@ -24,10 +24,7 @@ public sealed class Connection : SpNativeInstance<BindGen.Connection>
} }
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_connection_free(Instance);
{
NativeMethods.sp_connection_dealloc(Instance);
}
private unsafe Connection(BindGen.Connection* instance) : base(instance) private unsafe Connection(BindGen.Connection* instance) : base(instance)
{ {

View file

@ -127,8 +127,5 @@ public sealed class Cp437Grid : SpNativeInstance<BindGen.Cp437Grid>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_cp437_grid_free(Instance);
{
NativeMethods.sp_cp437_grid_dealloc(Instance);
}
} }

View file

@ -32,8 +32,5 @@ public sealed class Packet : SpNativeInstance<BindGen.Packet>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_packet_free(Instance);
{
NativeMethods.sp_packet_dealloc(Instance);
}
} }

View file

@ -96,8 +96,5 @@ public sealed class PixelGrid : SpNativeInstance<BindGen.PixelGrid>
{ {
} }
private protected override unsafe void Dealloc() private protected override unsafe void Free() => NativeMethods.sp_pixel_grid_free(Instance);
{
NativeMethods.sp_pixel_grid_dealloc(Instance);
}
} }

View file

@ -22,7 +22,7 @@ public abstract class SpNativeInstance<T>
_instance = instance; _instance = instance;
} }
private protected abstract void Dealloc(); private protected abstract void Free();
internal unsafe T* Into() internal unsafe T* Into()
{ {
@ -34,7 +34,7 @@ public abstract class SpNativeInstance<T>
private unsafe void ReleaseUnmanagedResources() private unsafe void ReleaseUnmanagedResources()
{ {
if (_instance != null) if (_instance != null)
Dealloc(); Free();
_instance = null; _instance = null;
} }