Skip to content

Commit

Permalink
Remove useless heap allocated (box) icon fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Jun 21, 2024
1 parent 6ba1991 commit cf5fa0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
2 changes: 0 additions & 2 deletions ledger_device_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ pub mod seph;

pub mod testing;

extern crate alloc;

#[cfg(any(target_os = "stax", target_os = "flex"))]
pub mod nbgl;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
Expand Down
46 changes: 18 additions & 28 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::io::{ApduHeader, Comm, Event, Reply};
use crate::nvm::*;
use const_zero::const_zero;
extern crate alloc;
use alloc::boxed::Box;
use alloc::ffi::CString;
use alloc::vec::Vec;
use core::ffi::c_char;
Expand Down Expand Up @@ -402,7 +401,7 @@ pub struct CenteredInfo {
text1: CString,
text2: CString,
text3: CString,
icon: Option<Box<nbgl_icon_details_t>>,
icon: Option<nbgl_icon_details_t>,
on_top: bool,
style: CenteredInfoStyle,
offset_y: i16,
Expand All @@ -418,15 +417,11 @@ impl CenteredInfo {
style: CenteredInfoStyle,
offset_y: i16,
) -> CenteredInfo {
let icon_boxed: Option<Box<nbgl_icon_details_t>> = match icon {
Some(glyph) => Some(Box::new(glyph.into())),
None => None,
};
CenteredInfo {
text1: CString::new(text1).unwrap(),
text2: CString::new(text2).unwrap(),
text3: CString::new(text3).unwrap(),
icon: icon_boxed,
icon: icon.map_or(None, |g| Some(g.into())),
on_top: on_top,
style: style,
offset_y: offset_y,
Expand All @@ -439,7 +434,7 @@ impl CenteredInfo {
/// on the device when using the NbglGenericReview struct.
pub struct InfoLongPress {
text: CString,
icon: Option<Box<nbgl_icon_details_t>>,
icon: Option<nbgl_icon_details_t>,
long_press_text: CString,
tune_id: TuneIndex,
}
Expand All @@ -451,13 +446,9 @@ impl InfoLongPress {
long_press_text: &str,
tune_id: TuneIndex,
) -> InfoLongPress {
let icon_boxed: Option<Box<nbgl_icon_details_t>> = match icon {
Some(glyph) => Some(Box::new(glyph.into())),
None => None,
};
InfoLongPress {
text: CString::new(text).unwrap(),
icon: icon_boxed,
icon: icon.map_or(None, |g| Some(g.into())),
long_press_text: CString::new(long_press_text).unwrap(),
tune_id: tune_id,
}
Expand All @@ -469,7 +460,7 @@ impl InfoLongPress {
/// on the device when using the NbglGenericReview struct.
pub struct InfoButton {
text: CString,
icon: Option<Box<nbgl_icon_details_t>>,
icon: Option<nbgl_icon_details_t>,
button_text: CString,
tune_id: TuneIndex,
}
Expand All @@ -481,13 +472,9 @@ impl InfoButton {
button_text: &str,
tune_id: TuneIndex,
) -> InfoButton {
let icon_boxed: Option<Box<nbgl_icon_details_t>> = match icon {
Some(glyph) => Some(Box::new(glyph.into())),
None => None,
};
InfoButton {
text: CString::new(text).unwrap(),
icon: icon_boxed,
icon: icon.map_or(None, |g| Some(g.into())),
button_text: CString::new(button_text).unwrap(),
tune_id: tune_id,
}
Expand Down Expand Up @@ -646,9 +633,10 @@ impl From<&NbglPageContent>
text1: data.text1.as_ptr() as *const c_char,
text2: data.text2.as_ptr() as *const c_char,
text3: data.text3.as_ptr() as *const c_char,
icon: data.icon.as_ref().map_or(core::ptr::null(), |icon| {
icon.as_ref() as *const nbgl_icon_details_t
}),
icon: data
.icon
.as_ref()
.map_or(core::ptr::null(), |icon| icon as *const nbgl_icon_details_t),
onTop: data.on_top,
style: data.style.into(),
offsetY: data.offset_y,
Expand Down Expand Up @@ -701,9 +689,10 @@ impl From<&NbglPageContent>
NbglPageContent::InfoLongPress(data) => {
let long_press = nbgl_contentInfoLongPress_t {
text: data.text.as_ptr() as *const c_char,
icon: data.icon.as_ref().map_or(core::ptr::null(), |icon| {
icon.as_ref() as *const nbgl_icon_details_t
}),
icon: data
.icon
.as_ref()
.map_or(core::ptr::null(), |icon| icon as *const nbgl_icon_details_t),
longPressText: data.long_press_text.as_ptr() as *const c_char,
longPressToken: FIRST_USER_TOKEN as u8,
tuneId: data.tune_id as u8,
Expand All @@ -720,9 +709,10 @@ impl From<&NbglPageContent>
NbglPageContent::InfoButton(data) => {
let button = nbgl_contentInfoButton_t {
text: data.text.as_ptr() as *const c_char,
icon: data.icon.as_ref().map_or(core::ptr::null(), |icon| {
icon.as_ref() as *const nbgl_icon_details_t
}),
icon: data
.icon
.as_ref()
.map_or(core::ptr::null(), |icon| icon as *const nbgl_icon_details_t),
buttonText: data.button_text.as_ptr() as *const c_char,
buttonToken: FIRST_USER_TOKEN as u8,
tuneId: data.tune_id as u8,
Expand Down
4 changes: 2 additions & 2 deletions ledger_secure_sdk_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ fn clone_sdk(device: &Device) -> PathBuf {
),
Device::Stax => (
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
"API_LEVEL_15",
"ux_sync_public_callbacks_15",
),
Device::Flex => (
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
"ux_sync_public_callbacks",
"ux_sync_public_callbacks_20",
),
};

Expand Down

0 comments on commit cf5fa0f

Please sign in to comment.