diff --git a/Cargo.lock b/Cargo.lock index 45d9e17..10ec770 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.29" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e804ac3194a48bb129643eb1d62fcc20d18c6b8c181704489353d13120bcd1" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ "jobserver", "libc", diff --git a/crates/servicepoint/examples/wiping_clear.rs b/crates/servicepoint/examples/wiping_clear.rs index c28345d..a3bf04a 100644 --- a/crates/servicepoint/examples/wiping_clear.rs +++ b/crates/servicepoint/examples/wiping_clear.rs @@ -25,7 +25,7 @@ fn main() { let connection = Connection::open(cli.destination) .expect("could not connect to display"); - let mut enabled_pixels = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT); + let mut enabled_pixels = Bitmap::max_sized(); enabled_pixels.fill(true); for x_offset in 0..PIXEL_WIDTH { diff --git a/crates/servicepoint_binding_c/examples/lang_c/include/servicepoint.h b/crates/servicepoint_binding_c/examples/lang_c/include/servicepoint.h index b0a420b..e85a9fa 100644 --- a/crates/servicepoint_binding_c/examples/lang_c/include/servicepoint.h +++ b/crates/servicepoint_binding_c/examples/lang_c/include/servicepoint.h @@ -76,9 +76,9 @@ typedef uint16_t SPCompressionCode; * * # Examples * ```C - * SPBitVec vec = sp_bit_vec_new(8); - * sp_bit_vec_set(vec, 5, true); - * sp_bit_vec_free(vec); + * SPBitVec vec = sp_bitvec_new(8); + * sp_bitvec_set(vec, 5, true); + * sp_bitvec_free(vec); * ``` */ typedef struct SPBitVec SPBitVec; @@ -212,9 +212,9 @@ extern "C" { * - `bit_vec` points to a valid [SPBitVec] * - `bit_vec` 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_free`. + * by explicitly calling `sp_bitvec_free`. */ -struct SPBitVec *sp_bit_vec_clone(const struct SPBitVec *bit_vec); +struct SPBitVec *sp_bitvec_clone(const struct SPBitVec *bit_vec); /** * Sets the value of all bits in the [SPBitVec]. @@ -235,7 +235,7 @@ struct SPBitVec *sp_bit_vec_clone(const struct SPBitVec *bit_vec); * - `bit_vec` points to a valid [SPBitVec] * - `bit_vec` is not written to or read from concurrently */ -void sp_bit_vec_fill(struct SPBitVec *bit_vec, bool value); +void sp_bitvec_fill(struct SPBitVec *bit_vec, bool value); /** * Deallocates a [SPBitVec]. @@ -252,7 +252,7 @@ void sp_bit_vec_fill(struct SPBitVec *bit_vec, bool value); * - `bit_vec` is not used concurrently or after this call * - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand] */ -void sp_bit_vec_free(struct SPBitVec *bit_vec); +void sp_bitvec_free(struct SPBitVec *bit_vec); /** * Gets the value of a bit from the [SPBitVec]. @@ -276,7 +276,7 @@ void sp_bit_vec_free(struct SPBitVec *bit_vec); * - `bit_vec` points to a valid [SPBitVec] * - `bit_vec` is not written to concurrently */ -bool sp_bit_vec_get(const struct SPBitVec *bit_vec, size_t index); +bool sp_bitvec_get(const struct SPBitVec *bit_vec, size_t index); /** * Returns true if length is 0. @@ -295,7 +295,7 @@ bool sp_bit_vec_get(const struct SPBitVec *bit_vec, size_t index); * * - `bit_vec` points to a valid [SPBitVec] */ -bool sp_bit_vec_is_empty(const struct SPBitVec *bit_vec); +bool sp_bitvec_is_empty(const struct SPBitVec *bit_vec); /** * Gets the length of the [SPBitVec] in bits. @@ -314,7 +314,7 @@ bool sp_bit_vec_is_empty(const struct SPBitVec *bit_vec); * * - `bit_vec` points to a valid [SPBitVec] */ -size_t sp_bit_vec_len(const struct SPBitVec *bit_vec); +size_t sp_bitvec_len(const struct SPBitVec *bit_vec); /** * Interpret the data as a series of bits and load then into a new [SPBitVec] instance. @@ -332,9 +332,9 @@ size_t sp_bit_vec_len(const struct SPBitVec *bit_vec); * - `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_free`. + * by explicitly calling `sp_bitvec_free`. */ -struct SPBitVec *sp_bit_vec_load(const uint8_t *data, +struct SPBitVec *sp_bitvec_load(const uint8_t *data, size_t data_length); /** @@ -355,9 +355,9 @@ struct SPBitVec *sp_bit_vec_load(const uint8_t *data, * 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_free`. + * by explicitly calling `sp_bitvec_free`. */ -struct SPBitVec *sp_bit_vec_new(size_t size); +struct SPBitVec *sp_bitvec_new(size_t size); /** * Sets the value of a bit in the [SPBitVec]. @@ -380,7 +380,7 @@ struct SPBitVec *sp_bit_vec_new(size_t size); * - `bit_vec` points to a valid [SPBitVec] * - `bit_vec` is not written to or read from concurrently */ -void sp_bit_vec_set(struct SPBitVec *bit_vec, size_t index, bool value); +void sp_bitvec_set(struct SPBitVec *bit_vec, size_t index, bool value); /** * Gets an unsafe reference to the data of the [SPBitVec] instance. @@ -401,7 +401,7 @@ void sp_bit_vec_set(struct SPBitVec *bit_vec, size_t index, bool value); * - 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 */ -struct SPByteSlice sp_bit_vec_unsafe_data_ref(struct SPBitVec *bit_vec); +struct SPByteSlice sp_bitvec_unsafe_data_ref(struct SPBitVec *bit_vec); /** * Clones a [SPBitmap]. diff --git a/crates/servicepoint_binding_c/src/bit_vec.rs b/crates/servicepoint_binding_c/src/bit_vec.rs index 8b9e94f..1fe509b 100644 --- a/crates/servicepoint_binding_c/src/bit_vec.rs +++ b/crates/servicepoint_binding_c/src/bit_vec.rs @@ -1,6 +1,6 @@ //! C functions for interacting with [SPBitVec]s //! -//! prefix `sp_bit_vec_` +//! prefix `sp_bitvec_` use crate::SPByteSlice; use servicepoint::bitvec::prelude::{BitVec, Msb0}; @@ -9,9 +9,9 @@ use servicepoint::bitvec::prelude::{BitVec, Msb0}; /// /// # Examples /// ```C -/// SPBitVec vec = sp_bit_vec_new(8); -/// sp_bit_vec_set(vec, 5, true); -/// sp_bit_vec_free(vec); +/// SPBitVec vec = sp_bitvec_new(8); +/// sp_bitvec_set(vec, 5, true); +/// sp_bitvec_free(vec); /// ``` pub struct SPBitVec(BitVec); @@ -50,9 +50,9 @@ 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_free`. +/// by explicitly calling `sp_bitvec_free`. #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_new(size: usize) -> *mut SPBitVec { +pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> *mut SPBitVec { let result = Box::into_raw(Box::new(SPBitVec(BitVec::repeat(false, size)))); assert!(!result.is_null()); result @@ -73,9 +73,9 @@ 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_free`. +/// by explicitly calling `sp_bitvec_free`. #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_load( +pub unsafe extern "C" fn sp_bitvec_load( data: *const u8, data_length: usize, ) -> *mut SPBitVec { @@ -101,9 +101,9 @@ pub unsafe extern "C" fn sp_bit_vec_load( /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` 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_free`. +/// by explicitly calling `sp_bitvec_free`. #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_clone( +pub unsafe extern "C" fn sp_bitvec_clone( bit_vec: *const SPBitVec, ) -> *mut SPBitVec { assert!(!bit_vec.is_null()); @@ -126,7 +126,7 @@ pub unsafe extern "C" fn sp_bit_vec_clone( /// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand] #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_free(bit_vec: *mut SPBitVec) { +pub unsafe extern "C" fn sp_bitvec_free(bit_vec: *mut SPBitVec) { assert!(!bit_vec.is_null()); _ = Box::from_raw(bit_vec); } @@ -152,7 +152,7 @@ pub unsafe extern "C" fn sp_bit_vec_free(bit_vec: *mut SPBitVec) { /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to concurrently #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_get( +pub unsafe extern "C" fn sp_bitvec_get( bit_vec: *const SPBitVec, index: usize, ) -> bool { @@ -180,7 +180,7 @@ pub unsafe extern "C" fn sp_bit_vec_get( /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to or read from concurrently #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_set( +pub unsafe extern "C" fn sp_bitvec_set( bit_vec: *mut SPBitVec, index: usize, value: bool, @@ -207,7 +207,7 @@ pub unsafe extern "C" fn sp_bit_vec_set( /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to or read from concurrently #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_fill(bit_vec: *mut SPBitVec, value: bool) { +pub unsafe extern "C" fn sp_bitvec_fill(bit_vec: *mut SPBitVec, value: bool) { assert!(!bit_vec.is_null()); (*bit_vec).0.fill(value) } @@ -228,7 +228,7 @@ pub unsafe extern "C" fn sp_bit_vec_fill(bit_vec: *mut SPBitVec, value: bool) { /// /// - `bit_vec` points to a valid [SPBitVec] #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_len(bit_vec: *const SPBitVec) -> usize { +pub unsafe extern "C" fn sp_bitvec_len(bit_vec: *const SPBitVec) -> usize { assert!(!bit_vec.is_null()); (*bit_vec).0.len() } @@ -249,7 +249,7 @@ pub unsafe extern "C" fn sp_bit_vec_len(bit_vec: *const SPBitVec) -> usize { /// /// - `bit_vec` points to a valid [SPBitVec] #[no_mangle] -pub unsafe extern "C" fn sp_bit_vec_is_empty(bit_vec: *const SPBitVec) -> bool { +pub unsafe extern "C" fn sp_bitvec_is_empty(bit_vec: *const SPBitVec) -> bool { assert!(!bit_vec.is_null()); (*bit_vec).0.is_empty() } @@ -272,7 +272,7 @@ pub unsafe extern "C" fn sp_bit_vec_is_empty(bit_vec: *const SPBitVec) -> bool { /// - 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( +pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref( bit_vec: *mut SPBitVec, ) -> SPByteSlice { assert!(!bit_vec.is_null()); diff --git a/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs b/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs index df0873f..1dd15a7 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs @@ -37,10 +37,10 @@ namespace ServicePoint.BindGen /// 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_free`. + /// by explicitly calling `sp_bitvec_free`. /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern BitVec* sp_bit_vec_new(nuint size); + [DllImport(__DllName, EntryPoint = "sp_bitvec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern BitVec* sp_bitvec_new(nuint size); /// /// Interpret the data as a series of bits and load then into a new [SPBitVec] instance. @@ -58,10 +58,10 @@ namespace ServicePoint.BindGen /// - `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_free`. + /// by explicitly calling `sp_bitvec_free`. /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern BitVec* sp_bit_vec_load(byte* data, nuint data_length); + [DllImport(__DllName, EntryPoint = "sp_bitvec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern BitVec* sp_bitvec_load(byte* data, nuint data_length); /// /// Clones a [SPBitVec]. @@ -79,10 +79,10 @@ namespace ServicePoint.BindGen /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` 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_free`. + /// by explicitly calling `sp_bitvec_free`. /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern BitVec* sp_bit_vec_clone(BitVec* bit_vec); + [DllImport(__DllName, EntryPoint = "sp_bitvec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern BitVec* sp_bitvec_clone(BitVec* bit_vec); /// /// Deallocates a [SPBitVec]. @@ -99,8 +99,8 @@ namespace ServicePoint.BindGen /// - `bit_vec` is not used concurrently or after this call /// - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand] /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_bit_vec_free(BitVec* bit_vec); + [DllImport(__DllName, EntryPoint = "sp_bitvec_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void sp_bitvec_free(BitVec* bit_vec); /// /// Gets the value of a bit from the [SPBitVec]. @@ -124,9 +124,9 @@ namespace ServicePoint.BindGen /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to concurrently /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [DllImport(__DllName, EntryPoint = "sp_bitvec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - public static extern bool sp_bit_vec_get(BitVec* bit_vec, nuint index); + public static extern bool sp_bitvec_get(BitVec* bit_vec, nuint index); /// /// Sets the value of a bit in the [SPBitVec]. @@ -149,8 +149,8 @@ namespace ServicePoint.BindGen /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to or read from concurrently /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_bit_vec_set(BitVec* bit_vec, nuint index, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(__DllName, EntryPoint = "sp_bitvec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void sp_bitvec_set(BitVec* bit_vec, nuint index, [MarshalAs(UnmanagedType.U1)] bool value); /// /// Sets the value of all bits in the [SPBitVec]. @@ -171,8 +171,8 @@ namespace ServicePoint.BindGen /// - `bit_vec` points to a valid [SPBitVec] /// - `bit_vec` is not written to or read from concurrently /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_bit_vec_fill(BitVec* bit_vec, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(__DllName, EntryPoint = "sp_bitvec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void sp_bitvec_fill(BitVec* bit_vec, [MarshalAs(UnmanagedType.U1)] bool value); /// /// Gets the length of the [SPBitVec] in bits. @@ -191,8 +191,8 @@ namespace ServicePoint.BindGen /// /// - `bit_vec` points to a valid [SPBitVec] /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern nuint sp_bit_vec_len(BitVec* bit_vec); + [DllImport(__DllName, EntryPoint = "sp_bitvec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern nuint sp_bitvec_len(BitVec* bit_vec); /// /// Returns true if length is 0. @@ -211,9 +211,9 @@ namespace ServicePoint.BindGen /// /// - `bit_vec` points to a valid [SPBitVec] /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [DllImport(__DllName, EntryPoint = "sp_bitvec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - public static extern bool sp_bit_vec_is_empty(BitVec* bit_vec); + public static extern bool sp_bitvec_is_empty(BitVec* bit_vec); /// /// Gets an unsafe reference to the data of the [SPBitVec] instance. @@ -234,8 +234,8 @@ namespace ServicePoint.BindGen /// - 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 /// - [DllImport(__DllName, EntryPoint = "sp_bit_vec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern ByteSlice sp_bit_vec_unsafe_data_ref(BitVec* bit_vec); + [DllImport(__DllName, EntryPoint = "sp_bitvec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteSlice sp_bitvec_unsafe_data_ref(BitVec* bit_vec); /// /// Creates a new [SPBrightnessGrid] with the specified dimensions. diff --git a/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs b/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs index 2abe78c..ab697e0 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs @@ -8,7 +8,7 @@ public sealed class BitVec : SpNativeInstance { unsafe { - return new BitVec(NativeMethods.sp_bit_vec_new((nuint)size)); + return new BitVec(NativeMethods.sp_bitvec_new((nuint)size)); } } @@ -18,7 +18,7 @@ public sealed class BitVec : SpNativeInstance { fixed (byte* bytesPtr = bytes) { - return new BitVec(NativeMethods.sp_bit_vec_load(bytesPtr, (nuint)bytes.Length)); + return new BitVec(NativeMethods.sp_bitvec_load(bytesPtr, (nuint)bytes.Length)); } } } @@ -27,7 +27,7 @@ public sealed class BitVec : SpNativeInstance { unsafe { - return new BitVec(NativeMethods.sp_bit_vec_clone(Instance)); + return new BitVec(NativeMethods.sp_bitvec_clone(Instance)); } } @@ -37,14 +37,14 @@ public sealed class BitVec : SpNativeInstance { unsafe { - return NativeMethods.sp_bit_vec_get(Instance, (nuint)index); + return NativeMethods.sp_bitvec_get(Instance, (nuint)index); } } set { unsafe { - NativeMethods.sp_bit_vec_set(Instance, (nuint)index, value); + NativeMethods.sp_bitvec_set(Instance, (nuint)index, value); } } } @@ -53,7 +53,7 @@ public sealed class BitVec : SpNativeInstance { unsafe { - NativeMethods.sp_bit_vec_fill(Instance, value); + NativeMethods.sp_bitvec_fill(Instance, value); } } @@ -63,7 +63,7 @@ public sealed class BitVec : SpNativeInstance { unsafe { - return (int)NativeMethods.sp_bit_vec_len(Instance); + return (int)NativeMethods.sp_bitvec_len(Instance); } } } @@ -74,7 +74,7 @@ public sealed class BitVec : SpNativeInstance { unsafe { - var slice = NativeMethods.sp_bit_vec_unsafe_data_ref(Instance); + var slice = NativeMethods.sp_bitvec_unsafe_data_ref(Instance); return new Span(slice.start, (int)slice.length); } } @@ -84,5 +84,5 @@ public sealed class BitVec : SpNativeInstance { } - private protected override unsafe void Free() => NativeMethods.sp_bit_vec_free(Instance); + private protected override unsafe void Free() => NativeMethods.sp_bitvec_free(Instance); }