generate some functions with macros, cbindgen 0.29

This commit is contained in:
Vinzenz Schroeter 2025-06-16 21:26:58 +02:00
parent db94fecbb3
commit 02f629c68b
23 changed files with 195 additions and 349 deletions

View file

@ -1,5 +1,6 @@
use crate::mem::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin, Packet};
use std::ptr::NonNull;
@ -44,21 +45,8 @@ pub unsafe extern "C" fn sp_cmd_bitmap_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into())
}
/// Clones an [BitmapCommand] instance.
///
/// returns: a new [BitmapCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitmap_clone(
command: NonNull<BitmapCommand>,
) -> NonNull<BitmapCommand> {
unsafe { heap_clone(command) }
}
/// Deallocates a [BitmapCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitmap_free(command: NonNull<BitmapCommand>) {
unsafe { heap_drop(command) }
}
wrap_clone!(BitmapCommand, sp_cmd_bitmap);
wrap_free!(BitmapCommand, sp_cmd_bitmap);
/// Returns a pointer to the provided `BitmapCommand`.
///

View file

@ -1,5 +1,6 @@
use crate::mem::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
@ -44,21 +45,8 @@ pub unsafe extern "C" fn sp_cmd_bitvec_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into())
}
/// Clones an [BitVecCommand] instance.
///
/// returns: a new [BitVecCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_clone(
command: NonNull<BitVecCommand>,
) -> NonNull<BitVecCommand> {
unsafe { heap_clone(command) }
}
/// Deallocates a [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
unsafe { heap_drop(command) }
}
wrap_clone!(BitVecCommand, sp_cmd_bitvec);
wrap_free!(BitVecCommand, sp_cmd_bitvec);
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
#[no_mangle]

View file

@ -1,9 +1,8 @@
use crate::mem::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
};
use servicepoint::{
BitmapCommand, BrightnessGrid, BrightnessGridCommand, Origin, Packet,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin, Packet};
use std::ptr::NonNull;
/// Set the brightness of individual tiles in a rectangular area of the display.
@ -42,23 +41,8 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into())
}
/// Clones an [BrightnessGridCommand] instance.
///
/// returns: a new [BrightnessGridCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_grid_clone(
command: NonNull<BrightnessGridCommand>,
) -> NonNull<BrightnessGridCommand> {
unsafe { heap_clone(command) }
}
/// Deallocates a [BitmapCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_grid_free(
command: NonNull<BitmapCommand>,
) {
unsafe { heap_drop(command) }
}
wrap_clone!(BrightnessGridCommand, sp_cmd_brightness_grid);
wrap_free!(BrightnessGridCommand, sp_cmd_brightness_grid);
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
#[no_mangle]

View file

@ -1,4 +1,4 @@
use crate::mem::{heap_drop, heap_move_nonnull};
use crate::{macros::wrap_free, mem::heap_move_nonnull};
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
use std::ptr::NonNull;
@ -12,11 +12,7 @@ pub unsafe extern "C" fn sp_cmd_clear_new() -> NonNull<ClearCommand> {
heap_move_nonnull(ClearCommand)
}
/// Deallocates a [ClearCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_clear_free(command: NonNull<ClearCommand>) {
unsafe { heap_drop(command) }
}
wrap_free!(ClearCommand, sp_cmd_clear);
/// Kills the udp daemon on the display, which usually results in a restart.
///
@ -28,13 +24,7 @@ pub unsafe extern "C" fn sp_cmd_hard_reset_new() -> NonNull<HardResetCommand> {
heap_move_nonnull(HardResetCommand)
}
/// Deallocates a [HardResetCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_hard_reset_free(
command: NonNull<ClearCommand>,
) {
unsafe { heap_drop(command) }
}
wrap_free!(HardResetCommand, sp_cmd_hard_reset);
/// A yet-to-be-tested command.
///
@ -44,8 +34,4 @@ pub unsafe extern "C" fn sp_cmd_fade_out_new() -> NonNull<FadeOutCommand> {
heap_move_nonnull(FadeOutCommand)
}
/// Deallocates a [FadeOutCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_fade_out_free(command: NonNull<ClearCommand>) {
unsafe { heap_drop(command) }
}
wrap_free!(FadeOutCommand, sp_cmd_fade_out);

View file

@ -1,7 +1,8 @@
use crate::mem::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{BitmapCommand, CharGrid, CharGridCommand, Origin, Packet};
use servicepoint::{CharGrid, CharGridCommand, Origin, Packet};
use std::ptr::NonNull;
/// Show UTF-8 encoded text on the screen.
@ -40,23 +41,8 @@ pub unsafe extern "C" fn sp_cmd_char_grid_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into())
}
/// Clones an [CharGridCommand] instance.
///
/// returns: a new [CharGridCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_char_grid_clone(
command: NonNull<CharGridCommand>,
) -> NonNull<CharGridCommand> {
unsafe { heap_clone(command) }
}
/// Deallocates a [BitmapCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_char_grid_free(
command: NonNull<BitmapCommand>,
) {
unsafe { heap_drop(command) }
}
wrap_clone!(CharGridCommand, sp_cmd_char_grid);
wrap_free!(CharGridCommand, sp_cmd_char_grid);
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
#[no_mangle]

View file

@ -1,9 +1,8 @@
use crate::mem::{
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
};
use servicepoint::{
BitmapCommand, Cp437Grid, Cp437GridCommand, Origin, Packet,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin, Packet};
use std::ptr::NonNull;
/// Show text on the screen.
@ -42,23 +41,8 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into())
}
/// Clones an [Cp437GridCommand] instance.
///
/// returns: a new [Cp437GridCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_cp437_grid_clone(
command: NonNull<Cp437GridCommand>,
) -> NonNull<Cp437GridCommand> {
unsafe { heap_clone(command) }
}
/// Deallocates a [Cp437GridCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_cp437_grid_free(
command: NonNull<BitmapCommand>,
) {
unsafe { heap_drop(command) }
}
wrap_clone!(Cp437GridCommand, sp_cmd_cp437_grid);
wrap_free!(Cp437GridCommand, sp_cmd_cp437_grid);
/// Moves the provided bitmap into the provided command.
///

View file

@ -222,7 +222,7 @@ pub unsafe extern "C" fn sp_cmd_generic_clone(command: SPCommand) -> SPCommand {
}
/// Deallocates an [SPCommand].
///
///
/// Commands with an invalid `tag` do not have to be freed as the `data` pointer should be null.
///
/// # Examples

View file

@ -1,7 +1,8 @@
use crate::mem::{heap_clone, heap_drop, heap_move_nonnull, heap_remove};
use servicepoint::{
BitmapCommand, Brightness, GlobalBrightnessCommand, Packet,
use crate::{
macros::{wrap_clone, wrap_free},
mem::{heap_move_nonnull, heap_remove},
};
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
use std::ptr::NonNull;
/// Set the brightness of all tiles to the same value.
@ -21,22 +22,8 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet(
heap_move_nonnull(unsafe { heap_remove(command) }.into())
}
/// Clones an [GlobalBrightnessCommand] instance.
///
/// returns: a new [GlobalBrightnessCommand] instance.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_global_clone(
command: NonNull<GlobalBrightnessCommand>,
) -> NonNull<GlobalBrightnessCommand> {
unsafe { heap_clone(command) }
}
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_global_free(
command: NonNull<BitmapCommand>,
) {
unsafe { heap_drop(command) }
}
wrap_clone!(GlobalBrightnessCommand, sp_cmd_brightness_global);
wrap_free!(GlobalBrightnessCommand, sp_cmd_brightness_global);
/// Moves the provided bitmap to be contained in the command.
#[no_mangle]