remove SPBitVec wrapper type
Some checks failed
Rust / build-gnu-apt (pull_request) Failing after 1m19s
Rust / build-size-gnu-unstable (pull_request) Failing after 1m9s

This commit is contained in:
Vinzenz Schroeter 2025-05-06 23:05:06 +02:00
parent 85ccf4123c
commit a4bacd53a2
5 changed files with 48 additions and 74 deletions

View file

@ -1,9 +1,6 @@
use crate::{
bitvec::SPBitVec, byte_slice::ByteSlice, heap_clone, heap_drop,
heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove,
};
use crate::{byte_slice::ByteSlice, heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove};
use servicepoint::{
Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet,
Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet, DisplayBitVec
};
use std::ptr::NonNull;
@ -72,10 +69,10 @@ pub unsafe extern "C" fn sp_bitmap_load(
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_from_bitvec(
width: usize,
bitvec: NonNull<SPBitVec>,
bitvec: NonNull<DisplayBitVec>,
) -> *mut Bitmap {
let bitvec = unsafe { heap_remove(bitvec) };
heap_move_ok(Bitmap::from_bitvec(width, bitvec.0))
heap_move_ok(Bitmap::from_bitvec(width, bitvec))
}
/// Clones a [Bitmap].
@ -187,9 +184,9 @@ pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
bitmap: NonNull<Bitmap>,
) -> NonNull<SPBitVec> {
) -> NonNull<DisplayBitVec> {
let bitmap = unsafe { heap_remove(bitmap) };
heap_move_nonnull(SPBitVec(bitmap.into()))
heap_move_nonnull(bitmap.into())
}
/// Creates a [BitmapCommand] and immediately turns that into a [Packet].

View file

@ -7,22 +7,6 @@ use servicepoint::{
};
use std::ptr::NonNull;
/// A vector of bits
///
/// # Examples
/// ```C
/// SPBitVec vec = sp_bitvec_new(8);
/// sp_bitvec_set(vec, 5, true);
/// sp_bitvec_free(vec);
/// ```
pub struct SPBitVec(pub(crate) DisplayBitVec);
impl Clone for SPBitVec {
fn clone(&self) -> Self {
SPBitVec(self.0.clone())
}
}
/// Creates a new [SPBitVec] instance.
///
/// # Arguments
@ -35,30 +19,32 @@ impl Clone for SPBitVec {
///
/// - when `size` is not divisible by 8.
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> NonNull<SPBitVec> {
heap_move_nonnull(SPBitVec(DisplayBitVec::repeat(false, size)))
pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> NonNull<DisplayBitVec> {
heap_move_nonnull(DisplayBitVec::repeat(false, size))
}
/// Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
///
/// returns: [SPBitVec] instance containing data.
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_load(data: ByteSlice) -> NonNull<SPBitVec> {
pub unsafe extern "C" fn sp_bitvec_load(
data: ByteSlice,
) -> NonNull<DisplayBitVec> {
let data = unsafe { data.as_slice() };
heap_move_nonnull(SPBitVec(DisplayBitVec::from_slice(data)))
heap_move_nonnull(DisplayBitVec::from_slice(data))
}
/// Clones a [SPBitVec].
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_clone(
bit_vec: NonNull<SPBitVec>,
) -> NonNull<SPBitVec> {
bit_vec: NonNull<DisplayBitVec>,
) -> NonNull<DisplayBitVec> {
unsafe { heap_clone(bit_vec) }
}
/// Deallocates a [SPBitVec].
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: NonNull<SPBitVec>) {
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: NonNull<DisplayBitVec>) {
unsafe { heap_drop(bit_vec) }
}
@ -76,10 +62,10 @@ pub unsafe extern "C" fn sp_bitvec_free(bit_vec: NonNull<SPBitVec>) {
/// - when accessing `index` out of bounds
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_get(
bit_vec: NonNull<SPBitVec>,
bit_vec: NonNull<DisplayBitVec>,
index: usize,
) -> bool {
unsafe { *bit_vec.as_ref().0.get(index).unwrap() }
unsafe { *bit_vec.as_ref().get(index).unwrap() }
}
/// Sets the value of a bit in the [SPBitVec].
@ -95,11 +81,11 @@ pub unsafe extern "C" fn sp_bitvec_get(
/// - when accessing `index` out of bounds
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_set(
bit_vec: NonNull<SPBitVec>,
bit_vec: NonNull<DisplayBitVec>,
index: usize,
value: bool,
) {
unsafe { (*bit_vec.as_ptr()).0.set(index, value) }
unsafe { (*bit_vec.as_ptr()).set(index, value) }
}
/// Sets the value of all bits in the [SPBitVec].
@ -110,10 +96,10 @@ pub unsafe extern "C" fn sp_bitvec_set(
/// - `value`: the value to set all bits to
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_fill(
bit_vec: NonNull<SPBitVec>,
bit_vec: NonNull<DisplayBitVec>,
value: bool,
) {
unsafe { (*bit_vec.as_ptr()).0.fill(value) }
unsafe { (*bit_vec.as_ptr()).fill(value) }
}
/// Gets the length of the [SPBitVec] in bits.
@ -122,8 +108,10 @@ pub unsafe extern "C" fn sp_bitvec_fill(
///
/// - `bit_vec`: instance to write to
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_len(bit_vec: NonNull<SPBitVec>) -> usize {
unsafe { bit_vec.as_ref().0.len() }
pub unsafe extern "C" fn sp_bitvec_len(
bit_vec: NonNull<DisplayBitVec>,
) -> usize {
unsafe { bit_vec.as_ref().len() }
}
/// Returns true if length is 0.
@ -133,9 +121,9 @@ pub unsafe extern "C" fn sp_bitvec_len(bit_vec: NonNull<SPBitVec>) -> usize {
/// - `bit_vec`: instance to write to
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_is_empty(
bit_vec: NonNull<SPBitVec>,
bit_vec: NonNull<DisplayBitVec>,
) -> bool {
unsafe { bit_vec.as_ref().0.is_empty() }
unsafe { bit_vec.as_ref().is_empty() }
}
/// Gets an unsafe reference to the data of the [SPBitVec] instance.
@ -147,9 +135,9 @@ pub unsafe extern "C" fn sp_bitvec_is_empty(
/// - `bit_vec`: instance to write to
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
bit_vec: NonNull<SPBitVec>,
bit_vec: NonNull<DisplayBitVec>,
) -> ByteSlice {
unsafe { ByteSlice::from_slice((*bit_vec.as_ptr()).0.as_raw_mut_slice()) }
unsafe { ByteSlice::from_slice((*bit_vec.as_ptr()).as_raw_mut_slice()) }
}
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
@ -159,12 +147,12 @@ pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
/// Returns NULL in case of an error.
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_into_packet(
bitvec: NonNull<SPBitVec>,
bitvec: NonNull<DisplayBitVec>,
offset: usize,
operation: BinaryOperation,
compression: CompressionCode,
) -> *mut Packet {
let bitvec = unsafe { heap_remove(bitvec) }.0;
let bitvec = unsafe { heap_remove(bitvec) };
heap_move_ok(Packet::try_from(BitVecCommand {
bitvec,
offset,

View file

@ -2,7 +2,7 @@ use crate::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
};
use servicepoint::{
BitVecCommand, BitmapCommand, BitmapLegacyCommand, BrightnessGridCommand,
BitVecCommand, BitmapCommand, BrightnessGridCommand,
CharGridCommand, ClearCommand, Cp437GridCommand, FadeOutCommand,
GlobalBrightnessCommand, HardResetCommand, Packet, TypedCommand,
};
@ -19,7 +19,7 @@ pub union CommandUnion {
pub global_brightness: NonNull<GlobalBrightnessCommand>,
pub clear: NonNull<ClearCommand>,
#[allow(deprecated)]
pub bitmap_legacy: NonNull<BitmapLegacyCommand>,
pub bitmap_legacy: NonNull<servicepoint::BitmapLegacyCommand>,
pub hard_reset: NonNull<HardResetCommand>,
pub fade_out: NonNull<FadeOutCommand>,
}