Skip to content

Commit 193b836

Browse files
committed
Replace BnStrCompatible with AsCStr trait
1 parent 3f1533e commit 193b836

Some content is hidden

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

43 files changed

+985
-1981
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,
@@ -1928,11 +1927,9 @@ macro_rules! cc_func {
19281927

19291928
/// Contains helper methods for all types implementing 'Architecture'
19301929
pub trait ArchitectureExt: Architecture {
1931-
fn register_by_name<S: BnStrCompatible>(&self, name: S) -> Option<Self::Register> {
1932-
let name = name.into_bytes_with_nul();
1933-
1930+
fn register_by_name<S: AsCStr>(&self, name: S) -> Option<Self::Register> {
19341931
match unsafe {
1935-
BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ref().as_ptr() as *mut _)
1932+
BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_cstr().as_ptr())
19361933
} {
19371934
0xffff_ffff => None,
19381935
reg => self.register_from_id(reg.into()),
@@ -2008,7 +2005,7 @@ pub trait ArchitectureExt: Architecture {
20082005

20092006
fn register_relocation_handler<S, R, F>(&self, name: S, func: F)
20102007
where
2011-
S: BnStrCompatible,
2008+
S: AsCStr,
20122009
R: 'static
20132010
+ RelocationHandler<Handle = CustomRelocationHandlerHandle<R>>
20142011
+ Send
@@ -2031,7 +2028,7 @@ impl<T: Architecture> ArchitectureExt for T {}
20312028

20322029
pub fn register_architecture<S, A, F>(name: S, func: F) -> &'static A
20332030
where
2034-
S: BnStrCompatible,
2031+
S: AsCStr,
20352032
A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync + Sized,
20362033
F: FnOnce(CustomArchitectureHandle<A>, CoreArchitecture) -> A,
20372034
{
@@ -3114,8 +3111,6 @@ where
31143111
custom_arch.skip_and_return_value(data, addr, val)
31153112
}
31163113

3117-
let name = name.into_bytes_with_nul();
3118-
31193114
let uninit_arch = ArchitectureBuilder {
31203115
arch: MaybeUninit::zeroed(),
31213116
func: Some(func),
@@ -3205,8 +3200,7 @@ where
32053200
};
32063201

32073202
unsafe {
3208-
let res =
3209-
BNRegisterArchitecture(name.as_ref().as_ptr() as *mut _, &mut custom_arch as *mut _);
3203+
let res = BNRegisterArchitecture(name.as_cstr().as_ptr(), &mut custom_arch as *mut _);
32103204

32113205
assert!(!res.is_null());
32123206

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)