已合并
fix(hicc-rs): use core::ffi::c_char instead of hardcoded *const i8 #110
Sparrow Li (LiYuan)创建于 8月28日
fix(hicc-rs): use core::ffi::c_char instead of hardcoded *const i8 #110
已合并
Sparrow Li (LiYuan)创建于 8月28日
共 2 个文件变更+7-5
@@ -22,7 +22,7 @@ impl String {
22 fn push_str(&mut self, s: &str);22 fn push_str(&mut self, s: &str);
23 fn as_str(&self) -> &str;23 fn as_str(&self) -> &str;
24 fn as_bytes(&self) -> &[u8];24 fn as_bytes(&self) -> &[u8];
25- fn push_pchar(&mut self, s: *const i8) {25+ fn push_pchar(&mut self, s: *const ffi::c_char) {
26 if s.is_null() {26 if s.is_null() {
27 return;27 return;
28 }28 }
@@ -43,7 +43,7 @@ impl String {
43 }43 }
44 }44 }
45 fn insert_str(&mut self, idx: usize, s: &str);45 fn insert_str(&mut self, idx: usize, s: &str);
46- fn insert_pchar(&mut self, idx: usize, s: *const i8) {46+ fn insert_pchar(&mut self, idx: usize, s: *const ffi::c_char) {
47 if s.is_null() {47 if s.is_null() {
48 return;48 return;
49 }49 }
@@ -1,5 +1,5 @@
1use crate::{AbiType, ValueType, IsPOD, IsValue};1use crate::{AbiType, ValueType, IsPOD, IsValue};
2-use core::ffi::CStr;2+use core::ffi::{c_char, CStr};
3 3 
4impl ValueType for &CStr {4impl ValueType for &CStr {
5 const N: usize = 0;5 const N: usize = 0;
@@ -10,8 +10,10 @@ impl ValueType for &CStr {
10 10 
11impl AbiType for &CStr {11impl AbiType for &CStr {
12 type Target = &'static CStr;12 type Target = &'static CStr;
13- type InputType = *const i8;13+ // c_char, not i8: c_char is u8 on arm/aarch64 targets and i8 on x86_64;
14- type OutputType = *const i8;14+ // hardcoding i8 breaks CStr::from_ptr / as_ptr on armv7-unknown-linux-ohos.
15+ type InputType = *const c_char;
16+ type OutputType = *const c_char;
15 fn from_abi(src: Self::InputType) -> Self::Target {17 fn from_abi(src: Self::InputType) -> Self::Target {
16 if !src.is_null() {18 if !src.is_null() {
17 return unsafe { CStr::from_ptr(src) };19 return unsafe { CStr::from_ptr(src) };