mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 10:00:14 +01:00
rename _dealloc to _free
This commit is contained in:
parent
f45c8090ec
commit
aa359cc807
|
@ -28,8 +28,8 @@ int main(void) {
|
|||
SPPacket *packet = sp_packet_from_command(command);
|
||||
while (sp_connection_send(connection, sp_packet_clone(packet)));
|
||||
|
||||
sp_packet_dealloc(packet);
|
||||
sp_connection_dealloc(connection);
|
||||
sp_packet_free(packet);
|
||||
sp_connection_free(connection);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -13,7 +13,7 @@ int main(void) {
|
|||
SPPacket *packet = sp_packet_from_command(command);
|
||||
while (sp_connection_send(connection, sp_packet_clone(packet)));
|
||||
|
||||
sp_packet_dealloc(packet);
|
||||
sp_connection_dealloc(connection);
|
||||
sp_packet_free(packet);
|
||||
sp_connection_free(connection);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `BitVec`s
|
||||
//! C functions for interacting with `SPBitVec`s
|
||||
//!
|
||||
//! prefix `sp_bit_vec_`
|
||||
|
||||
|
@ -11,7 +11,7 @@ use servicepoint::bitvec::prelude::{BitVec, Msb0};
|
|||
/// ```C
|
||||
/// SPBitVec vec = sp_bit_vec_new(8);
|
||||
/// sp_bit_vec_set(vec, 5, true);
|
||||
/// sp_bit_vec_dealloc(vec);
|
||||
/// sp_bit_vec_free(vec);
|
||||
/// ```
|
||||
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
|
||||
///
|
||||
/// - `size`: size in bits.
|
||||
///
|
||||
/// returns: `BitVec` with all bits set to false.
|
||||
/// returns: `SPBitVec` with all bits set to false.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -50,13 +50,13 @@ impl Clone for SPBitVec {
|
|||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_bit_vec_new(size: usize) -> *mut SPBitVec {
|
||||
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
|
||||
///
|
||||
|
@ -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`
|
||||
/// bytes in size.
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_bit_vec_load(
|
||||
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))))
|
||||
}
|
||||
|
||||
/// Clones a `BitVec`.
|
||||
/// Clones a `SPBitVec`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_bit_vec_clone(
|
||||
this: *const SPBitVec,
|
||||
|
@ -92,21 +92,21 @@ pub unsafe extern "C" fn sp_bit_vec_clone(
|
|||
Box::into_raw(Box::new((*this).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `BitVec`.
|
||||
/// Deallocates a `SPBitVec`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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` 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]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Gets the value of a bit from the `BitVec`.
|
||||
/// Gets the value of a bit from the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -123,7 +123,7 @@ pub unsafe extern "C" fn sp_bit_vec_dealloc(this: *mut SPBitVec) {
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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()
|
||||
}
|
||||
|
||||
/// Sets the value of a bit in the `BitVec`.
|
||||
/// Sets the value of a bit in the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -151,7 +151,7 @@ pub unsafe extern "C" fn sp_bit_vec_get(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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)
|
||||
}
|
||||
|
||||
/// Sets the value of all bits in the `BitVec`.
|
||||
/// Sets the value of all bits in the `SPBitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -172,20 +172,20 @@ pub unsafe extern "C" fn sp_bit_vec_set(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_fill(this: *mut SPBitVec, value: bool) {
|
||||
(*this).0.fill(value)
|
||||
}
|
||||
|
||||
/// Gets the length of the `BitVec` in bits.
|
||||
/// Gets the length of the `SPBitVec` in bits.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `BitVec`
|
||||
/// - `this` points to a valid `SPBitVec`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bit_vec_len(this: *const SPBitVec) -> usize {
|
||||
(*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:
|
||||
///
|
||||
/// - `this` points to a valid `BitVec`
|
||||
/// - `this` 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()
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the `BitVec` instance.
|
||||
/// Gets an unsafe reference to the data of the `SPBitVec` instance.
|
||||
///
|
||||
/// ## Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `BitVec`
|
||||
/// - the returned memory range is never accessed after the passed `BitVec` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `BitVec` or directly
|
||||
/// - `this` 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,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `BrightnessGrid`s
|
||||
//! C functions for interacting with `SPBrightnessGrid`s
|
||||
//!
|
||||
//! prefix `sp_brightness_grid_`
|
||||
|
||||
|
@ -19,7 +19,7 @@ use std::intrinsics::transmute;
|
|||
/// sp_brightness_grid_set(grid, 1, 1, 10);
|
||||
///
|
||||
/// SPCommand command = sp_command_char_brightness(grid);
|
||||
/// sp_connection_dealloc(connection);
|
||||
/// sp_connection_free(connection);
|
||||
/// ```
|
||||
pub struct SPBrightnessGrid {
|
||||
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
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_new(
|
||||
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
|
||||
///
|
||||
|
@ -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`
|
||||
/// bytes in size.
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_load(
|
||||
width: usize,
|
||||
|
@ -81,16 +81,16 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
|||
Box::into_raw(Box::new(SPBrightnessGrid { actual: grid }))
|
||||
}
|
||||
|
||||
/// Clones a `BrightnessGrid`.
|
||||
/// Clones a `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_clone(
|
||||
this: *const SPBrightnessGrid,
|
||||
|
@ -98,17 +98,17 @@ pub unsafe extern "C" fn sp_brightness_grid_clone(
|
|||
Box::into_raw(Box::new((*this).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `BrightnessGrid`.
|
||||
/// Deallocates a `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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` 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]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_dealloc(
|
||||
pub unsafe extern "C" fn sp_brightness_grid_free(
|
||||
this: *mut SPBrightnessGrid,
|
||||
) {
|
||||
_ = Box::from_raw(this);
|
||||
|
@ -129,7 +129,7 @@ pub unsafe extern "C" fn sp_brightness_grid_dealloc(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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()
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `BrightnessGrid`.
|
||||
/// Sets the value of the specified position in the `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -159,7 +159,7 @@ pub unsafe extern "C" fn sp_brightness_grid_get(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Sets the value of all cells in the `BrightnessGrid`.
|
||||
/// Sets the value of all cells in the `SPBrightnessGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -188,7 +188,7 @@ pub unsafe extern "C" fn sp_brightness_grid_set(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Gets the width of the `BrightnessGrid` instance.
|
||||
/// Gets the width of the `SPBrightnessGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -210,7 +210,7 @@ pub unsafe extern "C" fn sp_brightness_grid_fill(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `BrightnessGrid`
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_width(
|
||||
this: *const SPBrightnessGrid,
|
||||
|
@ -218,7 +218,7 @@ pub unsafe extern "C" fn sp_brightness_grid_width(
|
|||
(*this).actual.width()
|
||||
}
|
||||
|
||||
/// Gets the height of the `BrightnessGrid` instance.
|
||||
/// Gets the height of the `SPBrightnessGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -228,7 +228,7 @@ pub unsafe extern "C" fn sp_brightness_grid_width(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `BrightnessGrid`
|
||||
/// - `this` points to a valid `SPBrightnessGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_height(
|
||||
this: *const SPBrightnessGrid,
|
||||
|
@ -236,15 +236,15 @@ pub unsafe extern "C" fn sp_brightness_grid_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
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `BrightnessGrid`
|
||||
/// - the returned memory range is never accessed after the passed `BrightnessGrid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `BrightnessGrid` or directly
|
||||
/// - `this` 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,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `Command`s
|
||||
//! C functions for interacting with `SPCommand`s
|
||||
//!
|
||||
//! prefix `sp_command_`
|
||||
|
||||
|
@ -39,11 +39,11 @@ impl Clone for SPCommand {
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `packet` points to a valid instance of `SPPacket`
|
||||
/// - `packet` is not used concurrently or after this call
|
||||
/// - `SPPacket` points to a valid instance of `SPPacket`
|
||||
/// - `SPPacket` is not used concurrently or after this call
|
||||
/// - the result is checked for NULL
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_command_try_from_packet(
|
||||
packet: *mut SPPacket,
|
||||
|
@ -61,10 +61,10 @@ pub unsafe extern "C" fn sp_command_try_from_packet(
|
|||
///
|
||||
/// 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
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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,
|
||||
|
@ -86,8 +86,8 @@ pub unsafe extern "C" fn sp_command_clone(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_clear() -> *mut SPCommand {
|
||||
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 returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_hard_reset() -> *mut SPCommand {
|
||||
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 returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_fade_out() -> *mut SPCommand {
|
||||
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 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]
|
||||
pub unsafe extern "C" fn sp_command_brightness(
|
||||
brightness: u8,
|
||||
|
@ -157,8 +157,8 @@ pub unsafe extern "C" fn sp_command_brightness(
|
|||
///
|
||||
/// - `grid` points to a valid instance of `SPBrightnessGrid`
|
||||
/// - `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
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_char_brightness(
|
||||
x: usize,
|
||||
|
@ -173,24 +173,24 @@ pub unsafe extern "C" fn sp_command_char_brightness(
|
|||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// The contained `BitVec` is always uncompressed.
|
||||
/// The contained `SPBitVec` is always uncompressed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - `compression` matches one of the allowed enum values
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_bitmap_linear(
|
||||
offset: usize,
|
||||
|
@ -206,24 +206,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
|
|||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// The contained `BitVec` is always uncompressed.
|
||||
/// The contained `SPBitVec` is always uncompressed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - `compression` matches one of the allowed enum values
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_bitmap_linear_and(
|
||||
offset: usize,
|
||||
|
@ -239,24 +239,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
|||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// The contained `BitVec` is always uncompressed.
|
||||
/// The contained `SPBitVec` is always uncompressed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - `compression` matches one of the allowed enum values
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_bitmap_linear_or(
|
||||
offset: usize,
|
||||
|
@ -272,24 +272,24 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
|||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// The contained `BitVec` is always uncompressed.
|
||||
/// The contained `SPBitVec` is always uncompressed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - `compression` matches one of the allowed enum values
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_bitmap_linear_xor(
|
||||
offset: usize,
|
||||
|
@ -305,7 +305,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
|||
}
|
||||
|
||||
/// Allocates a new `Command::Cp437Data` instance.
|
||||
/// The passed `ByteGrid` gets consumed.
|
||||
/// The passed `SPCp437Grid` gets consumed.
|
||||
///
|
||||
/// 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:
|
||||
///
|
||||
/// - `byte_grid` points to a valid instance of `ByteGrid`
|
||||
/// - `byte_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
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - `grid` points to a valid instance of `SPCp437Grid`
|
||||
/// - `grid` is not used concurrently or after this call
|
||||
/// - 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_cp437_data(
|
||||
x: usize,
|
||||
y: usize,
|
||||
byte_grid: *mut SPCp437Grid,
|
||||
grid: *mut SPCp437Grid,
|
||||
) -> *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(
|
||||
Origin::new(x, y),
|
||||
byte_grid.actual,
|
||||
grid.actual,
|
||||
))))
|
||||
}
|
||||
|
||||
/// 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
|
||||
///
|
||||
|
@ -344,11 +344,11 @@ pub unsafe extern "C" fn sp_command_cp437_data(
|
|||
///
|
||||
/// 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
|
||||
/// - `compression` matches one of the allowed enum values
|
||||
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_command_dealloc`.
|
||||
/// - 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_bitmap_linear_win(
|
||||
x: usize,
|
||||
|
@ -366,23 +366,23 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
|
|||
))))
|
||||
}
|
||||
|
||||
/// Deallocates a `Command`.
|
||||
/// Deallocates a `SPCommand`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// SPCommand c = sp_command_clear();
|
||||
/// sp_command_dealloc(c);
|
||||
/// sp_command_free(c);
|
||||
/// ```
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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` 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]
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `Connection`s
|
||||
//! C functions for interacting with `SPConnection`s
|
||||
//!
|
||||
//! prefix `sp_connection_`
|
||||
|
||||
|
@ -18,7 +18,7 @@ use crate::SPPacket;
|
|||
/// ```
|
||||
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
|
||||
///
|
||||
|
@ -31,7 +31,7 @@ pub struct SPConnection(pub(crate) servicepoint::Connection);
|
|||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_connection_open(
|
||||
host: *const c_char,
|
||||
|
@ -45,8 +45,8 @@ pub unsafe extern "C" fn sp_connection_open(
|
|||
Box::into_raw(Box::new(SPConnection(connection)))
|
||||
}
|
||||
|
||||
/// Sends a `Packet` to the display using the `Connection`.
|
||||
/// The passed `Packet` gets consumed.
|
||||
/// Sends a `SPPacket` to the display using the `SPConnection`.
|
||||
/// The passed `SPPacket` gets consumed.
|
||||
///
|
||||
/// 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:
|
||||
///
|
||||
/// - `connection` points to a valid instance of `Connection`
|
||||
/// - `packet` points to a valid instance of `Packet`
|
||||
/// - `packet` is not used concurrently or after this call
|
||||
/// - `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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_connection_send(
|
||||
connection: *const SPConnection,
|
||||
|
@ -66,15 +66,15 @@ pub unsafe extern "C" fn sp_connection_send(
|
|||
(*connection).0.send((*packet).0).is_ok()
|
||||
}
|
||||
|
||||
/// Closes and deallocates a `Connection`.
|
||||
/// Closes and deallocates a `SPConnection`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
#[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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `Cp437Grid`s
|
||||
//! C functions for interacting with `SPCp437Grid`s
|
||||
//!
|
||||
//! prefix `sp_cp437_grid_`
|
||||
|
||||
|
@ -15,7 +15,7 @@ use servicepoint::{DataRef, Grid};
|
|||
/// Cp437Grid grid = sp_cp437_grid_new(4, 3);
|
||||
/// sp_cp437_grid_fill(grid, '?');
|
||||
/// sp_cp437_grid_set(grid, 0, 0, '!');
|
||||
/// sp_cp437_grid_dealloc(grid);
|
||||
/// sp_cp437_grid_free(grid);
|
||||
/// ```
|
||||
pub struct SPCp437Grid {
|
||||
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
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_new(
|
||||
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
|
||||
///
|
||||
|
@ -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`
|
||||
/// bytes in size.
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_load(
|
||||
width: usize,
|
||||
|
@ -76,16 +76,16 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
|
|||
}))
|
||||
}
|
||||
|
||||
/// Clones a `Cp437Grid`.
|
||||
/// Clones a `SPCp437Grid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_clone(
|
||||
this: *const SPCp437Grid,
|
||||
|
@ -93,17 +93,17 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
|
|||
Box::into_raw(Box::new((*this).clone()))
|
||||
}
|
||||
|
||||
/// Deallocates a `Cp437Grid`.
|
||||
/// Deallocates a `SPCp437Grid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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` 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]
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ pub unsafe extern "C" fn sp_cp437_grid_dealloc(this: *mut SPCp437Grid) {
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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)
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `Cp437Grid`.
|
||||
/// Sets the value of the specified position in the `SPCp437Grid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -151,7 +151,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Sets the value of all cells in the `Cp437Grid`.
|
||||
/// Sets the value of all cells in the `SPCp437Grid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -174,14 +174,14 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut SPCp437Grid, value: u8) {
|
||||
(*this).actual.fill(value);
|
||||
}
|
||||
|
||||
/// Gets the width of the `Cp437Grid` instance.
|
||||
/// Gets the width of the `SPCp437Grid` instance.
|
||||
///
|
||||
/// # 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:
|
||||
///
|
||||
/// - `this` points to a valid `Cp437Grid`
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_width(
|
||||
this: *const SPCp437Grid,
|
||||
|
@ -199,7 +199,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
|
|||
(*this).actual.width()
|
||||
}
|
||||
|
||||
/// Gets the height of the `Cp437Grid` instance.
|
||||
/// Gets the height of the `SPCp437Grid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -209,7 +209,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `Cp437Grid`
|
||||
/// - `this` points to a valid `SPCp437Grid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_height(
|
||||
this: *const SPCp437Grid,
|
||||
|
@ -217,15 +217,15 @@ pub unsafe extern "C" fn sp_cp437_grid_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
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `Cp437Grid`
|
||||
/// - the returned memory range is never accessed after the passed `Cp437Grid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `Cp437Grid` or directly
|
||||
/// - `this` 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,
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
//! SPPacket *packet = sp_packet_from_command(command);
|
||||
//! while (sp_connection_send(connection, sp_packet_clone(packet)));
|
||||
//!
|
||||
//! sp_packet_dealloc(packet);
|
||||
//! sp_connection_dealloc(connection);
|
||||
//! sp_packet_free(packet);
|
||||
//! sp_connection_free(connection);
|
||||
//! return 0;
|
||||
//! }
|
||||
//! ```
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `Packet`s
|
||||
//! C functions for interacting with `SPPacket`s
|
||||
//!
|
||||
//! prefix `sp_packet_`
|
||||
|
||||
|
@ -9,17 +9,17 @@ use crate::SPCommand;
|
|||
/// The raw packet
|
||||
pub struct SPPacket(pub(crate) servicepoint::Packet);
|
||||
|
||||
/// Turns a `Command` into a `Packet`.
|
||||
/// The `Command` gets consumed.
|
||||
/// Turns a `SPCommand` into a `SPPacket`.
|
||||
/// The `SPCommand` gets consumed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `command` points to a valid instance of `Command`
|
||||
/// - `command` is not used concurrently or after this call
|
||||
/// - the returned `Packet` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_packet_dealloc`.
|
||||
/// - `SPCommand` points to a valid instance of `SPCommand`
|
||||
/// - `SPCommand` is not used concurrently or after this call
|
||||
/// - the returned `SPPacket` 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_from_command(
|
||||
command: *mut SPCommand,
|
||||
|
@ -29,7 +29,7 @@ pub unsafe extern "C" fn sp_packet_from_command(
|
|||
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
|
||||
///
|
||||
|
@ -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` is not written to concurrently
|
||||
/// - the returned `Packet` instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_packet_dealloc`.
|
||||
/// - the returned `SPPacket` 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_try_load(
|
||||
data: *const u8,
|
||||
|
@ -53,16 +53,16 @@ pub unsafe extern "C" fn sp_packet_try_load(
|
|||
}
|
||||
}
|
||||
|
||||
/// Clones a `Packet`.
|
||||
/// Clones a `SPPacket`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_packet_clone(
|
||||
this: *const SPPacket,
|
||||
|
@ -70,15 +70,15 @@ pub unsafe extern "C" fn sp_packet_clone(
|
|||
Box::into_raw(Box::new(SPPacket((*this).0.clone())))
|
||||
}
|
||||
|
||||
/// Deallocates a `Packet`.
|
||||
/// Deallocates a `SPPacket`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
#[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)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! C functions for interacting with `PixelGrid`s
|
||||
//! C functions for interacting with `SPPixelGrid`s
|
||||
//!
|
||||
//! prefix `sp_pixel_grid_`
|
||||
|
||||
|
@ -14,18 +14,18 @@ use crate::byte_slice::SPByteSlice;
|
|||
/// Cp437Grid grid = sp_pixel_grid_new(8, 3);
|
||||
/// sp_pixel_grid_fill(grid, true);
|
||||
/// 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);
|
||||
|
||||
/// Creates a new `PixelGrid` with the specified dimensions.
|
||||
/// Creates a new `SPPixelGrid` with the specified dimensions.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `width`: size in pixels in x-direction
|
||||
/// - `height`: size in pixels in y-direction
|
||||
///
|
||||
/// returns: `PixelGrid` initialized to all pixels off
|
||||
/// returns: `SPPixelGrid` initialized to all pixels off
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -36,7 +36,7 @@ pub struct SPPixelGrid(pub(crate) servicepoint::PixelGrid);
|
|||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_new(
|
||||
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
|
||||
///
|
||||
/// - `width`: size in pixels in x-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
|
||||
///
|
||||
|
@ -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.
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_load(
|
||||
width: usize,
|
||||
|
@ -81,16 +81,16 @@ pub unsafe extern "C" fn sp_pixel_grid_load(
|
|||
))))
|
||||
}
|
||||
|
||||
/// Clones a `PixelGrid`.
|
||||
/// Clones a `SPPixelGrid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// - 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]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_clone(
|
||||
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())))
|
||||
}
|
||||
|
||||
/// Deallocates a `PixelGrid`.
|
||||
/// Deallocates a `SPPixelGrid`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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` 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]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Gets the current value at the specified position in the `PixelGrid`.
|
||||
/// Gets the current value at the specified position in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -127,7 +127,7 @@ pub unsafe extern "C" fn sp_pixel_grid_dealloc(this: *mut SPPixelGrid) {
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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)
|
||||
}
|
||||
|
||||
/// Sets the value of the specified position in the `PixelGrid`.
|
||||
/// Sets the value of the specified position in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -156,7 +156,7 @@ pub unsafe extern "C" fn sp_pixel_grid_get(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Sets the state of all pixels in the `PixelGrid`.
|
||||
/// Sets the state of all pixels in the `SPPixelGrid`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -179,7 +179,7 @@ pub unsafe extern "C" fn sp_pixel_grid_set(
|
|||
///
|
||||
/// 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
|
||||
#[no_mangle]
|
||||
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);
|
||||
}
|
||||
|
||||
/// Gets the width in pixels of the `PixelGrid` instance.
|
||||
/// Gets the width in pixels of the `SPPixelGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -199,7 +199,7 @@ pub unsafe extern "C" fn sp_pixel_grid_fill(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `PixelGrid`
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_width(
|
||||
this: *const SPPixelGrid,
|
||||
|
@ -207,7 +207,7 @@ pub unsafe extern "C" fn sp_pixel_grid_width(
|
|||
(*this).0.width()
|
||||
}
|
||||
|
||||
/// Gets the height in pixels of the `PixelGrid` instance.
|
||||
/// Gets the height in pixels of the `SPPixelGrid` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -217,7 +217,7 @@ pub unsafe extern "C" fn sp_pixel_grid_width(
|
|||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `PixelGrid`
|
||||
/// - `this` points to a valid `SPPixelGrid`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_pixel_grid_height(
|
||||
this: *const SPPixelGrid,
|
||||
|
@ -225,15 +225,15 @@ pub unsafe extern "C" fn sp_pixel_grid_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
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `this` points to a valid `PixelGrid`
|
||||
/// - the returned memory range is never accessed after the passed `PixelGrid` has been freed
|
||||
/// - the returned memory range is never accessed concurrently, either via the `PixelGrid` or directly
|
||||
/// - `this` 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,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -84,8 +84,5 @@ public sealed class BitVec : SpNativeInstance<BindGen.BitVec>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_bit_vec_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_bit_vec_free(Instance);
|
||||
}
|
||||
|
|
|
@ -96,8 +96,5 @@ public sealed class BrightnessGrid : SpNativeInstance<BindGen.BrightnessGrid>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_brightness_grid_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_brightness_grid_free(Instance);
|
||||
}
|
||||
|
|
|
@ -125,8 +125,5 @@ public sealed class Command : SpNativeInstance<BindGen.Command>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_command_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_command_free(Instance);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,7 @@ public sealed class Connection : SpNativeInstance<BindGen.Connection>
|
|||
}
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_connection_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_connection_free(Instance);
|
||||
|
||||
private unsafe Connection(BindGen.Connection* instance) : base(instance)
|
||||
{
|
||||
|
|
|
@ -127,8 +127,5 @@ public sealed class Cp437Grid : SpNativeInstance<BindGen.Cp437Grid>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_cp437_grid_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_cp437_grid_free(Instance);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,5 @@ public sealed class Packet : SpNativeInstance<BindGen.Packet>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_packet_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_packet_free(Instance);
|
||||
}
|
||||
|
|
|
@ -96,8 +96,5 @@ public sealed class PixelGrid : SpNativeInstance<BindGen.PixelGrid>
|
|||
{
|
||||
}
|
||||
|
||||
private protected override unsafe void Dealloc()
|
||||
{
|
||||
NativeMethods.sp_pixel_grid_dealloc(Instance);
|
||||
}
|
||||
private protected override unsafe void Free() => NativeMethods.sp_pixel_grid_free(Instance);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public abstract class SpNativeInstance<T>
|
|||
_instance = instance;
|
||||
}
|
||||
|
||||
private protected abstract void Dealloc();
|
||||
private protected abstract void Free();
|
||||
|
||||
internal unsafe T* Into()
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ public abstract class SpNativeInstance<T>
|
|||
private unsafe void ReleaseUnmanagedResources()
|
||||
{
|
||||
if (_instance != null)
|
||||
Dealloc();
|
||||
Free();
|
||||
_instance = null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue