Skip to content

Commit

Permalink
Merge pull request #167 from LedgerHQ/y333/c_callbacks
Browse files Browse the repository at this point in the history
Using transmute is not required when defining callbacks used by C API
  • Loading branch information
yogh333 authored Jun 25, 2024
2 parents c29f244 + ef702b8 commit 077383a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.10.4"
version = "1.10.5"
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
edition = "2021"
license.workspace = true
Expand Down
11 changes: 6 additions & 5 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ pub extern "C" fn io_recv_and_process_event() -> bool {
}

/// Callback triggered by the NBGL API when a setting switch is toggled.
unsafe fn settings_callback(token: ::core::ffi::c_int, _index: u8, _page: ::core::ffi::c_int) {
unsafe extern "C" fn settings_callback(
token: ::core::ffi::c_int,
_index: u8,
_page: ::core::ffi::c_int,
) {
let idx = token - FIRST_USER_TOKEN as i32;
if idx < 0 || idx >= SETTINGS_SIZE as i32 {
panic!("Invalid token.");
Expand Down Expand Up @@ -237,10 +241,7 @@ impl<'a> NbglHomeAndSettings<'a> {
nbSwitches: self.nb_settings,
},
},
contentActionCallback: transmute(
(|token, index, page| settings_callback(token, index, page))
as fn(::core::ffi::c_int, u8, ::core::ffi::c_int),
),
contentActionCallback: Some(settings_callback),
type_: SWITCHES_LIST,
};

Expand Down

0 comments on commit 077383a

Please sign in to comment.