Browse Source

Use rust functions instead of memcpy and memset

pull/157/head
Fenrir 10 months ago
parent
commit
bd19f97050
  1. 46
      ctru-rs/src/applets/swkbd.rs

46
ctru-rs/src/applets/swkbd.rs

@ -733,10 +733,10 @@ impl SoftwareKeyboard {
if !extra.dict.is_null() { if !extra.dict.is_null() {
swkbd.dict_offset = dict_off as _; swkbd.dict_offset = dict_off as _;
unsafe { unsafe {
libc::memcpy( std::ptr::copy_nonoverlapping(
SWKBD_SHARED_MEM.add(dict_off), extra.dict,
extra.dict.cast(), SWKBD_SHARED_MEM.add(dict_off).cast(),
std::mem::size_of::<SwkbdDictWord>() * swkbd.dict_word_count as usize, swkbd.dict_word_count as _,
) )
}; };
} }
@ -744,10 +744,10 @@ impl SoftwareKeyboard {
if swkbd.initial_status_offset >= 0 { if swkbd.initial_status_offset >= 0 {
swkbd.initial_status_offset = status_off as _; swkbd.initial_status_offset = status_off as _;
unsafe { unsafe {
libc::memcpy( std::ptr::copy_nonoverlapping(
SWKBD_SHARED_MEM.add(status_off), extra.status_data,
extra.status_data.cast(), SWKBD_SHARED_MEM.add(status_off).cast(),
std::mem::size_of::<SwkbdStatusData>(), 1,
) )
}; };
} }
@ -755,10 +755,10 @@ impl SoftwareKeyboard {
if swkbd.initial_learning_offset >= 0 { if swkbd.initial_learning_offset >= 0 {
swkbd.initial_learning_offset = learning_off as _; swkbd.initial_learning_offset = learning_off as _;
unsafe { unsafe {
libc::memcpy( std::ptr::copy_nonoverlapping(
SWKBD_SHARED_MEM.add(learning_off), extra.learning_data,
extra.learning_data.cast(), SWKBD_SHARED_MEM.add(learning_off).cast(),
std::mem::size_of::<SwkbdLearningData>(), 1,
) )
}; };
} }
@ -771,11 +771,7 @@ impl SoftwareKeyboard {
// Launch swkbd // Launch swkbd
unsafe { unsafe {
libc::memset( swkbd.__bindgen_anon_1.reserved.fill(0);
std::ptr::addr_of_mut!(swkbd.__bindgen_anon_1.reserved).cast(),
0,
swkbd.__bindgen_anon_1.reserved.len(),
);
if extra.callback.is_some() { if extra.callback.is_some() {
aptSetMessageCallback( aptSetMessageCallback(
@ -821,20 +817,20 @@ impl SoftwareKeyboard {
if swkbd.save_state_flags & (1 << 0) != 0 { if swkbd.save_state_flags & (1 << 0) != 0 {
unsafe { unsafe {
libc::memcpy( std::ptr::copy_nonoverlapping(
extra.status_data.cast(), SWKBD_SHARED_MEM.add(swkbd.status_offset as _).cast(),
SWKBD_SHARED_MEM.add(swkbd.status_offset as _), extra.status_data,
std::mem::size_of::<SwkbdStatusData>(), 1,
) )
}; };
} }
if swkbd.save_state_flags & (1 << 1) != 0 { if swkbd.save_state_flags & (1 << 1) != 0 {
unsafe { unsafe {
libc::memcpy( std::ptr::copy_nonoverlapping(
extra.learning_data.cast(), SWKBD_SHARED_MEM.add(swkbd.learning_offset as _).cast(),
SWKBD_SHARED_MEM.add(swkbd.learning_offset as _), extra.learning_data,
std::mem::size_of::<SwkbdLearningData>(), 1,
) )
}; };
} }

Loading…
Cancel
Save