From 5a849a87c7bb608ba0dcabbe2e82dd702329eee7 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Mon, 23 Jun 2025 21:16:22 +0200 Subject: [PATCH] fix missing renames --- include/servicepoint.h | 84 +++++++++++++++--------------- src/commands/char_grid_command.rs | 2 +- src/commands/cp437_grid_command.rs | 2 +- src/commands/generic_command.rs | 11 ++-- src/containers/bitmap.rs | 2 +- src/containers/cp437_grid.rs | 15 ++---- 6 files changed, 53 insertions(+), 63 deletions(-) diff --git a/include/servicepoint.h b/include/servicepoint.h index 095c6cc..2648383 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -1405,6 +1405,14 @@ struct CharGridCommand */*notnull*/ sp_chargridcommand_clone(struct CharGridComm */ void sp_chargridcommand_free(struct CharGridCommand */*notnull*/ instance); +/** + * Moves the provided [CharGrid] into a new [CharGridCommand], + * leaving other fields as their default values. + * + * This function is part of the `chargridcommand` module. + */ +struct CharGridCommand */*notnull*/ sp_chargridcommand_from_grid(CharGrid */*notnull*/ grid); + /** * Gets a reference to the field `grid` of the [`servicepoint::CharGridCommand`]. * @@ -1424,6 +1432,19 @@ void sp_chargridcommand_get_origin(struct CharGridCommand */*notnull*/ command, size_t */*notnull*/ origin_x, size_t */*notnull*/ origin_y); +/** + * Show UTF-8 encoded text on the screen. + * + * The passed [CharGrid] gets consumed. + * + * Returns: a new [CharGridCommand] instance. + * + * This function is part of the `chargridcommand` module. + */ +struct CharGridCommand */*notnull*/ sp_chargridcommand_new(CharGrid */*notnull*/ grid, + size_t origin_x, + size_t origin_y); + /** * Sets the value of field `grid` of the [`servicepoint::CharGridCommand`]. * The provided value is moved into the instance, potentially invalidating previously taken references. @@ -1489,48 +1510,6 @@ struct ClearCommand */*notnull*/ sp_clearcommand_new(void); */ struct Packet *sp_clearcommand_try_into_packet(struct ClearCommand */*notnull*/ instance); -/** - * Moves the provided [CharGrid] into a new [CharGridCommand], - * leaving other fields as their default values. - * - * This function is part of the `cmd_chargrid` module. - */ -struct CharGridCommand */*notnull*/ sp_cmd_chargrid_from_grid(CharGrid */*notnull*/ grid); - -/** - * Show UTF-8 encoded text on the screen. - * - * The passed [CharGrid] gets consumed. - * - * Returns: a new [CharGridCommand] instance. - * - * This function is part of the `cmd_chargrid` module. - */ -struct CharGridCommand */*notnull*/ sp_cmd_chargrid_new(CharGrid */*notnull*/ grid, - size_t origin_x, - size_t origin_y); - -/** - * Moves the provided [Cp437Grid] into a new [Cp437GridCommand], - * leaving other fields as their default values. - * - * This function is part of the `cmd_cp437grid` module. - */ -struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_from_grid(Cp437Grid */*notnull*/ grid); - -/** - * Show text on the screen. - * - * The text is sent in the form of a 2D grid of [CP-437] encoded characters. - * - * The origin is relative to the top-left of the display. - * - * This function is part of the `cmd_cp437grid` module. - */ -struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_new(Cp437Grid */*notnull*/ grid, - size_t origin_x, - size_t origin_y); - /** *Clones a [`Cp437Grid`] instance. * @@ -1672,6 +1651,14 @@ struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_clone(struct Cp437GridC */ void sp_cp437gridcommand_free(struct Cp437GridCommand */*notnull*/ instance); +/** + * Moves the provided [Cp437Grid] into a new [Cp437GridCommand], + * leaving other fields as their default values. + * + * This function is part of the `cp437gridcommand` module. + */ +struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_from_grid(Cp437Grid */*notnull*/ grid); + /** * Gets a reference to the field `grid` of the [`servicepoint::Cp437GridCommand`]. * @@ -1691,6 +1678,19 @@ void sp_cp437gridcommand_get_origin(struct Cp437GridCommand */*notnull*/ command size_t */*notnull*/ origin_x, size_t */*notnull*/ origin_y); +/** + * Show text on the screen. + * + * The text is sent in the form of a 2D grid of [CP-437] encoded characters. + * + * The origin is relative to the top-left of the display. + * + * This function is part of the `cp437gridcommand` module. + */ +struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_new(Cp437Grid */*notnull*/ grid, + size_t origin_x, + size_t origin_y); + /** * Sets the value of field `grid` of the [`servicepoint::Cp437GridCommand`]. * The provided value is moved into the instance, potentially invalidating previously taken references. diff --git a/src/commands/char_grid_command.rs b/src/commands/char_grid_command.rs index f8d5107..41e5000 100644 --- a/src/commands/char_grid_command.rs +++ b/src/commands/char_grid_command.rs @@ -14,7 +14,7 @@ wrap_fields!(CharGridCommand; wrap_origin_accessors!(CharGridCommand); -wrap_functions!(cmd_chargrid; +wrap_functions!(associate CharGridCommand; /// Show UTF-8 encoded text on the screen. /// diff --git a/src/commands/cp437_grid_command.rs b/src/commands/cp437_grid_command.rs index 4977195..b43afb4 100644 --- a/src/commands/cp437_grid_command.rs +++ b/src/commands/cp437_grid_command.rs @@ -14,7 +14,7 @@ wrap_fields!(Cp437GridCommand; wrap_origin_accessors!(Cp437GridCommand); -wrap_functions!(cmd_cp437grid; +wrap_functions!(associate Cp437GridCommand; /// Show text on the screen. /// diff --git a/src/commands/generic_command.rs b/src/commands/generic_command.rs index 609daac..d288a27 100644 --- a/src/commands/generic_command.rs +++ b/src/commands/generic_command.rs @@ -1,5 +1,5 @@ use crate::{ - macros::{derive_clone, derive_free, wrap_functions}, + macros::{derive_clone, derive_free, wrap_functions, wrap_methods}, mem::{ heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok, heap_remove, @@ -11,7 +11,6 @@ use servicepoint::{ HardResetCommand, Packet, TypedCommand, }; use std::ptr::{null_mut, NonNull}; -use crate::macros::wrap_methods; /// Pointer to one of the available command structs. #[repr(C)] @@ -168,11 +167,12 @@ impl Drop for GenericCommand { CommandTag::BitmapLegacy => heap_drop(self.data.bitmap_legacy), } } + + *self = Self::INVALID; } } wrap_functions!(associate GenericCommand; - /// Tries to turn a [Packet] into a [GenericCommand]. /// /// The packet is dropped in the process. @@ -181,7 +181,7 @@ wrap_functions!(associate GenericCommand; fn try_from_packet( packet: NonNull, ) -> NonNull { - let packet = *unsafe { Box::from_raw(packet.as_ptr()) }; + let packet = unsafe { heap_remove(packet) }; let result = servicepoint::TypedCommand::try_from(packet) .map(|value| match value { TypedCommand::Clear(clear) => GenericCommand { @@ -252,10 +252,9 @@ wrap_functions!(associate GenericCommand; }); heap_move_nonnull(result) } - ); -wrap_methods!{GenericCommand; +wrap_methods! { GenericCommand; /// Tries to turn a [GenericCommand] into a [Packet]. /// The [GenericCommand] gets consumed. /// diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs index 4ce7972..738925b 100644 --- a/src/containers/bitmap.rs +++ b/src/containers/bitmap.rs @@ -11,7 +11,7 @@ use std::ptr::NonNull; wrap_grid!(Bitmap, bool); -wrap_functions!(bitmap; +wrap_functions!(associate Bitmap; /// Creates a new [Bitmap] with the specified dimensions. /// /// # Arguments diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs index 38efc58..8905610 100644 --- a/src/containers/cp437_grid.rs +++ b/src/containers/cp437_grid.rs @@ -10,28 +10,19 @@ use std::ptr::NonNull; wrap_grid!(Cp437Grid, u8); -wrap_functions!(cp437grid; - +wrap_functions!(associate Cp437Grid; /// Creates a new [Cp437Grid] with the specified dimensions. /// /// returns: [Cp437Grid] initialized to 0. - fn new( - width: usize, - height: usize, - ) -> NonNull { + fn new(width: usize, height: usize) -> NonNull { heap_move_nonnull(Cp437Grid::new(width, height)) } /// Loads a [Cp437Grid] with the specified dimensions from the provided data. - fn load( - width: usize, - height: usize, - data: ByteSlice, - ) -> *mut Cp437Grid { + fn load(width: usize, height: usize, data: ByteSlice) -> *mut Cp437Grid { let data = unsafe { data.as_slice() }; heap_move_some(Cp437Grid::load(width, height, data)) } - ); wrap_methods!(Cp437Grid;