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

@ -35,7 +35,6 @@ include = []
exclude = ["BitVec"] exclude = ["BitVec"]
[export.rename] [export.rename]
"SpBitVec" = "BitVec"
"SpByteSlice" = "ByteSlice" "SpByteSlice" = "ByteSlice"
"SpCommand" = "Command" "SpCommand" = "Command"

View file

@ -396,18 +396,6 @@ typedef struct HardResetCommand HardResetCommand;
*/ */
typedef struct Packet Packet; typedef struct Packet Packet;
/**
* A vector of bits
*
* # Examples
* ```C
* SPBitVec vec = sp_bitvec_new(8);
* sp_bitvec_set(vec, 5, true);
* sp_bitvec_free(vec);
* ```
*/
typedef struct SPBitVec SPBitVec;
/** /**
* This is a type only used by cbindgen to have a type for pointers. * This is a type only used by cbindgen to have a type for pointers.
*/ */
@ -634,7 +622,7 @@ void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
* *
* Returns NULL in case of error. * Returns NULL in case of error.
*/ */
Bitmap *sp_bitmap_from_bitvec(size_t width, SPBitVec */*notnull*/ bitvec); Bitmap *sp_bitmap_from_bitvec(size_t width, DisplayBitVec */*notnull*/ bitvec);
/** /**
* Gets the current value at the specified position in the [Bitmap]. * Gets the current value at the specified position in the [Bitmap].
@ -662,7 +650,7 @@ size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
/** /**
* Consumes the Bitmap and returns the contained BitVec * Consumes the Bitmap and returns the contained BitVec
*/ */
SPBitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap); DisplayBitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
/** /**
* Creates a [BitmapCommand] and immediately turns that into a [Packet]. * Creates a [BitmapCommand] and immediately turns that into a [Packet].
@ -768,7 +756,7 @@ size_t sp_bitmap_width(Bitmap */*notnull*/ bitmap);
/** /**
* Clones a [SPBitVec]. * Clones a [SPBitVec].
*/ */
SPBitVec */*notnull*/ sp_bitvec_clone(SPBitVec */*notnull*/ bit_vec); DisplayBitVec */*notnull*/ sp_bitvec_clone(DisplayBitVec */*notnull*/ bit_vec);
/** /**
* Sets the value of all bits in the [SPBitVec]. * Sets the value of all bits in the [SPBitVec].
@ -778,12 +766,12 @@ SPBitVec */*notnull*/ sp_bitvec_clone(SPBitVec */*notnull*/ bit_vec);
* - `bit_vec`: instance to write to * - `bit_vec`: instance to write to
* - `value`: the value to set all bits to * - `value`: the value to set all bits to
*/ */
void sp_bitvec_fill(SPBitVec */*notnull*/ bit_vec, bool value); void sp_bitvec_fill(DisplayBitVec */*notnull*/ bit_vec, bool value);
/** /**
* Deallocates a [SPBitVec]. * Deallocates a [SPBitVec].
*/ */
void sp_bitvec_free(SPBitVec */*notnull*/ bit_vec); void sp_bitvec_free(DisplayBitVec */*notnull*/ bit_vec);
/** /**
* Gets the value of a bit from the [SPBitVec]. * Gets the value of a bit from the [SPBitVec].
@ -799,7 +787,7 @@ void sp_bitvec_free(SPBitVec */*notnull*/ bit_vec);
* *
* - when accessing `index` out of bounds * - when accessing `index` out of bounds
*/ */
bool sp_bitvec_get(SPBitVec */*notnull*/ bit_vec, size_t index); bool sp_bitvec_get(DisplayBitVec */*notnull*/ bit_vec, size_t index);
/** /**
* Creates a [BitVecCommand] and immediately turns that into a [Packet]. * Creates a [BitVecCommand] and immediately turns that into a [Packet].
@ -808,7 +796,7 @@ bool sp_bitvec_get(SPBitVec */*notnull*/ bit_vec, size_t index);
* *
* Returns NULL in case of an error. * Returns NULL in case of an error.
*/ */
Packet *sp_bitvec_into_packet(SPBitVec */*notnull*/ bitvec, Packet *sp_bitvec_into_packet(DisplayBitVec */*notnull*/ bitvec,
size_t offset, size_t offset,
BinaryOperation operation, BinaryOperation operation,
CompressionCode compression); CompressionCode compression);
@ -820,7 +808,7 @@ Packet *sp_bitvec_into_packet(SPBitVec */*notnull*/ bitvec,
* *
* - `bit_vec`: instance to write to * - `bit_vec`: instance to write to
*/ */
bool sp_bitvec_is_empty(SPBitVec */*notnull*/ bit_vec); bool sp_bitvec_is_empty(DisplayBitVec */*notnull*/ bit_vec);
/** /**
* Gets the length of the [SPBitVec] in bits. * Gets the length of the [SPBitVec] in bits.
@ -829,14 +817,14 @@ bool sp_bitvec_is_empty(SPBitVec */*notnull*/ bit_vec);
* *
* - `bit_vec`: instance to write to * - `bit_vec`: instance to write to
*/ */
size_t sp_bitvec_len(SPBitVec */*notnull*/ bit_vec); size_t sp_bitvec_len(DisplayBitVec */*notnull*/ bit_vec);
/** /**
* Interpret the data as a series of bits and load then into a new [SPBitVec] instance. * Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
* *
* returns: [SPBitVec] instance containing data. * returns: [SPBitVec] instance containing data.
*/ */
SPBitVec */*notnull*/ sp_bitvec_load(ByteSlice data); DisplayBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
/** /**
* Creates a new [SPBitVec] instance. * Creates a new [SPBitVec] instance.
@ -851,7 +839,7 @@ SPBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
* *
* - when `size` is not divisible by 8. * - when `size` is not divisible by 8.
*/ */
SPBitVec */*notnull*/ sp_bitvec_new(size_t size); DisplayBitVec */*notnull*/ sp_bitvec_new(size_t size);
/** /**
* Sets the value of a bit in the [SPBitVec]. * Sets the value of a bit in the [SPBitVec].
@ -866,7 +854,9 @@ SPBitVec */*notnull*/ sp_bitvec_new(size_t size);
* *
* - when accessing `index` out of bounds * - when accessing `index` out of bounds
*/ */
void sp_bitvec_set(SPBitVec */*notnull*/ bit_vec, size_t index, bool value); void sp_bitvec_set(DisplayBitVec */*notnull*/ bit_vec,
size_t index,
bool value);
/** /**
* Gets an unsafe reference to the data of the [SPBitVec] instance. * Gets an unsafe reference to the data of the [SPBitVec] instance.
@ -877,7 +867,7 @@ void sp_bitvec_set(SPBitVec */*notnull*/ bit_vec, size_t index, bool value);
* *
* - `bit_vec`: instance to write to * - `bit_vec`: instance to write to
*/ */
ByteSlice sp_bitvec_unsafe_data_ref(SPBitVec */*notnull*/ bit_vec); ByteSlice sp_bitvec_unsafe_data_ref(DisplayBitVec */*notnull*/ bit_vec);
/** /**
* Clones a [BrightnessGrid]. * Clones a [BrightnessGrid].

View file

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

View file

@ -7,22 +7,6 @@ use servicepoint::{
}; };
use std::ptr::NonNull; 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. /// Creates a new [SPBitVec] instance.
/// ///
/// # Arguments /// # Arguments
@ -35,30 +19,32 @@ impl Clone for SPBitVec {
/// ///
/// - when `size` is not divisible by 8. /// - when `size` is not divisible by 8.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> NonNull<SPBitVec> { pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> NonNull<DisplayBitVec> {
heap_move_nonnull(SPBitVec(DisplayBitVec::repeat(false, size))) heap_move_nonnull(DisplayBitVec::repeat(false, size))
} }
/// Interpret the data as a series of bits and load then into a new [SPBitVec] instance. /// Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
/// ///
/// returns: [SPBitVec] instance containing data. /// returns: [SPBitVec] instance containing data.
#[no_mangle] #[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() }; let data = unsafe { data.as_slice() };
heap_move_nonnull(SPBitVec(DisplayBitVec::from_slice(data))) heap_move_nonnull(DisplayBitVec::from_slice(data))
} }
/// Clones a [SPBitVec]. /// Clones a [SPBitVec].
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_clone( pub unsafe extern "C" fn sp_bitvec_clone(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
) -> NonNull<SPBitVec> { ) -> NonNull<DisplayBitVec> {
unsafe { heap_clone(bit_vec) } unsafe { heap_clone(bit_vec) }
} }
/// Deallocates a [SPBitVec]. /// Deallocates a [SPBitVec].
#[no_mangle] #[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) } 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 /// - when accessing `index` out of bounds
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_get( pub unsafe extern "C" fn sp_bitvec_get(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
index: usize, index: usize,
) -> bool { ) -> 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]. /// 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 /// - when accessing `index` out of bounds
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_set( pub unsafe extern "C" fn sp_bitvec_set(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
index: usize, index: usize,
value: bool, 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]. /// 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 /// - `value`: the value to set all bits to
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_fill( pub unsafe extern "C" fn sp_bitvec_fill(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
value: bool, 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. /// 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 /// - `bit_vec`: instance to write to
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_len(bit_vec: NonNull<SPBitVec>) -> usize { pub unsafe extern "C" fn sp_bitvec_len(
unsafe { bit_vec.as_ref().0.len() } bit_vec: NonNull<DisplayBitVec>,
) -> usize {
unsafe { bit_vec.as_ref().len() }
} }
/// Returns true if length is 0. /// 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 /// - `bit_vec`: instance to write to
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_is_empty( pub unsafe extern "C" fn sp_bitvec_is_empty(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
) -> bool { ) -> 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. /// 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 /// - `bit_vec`: instance to write to
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref( pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
bit_vec: NonNull<SPBitVec>, bit_vec: NonNull<DisplayBitVec>,
) -> ByteSlice { ) -> 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]. /// 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. /// Returns NULL in case of an error.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn sp_bitvec_into_packet( pub unsafe extern "C" fn sp_bitvec_into_packet(
bitvec: NonNull<SPBitVec>, bitvec: NonNull<DisplayBitVec>,
offset: usize, offset: usize,
operation: BinaryOperation, operation: BinaryOperation,
compression: CompressionCode, compression: CompressionCode,
) -> *mut Packet { ) -> *mut Packet {
let bitvec = unsafe { heap_remove(bitvec) }.0; let bitvec = unsafe { heap_remove(bitvec) };
heap_move_ok(Packet::try_from(BitVecCommand { heap_move_ok(Packet::try_from(BitVecCommand {
bitvec, bitvec,
offset, offset,

View file

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