From 788a8b7091bbdde77817030e0836d7a7a786fd99 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:47:55 -0400 Subject: [Rust] Simplify usage surrounding c strings `cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()` `cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()` `cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()` With a few fixes for cstrings that might be dropped prematurely. --- rust/src/platform.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'rust/src/platform.rs') diff --git a/rust/src/platform.rs b/rust/src/platform.rs index 19186740..c225392f 100644 --- a/rust/src/platform.rs +++ b/rust/src/platform.rs @@ -85,7 +85,7 @@ impl Platform { pub fn by_name(name: S) -> Option> { let raw_name = name.to_cstr(); unsafe { - let res = BNGetPlatformByName(raw_name.as_ref().as_ptr() as *mut _); + let res = BNGetPlatformByName(raw_name.as_ptr()); if res.is_null() { None @@ -118,7 +118,7 @@ impl Platform { unsafe { let mut count = 0; - let handles = BNGetPlatformListByOS(raw_name.as_ref().as_ptr() as *mut _, &mut count); + let handles = BNGetPlatformListByOS(raw_name.as_ptr(), &mut count); Array::new(handles, count, ()) } @@ -129,11 +129,8 @@ impl Platform { unsafe { let mut count = 0; - let handles = BNGetPlatformListByOSAndArchitecture( - raw_name.as_ref().as_ptr() as *mut _, - arch.handle, - &mut count, - ); + let handles = + BNGetPlatformListByOSAndArchitecture(raw_name.as_ptr(), arch.handle, &mut count); Array::new(handles, count, ()) } @@ -151,7 +148,7 @@ impl Platform { pub fn new(arch: &A, name: S) -> Ref { let name = name.to_cstr(); unsafe { - let handle = BNCreatePlatform(arch.as_ref().handle, name.as_ref().as_ptr() as *mut _); + let handle = BNCreatePlatform(arch.as_ref().handle, name.as_ptr()); assert!(!handle.is_null()); Ref::new(Self { handle }) } @@ -179,13 +176,8 @@ impl Platform { pub fn get_type_libraries_by_name(&self, name: T) -> Array { let mut count = 0; let name = name.to_cstr(); - let result = unsafe { - BNGetPlatformTypeLibrariesByName( - self.handle, - name.as_ref().as_ptr() as *mut _, - &mut count, - ) - }; + let result = + unsafe { BNGetPlatformTypeLibrariesByName(self.handle, name.as_ptr(), &mut count) }; assert!(!result.is_null()); unsafe { Array::new(result, count, ()) } } @@ -194,7 +186,7 @@ impl Platform { let os = os.to_cstr(); unsafe { - BNRegisterPlatform(os.as_ref().as_ptr() as *mut _, self.handle); + BNRegisterPlatform(os.as_ptr(), self.handle); } } -- cgit v1.3.1