summaryrefslogtreecommitdiff
path: root/plugins/svd/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 19:22:21 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit2f214f6c9935e8ce8df4732cde44a540a003258c (patch)
tree6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /plugins/svd/src
parentb4cf0be8816182c9efca037e27e9439482f8bf36 (diff)
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids. Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type. This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type. Special consideration must be made for symbols or other possible non utf-8 objects. This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'plugins/svd/src')
-rw-r--r--plugins/svd/src/mapper.rs12
-rw-r--r--plugins/svd/src/settings.rs12
2 files changed, 13 insertions, 11 deletions
diff --git a/plugins/svd/src/mapper.rs b/plugins/svd/src/mapper.rs
index 2d511615..314fba76 100644
--- a/plugins/svd/src/mapper.rs
+++ b/plugins/svd/src/mapper.rs
@@ -205,7 +205,7 @@ impl DeviceMapper {
let peripheral_ty_id = format!("SVD:{}", peripheral.name);
let id = view.define_auto_type_with_id(
&peripheral.name,
- peripheral_ty_id,
+ &peripheral_ty_id,
&peripheral_ty,
);
let ntr =
@@ -224,14 +224,14 @@ impl DeviceMapper {
view.define_auto_symbol(&symbol);
view.set_comment_at(
block_addr,
- format!("Buffer block with size {}", address_block.size),
+ &format!("Buffer block with size {}", address_block.size),
);
}
AddressBlockUsage::Reserved => {
// TODO: What to do for reserved blocks?
view.set_comment_at(
block_addr,
- format!("Reserved block with size {}", address_block.size),
+ &format!("Reserved block with size {}", address_block.size),
);
}
}
@@ -286,11 +286,11 @@ impl DeviceMapper {
for (field_addr, comments) in unaligned_comments {
let comment = comments.join("\n");
- view.set_comment_at(field_addr, comment);
+ view.set_comment_at(field_addr, &comment);
}
}
}
- view.file().commit_undo_actions(undo_id);
+ view.file().commit_undo_actions(&undo_id);
}
pub fn peripheral_block_memory_info(
@@ -662,7 +662,7 @@ impl DeviceMapper {
current_value = enumerated_value.value.unwrap_or(current_value + 1);
// TODO: The Rust API needs to expose this...
let _is_default = enumerated_value.is_default.unwrap_or(false);
- enum_builder.insert(enumerated_value.name.to_owned(), current_value);
+ enum_builder.insert(&enumerated_value.name, current_value);
}
let enum_width = NonZeroUsize::new(byte_aligned_width as usize).unwrap();
diff --git a/plugins/svd/src/settings.rs b/plugins/svd/src/settings.rs
index 9621da64..fb2f680c 100644
--- a/plugins/svd/src/settings.rs
+++ b/plugins/svd/src/settings.rs
@@ -32,7 +32,7 @@ impl LoadSettings {
});
bn_settings.register_setting_json(
Self::ADD_BACKING_REGIONS_SETTING,
- add_backing_region_props.to_string(),
+ &add_backing_region_props.to_string(),
);
let add_bitfields_props = json!({
@@ -41,8 +41,10 @@ impl LoadSettings {
"default" : Self::ADD_BITFIELDS_DEFAULT,
"description" : "Whether to add bitfields. Bitfields are not supported by Binary Ninja, so this is a workaround using unions.",
});
- bn_settings
- .register_setting_json(Self::ADD_BITFIELDS_SETTING, add_bitfields_props.to_string());
+ bn_settings.register_setting_json(
+ Self::ADD_BITFIELDS_SETTING,
+ &add_bitfields_props.to_string(),
+ );
let add_comments_props = json!({
"title" : "Add Comments",
@@ -51,7 +53,7 @@ impl LoadSettings {
"description" : "Whether to add comments. If you see comment placement is off, try disabling this.",
});
bn_settings
- .register_setting_json(Self::ADD_COMMENTS_SETTING, add_comments_props.to_string());
+ .register_setting_json(Self::ADD_COMMENTS_SETTING, &add_comments_props.to_string());
let file_props = json!({
"title" : "SVD File",
@@ -60,7 +62,7 @@ impl LoadSettings {
"description" : "The SVD File to automatically load when opening the view.",
"uiSelectionAction" : "file"
});
- bn_settings.register_setting_json(Self::AUTO_LOAD_FILE_SETTING, file_props.to_string());
+ bn_settings.register_setting_json(Self::AUTO_LOAD_FILE_SETTING, &file_props.to_string());
}
pub fn from_view_settings(view: &BinaryView) -> Self {