Skip to content

Commit 75e4c60

Browse files
committed
Replace BnStrCompatible with AsCStr trait
1 parent b3f2ef8 commit 75e4c60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1239
-2506
lines changed

plugins/warp/src/matcher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub struct PlatformID(u64);
506506
impl From<&Platform> for PlatformID {
507507
fn from(value: &Platform) -> Self {
508508
let mut hasher = DefaultHasher::new();
509-
hasher.write(value.name().to_bytes());
509+
hasher.write(value.name().as_bytes());
510510
Self(hasher.finish())
511511
}
512512
}

rust/src/architecture.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
platform::Platform,
2828
rc::*,
2929
relocation::CoreRelocationHandler,
30-
string::BnStrCompatible,
30+
string::AsCStr,
3131
string::*,
3232
types::{NameAndType, Type},
3333
Endianness,
@@ -1397,8 +1397,7 @@ impl CoreArchitecture {
13971397
}
13981398

13991399
pub fn by_name(name: &str) -> Option<Self> {
1400-
let handle =
1401-
unsafe { BNGetArchitectureByName(name.into_bytes_with_nul().as_ptr() as *mut _) };
1400+
let handle = unsafe { BNGetArchitectureByName(name.as_cstr().as_ptr()) };
14021401
match handle.is_null() {
14031402
false => Some(CoreArchitecture { handle }),
14041403
true => None,
@@ -1945,11 +1944,9 @@ macro_rules! cc_func {
19451944

19461945
/// Contains helper methods for all types implementing 'Architecture'
19471946
pub trait ArchitectureExt: Architecture {
1948-
fn register_by_name<S: BnStrCompatible>(&self, name: S) -> Option<Self::Register> {
1949-
let name = name.into_bytes_with_nul();
1950-
1947+
fn register_by_name<S: AsCStr>(&self, name: S) -> Option<Self::Register> {
19511948
match unsafe {
1952-
BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ref().as_ptr() as *mut _)
1949+
BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_cstr().as_ptr())
19531950
} {
19541951
0xffff_ffff => None,
19551952
reg => self.register_from_id(reg.into()),
@@ -2025,7 +2022,7 @@ pub trait ArchitectureExt: Architecture {
20252022

20262023
fn register_relocation_handler<S, R, F>(&self, name: S, func: F)
20272024
where
2028-
S: BnStrCompatible,
2025+
S: AsCStr,
20292026
R: 'static
20302027
+ RelocationHandler<Handle = CustomRelocationHandlerHandle<R>>
20312028
+ Send
@@ -2048,7 +2045,7 @@ impl<T: Architecture> ArchitectureExt for T {}
20482045

20492046
pub fn register_architecture<S, A, F>(name: S, func: F) -> &'static A
20502047
where
2051-
S: BnStrCompatible,
2048+
S: AsCStr,
20522049
A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync + Sized,
20532050
F: FnOnce(CustomArchitectureHandle<A>, CoreArchitecture) -> A,
20542051
{
@@ -3131,8 +3128,6 @@ where
31313128
custom_arch.skip_and_return_value(data, addr, val)
31323129
}
31333130

3134-
let name = name.into_bytes_with_nul();
3135-
31363131
let uninit_arch = ArchitectureBuilder {
31373132
arch: MaybeUninit::zeroed(),
31383133
func: Some(func),
@@ -3222,8 +3217,7 @@ where
32223217
};
32233218

32243219
unsafe {
3225-
let res =
3226-
BNRegisterArchitecture(name.as_ref().as_ptr() as *mut _, &mut custom_arch as *mut _);
3220+
let res = BNRegisterArchitecture(name.as_cstr().as_ptr(), &mut custom_arch as *mut _);
32273221

32283222
assert!(!res.is_null());
32293223

rust/src/background_task.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ impl BackgroundTask {
4343
Self { handle }
4444
}
4545

46-
pub fn new<S: BnStrCompatible>(initial_text: S, can_cancel: bool) -> Ref<Self> {
47-
let text = initial_text.into_bytes_with_nul();
48-
let handle = unsafe { BNBeginBackgroundTask(text.as_ref().as_ptr() as *mut _, can_cancel) };
46+
pub fn new<S: AsCStr>(initial_text: S, can_cancel: bool) -> Ref<Self> {
47+
let handle = unsafe { BNBeginBackgroundTask(initial_text.as_cstr().as_ptr(), can_cancel) };
4948
// We should always be returned a valid task.
5049
assert!(!handle.is_null());
5150
unsafe { Ref::new(Self { handle }) }
@@ -75,11 +74,8 @@ impl BackgroundTask {
7574
unsafe { BnString::from_raw(BNGetBackgroundTaskProgressText(self.handle)) }
7675
}
7776

78-
pub fn set_progress_text<S: BnStrCompatible>(&self, text: S) {
79-
let progress_text = text.into_bytes_with_nul();
80-
unsafe {
81-
BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ref().as_ptr() as *mut _)
82-
}
77+
pub fn set_progress_text<S: AsCStr>(&self, text: S) {
78+
unsafe { BNSetBackgroundTaskProgressText(self.handle, text.as_cstr().as_ptr()) }
8379
}
8480

8581
pub fn running_tasks() -> Array<BackgroundTask> {

0 commit comments

Comments
 (0)