Browse Source

Add comment clarifying callback pointer safety

pull/163/head
Fenrir 10 months ago
parent
commit
2f7a04b08d
  1. 6
      ctru-rs/src/applets/swkbd.rs

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

@ -727,8 +727,10 @@ impl SoftwareKeyboard { @@ -727,8 +727,10 @@ impl SoftwareKeyboard {
swkbd_shared_mem_ptr,
};
if let Some(callback) = self.callback.as_ref() {
callback_data.callback = std::ptr::addr_of!(*callback);
// We need to pass a thin pointer to the boxed closure over FFI. Since we know that the callback will finish before
// `self` is allowed to be moved again, we can safely use a pointer to the local value contained in `self.callback`
if let Some(ref_to_boxed_closure) = self.callback.as_ref() {
callback_data.callback = ref_to_boxed_closure as *const _;
aptSetMessageCallback(
Some(Self::swkbd_message_callback),

Loading…
Cancel
Save