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"]
[export.rename]
"SpBitVec" = "BitVec"
"SpByteSlice" = "ByteSlice"
"SpCommand" = "Command"

View file

@ -396,18 +396,6 @@ typedef struct HardResetCommand HardResetCommand;
*/
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.
*/
@ -634,7 +622,7 @@ void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
*
* 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].
@ -662,7 +650,7 @@ size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
/**
* 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].
@ -768,7 +756,7 @@ size_t sp_bitmap_width(Bitmap */*notnull*/ bitmap);
/**
* 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].
@ -778,12 +766,12 @@ SPBitVec */*notnull*/ sp_bitvec_clone(SPBitVec */*notnull*/ bit_vec);
* - `bit_vec`: instance to write 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].
*/
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].
@ -799,7 +787,7 @@ void sp_bitvec_free(SPBitVec */*notnull*/ bit_vec);
*
* - 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].
@ -808,7 +796,7 @@ bool sp_bitvec_get(SPBitVec */*notnull*/ bit_vec, size_t index);
*
* 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,
BinaryOperation operation,
CompressionCode compression);
@ -820,7 +808,7 @@ Packet *sp_bitvec_into_packet(SPBitVec */*notnull*/ bitvec,
*
* - `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.
@ -829,14 +817,14 @@ bool sp_bitvec_is_empty(SPBitVec */*notnull*/ bit_vec);
*
* - `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.
*
* returns: [SPBitVec] instance containing data.
*/
SPBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
DisplayBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
/**
* Creates a new [SPBitVec] instance.
@ -851,7 +839,7 @@ SPBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
*
* - 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].
@ -866,7 +854,9 @@ SPBitVec */*notnull*/ sp_bitvec_new(size_t size);
*
* - 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.
@ -877,7 +867,7 @@ void sp_bitvec_set(SPBitVec */*notnull*/ bit_vec, size_t index, bool value);
*
* - `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].

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>,
}