Use right char type for ffi binding

On aarch64, `char` is unsigned (unlike x86-64 where it's signed), so use
`c_char` for the pointer so that it always matches the architecture.
This commit is contained in:
Jeremy Fitzhardinge authored and Wez Furlong committed 2020-11-11 20:31:18 -08:00
1 parent 37a3f7db5f
commit bf962c8b1a
2 files changed
+8 -7

No files matched your search

+3 -3
View File
@@ -6,7 +6,7 @@ pub use fontconfig::*;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::os::raw::c_int; use std::os::raw::{c_char, c_int};
use std::ptr; use std::ptr;
use std::sync::Mutex; use std::sync::Mutex;
@@ -208,7 +208,7 @@ impl Pattern {
let s = FcPatternFormat(self.pat, fmt.as_ptr() as *const u8); let s = FcPatternFormat(self.pat, fmt.as_ptr() as *const u8);
ensure!(!s.is_null(), "failed to format pattern"); ensure!(!s.is_null(), "failed to format pattern");
let res = CStr::from_ptr(s as *const i8) let res = CStr::from_ptr(s as *const c_char)
.to_string_lossy() .to_string_lossy()
.into_owned(); .into_owned();
FcStrFree(s); FcStrFree(s);
@@ -313,7 +313,7 @@ impl Pattern {
if !res.succeeded() { if !res.succeeded() {
Err(res.as_err()) Err(res.as_err())
} else { } else {
Ok(CStr::from_ptr(ptr as *const i8) Ok(CStr::from_ptr(ptr as *const c_char)
.to_string_lossy() .to_string_lossy()
.into_owned()) .into_owned())
} }
+5 -4
View File
@@ -8,6 +8,7 @@ pub use harfbuzz::*;
use anyhow::{ensure, Error}; use anyhow::{ensure, Error};
use std::mem; use std::mem;
use std::os::raw::c_char;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
@@ -42,7 +43,7 @@ hb_coretext_font_get_ct_font (hb_font_t *font);
pub fn language_from_string(s: &str) -> Result<hb_language_t, Error> { pub fn language_from_string(s: &str) -> Result<hb_language_t, Error> {
unsafe { unsafe {
let lang = hb_language_from_string(s.as_ptr() as *const i8, s.len() as i32); let lang = hb_language_from_string(s.as_ptr() as *const c_char, s.len() as i32);
ensure!(!lang.is_null(), "failed to convert {} to language"); ensure!(!lang.is_null(), "failed to convert {} to language");
Ok(lang) Ok(lang)
} }
@@ -53,7 +54,7 @@ pub fn feature_from_string(s: &str) -> Result<hb_feature_t, Error> {
let mut feature = mem::zeroed(); let mut feature = mem::zeroed();
ensure!( ensure!(
hb_feature_from_string( hb_feature_from_string(
s.as_ptr() as *const i8, s.as_ptr() as *const c_char,
s.len() as i32, s.len() as i32,
&mut feature as *mut _, &mut feature as *mut _,
) != 0, ) != 0,
@@ -92,7 +93,7 @@ impl Blob {
fn from_slice(data: &[u8]) -> Result<Self, Error> { fn from_slice(data: &[u8]) -> Result<Self, Error> {
let blob = unsafe { let blob = unsafe {
hb_blob_create( hb_blob_create(
data.as_ptr() as *const i8, data.as_ptr() as *const c_char,
data.len() as u32, data.len() as u32,
hb_memory_mode_t::HB_MEMORY_MODE_READONLY, hb_memory_mode_t::HB_MEMORY_MODE_READONLY,
ptr::null_mut(), ptr::null_mut(),
@@ -250,7 +251,7 @@ impl Buffer {
unsafe { unsafe {
hb_buffer_add_utf8( hb_buffer_add_utf8(
self.buf, self.buf,
buf.as_ptr() as *const i8, buf.as_ptr() as *const c_char,
buf.len() as i32, buf.len() as i32,
0, 0,
buf.len() as i32, buf.len() as i32,