sp_cmd_generic_try_from_packet return struct directly
This commit is contained in:
parent
389ced492c
commit
c9d2479f5e
3 changed files with 24 additions and 8 deletions
|
@ -74,10 +74,10 @@ impl SPCommand {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
||||
packet: NonNull<Packet>,
|
||||
) -> *mut SPCommand {
|
||||
) -> SPCommand {
|
||||
let packet = *unsafe { Box::from_raw(packet.as_ptr()) };
|
||||
heap_move_ok(servicepoint::TypedCommand::try_from(packet).map(|value| {
|
||||
match value {
|
||||
servicepoint::TypedCommand::try_from(packet)
|
||||
.map(|value| match value {
|
||||
TypedCommand::Clear(clear) => SPCommand {
|
||||
tag: CommandTag::Clear,
|
||||
data: CommandUnion {
|
||||
|
@ -139,8 +139,11 @@ pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
|||
bitmap_legacy: heap_move_nonnull(bitmap_legacy),
|
||||
},
|
||||
},
|
||||
}
|
||||
}))
|
||||
})
|
||||
.unwrap_or_else(move |_| SPCommand {
|
||||
tag: CommandTag::Invalid,
|
||||
data: CommandUnion { null: null_mut() },
|
||||
})
|
||||
}
|
||||
|
||||
/// Clones an [SPCommand] instance.
|
||||
|
@ -219,6 +222,8 @@ 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
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue