From bf962c8b1a345889cf7dab9c97ebc212b0bc2f26 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 9 Nov 2020 00:25:38 -0800 Subject: [PATCH] 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. --- wezterm-font/src/fcwrap.rs | 6 +++--- wezterm-font/src/hbwrap.rs | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/wezterm-font/src/fcwrap.rs b/wezterm-font/src/fcwrap.rs index 1b883f6e9..4ca7ec437 100644 --- a/wezterm-font/src/fcwrap.rs +++ b/wezterm-font/src/fcwrap.rs @@ -6,7 +6,7 @@ pub use fontconfig::*; use std::ffi::{CStr, CString}; use std::fmt; use std::mem; -use std::os::raw::c_int; +use std::os::raw::{c_char, c_int}; use std::ptr; use std::sync::Mutex; @@ -208,7 +208,7 @@ impl Pattern { let s = FcPatternFormat(self.pat, fmt.as_ptr() as *const u8); 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() .into_owned(); FcStrFree(s); @@ -313,7 +313,7 @@ impl Pattern { if !res.succeeded() { Err(res.as_err()) } else { - Ok(CStr::from_ptr(ptr as *const i8) + Ok(CStr::from_ptr(ptr as *const c_char) .to_string_lossy() .into_owned()) } diff --git a/wezterm-font/src/hbwrap.rs b/wezterm-font/src/hbwrap.rs index e7161d692..c78d28973 100644 --- a/wezterm-font/src/hbwrap.rs +++ b/wezterm-font/src/hbwrap.rs @@ -8,6 +8,7 @@ pub use harfbuzz::*; use anyhow::{ensure, Error}; use std::mem; +use std::os::raw::c_char; use std::ptr; 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 { 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"); Ok(lang) } @@ -53,7 +54,7 @@ pub fn feature_from_string(s: &str) -> Result { let mut feature = mem::zeroed(); ensure!( hb_feature_from_string( - s.as_ptr() as *const i8, + s.as_ptr() as *const c_char, s.len() as i32, &mut feature as *mut _, ) != 0, @@ -92,7 +93,7 @@ impl Blob { fn from_slice(data: &[u8]) -> Result { let blob = unsafe { hb_blob_create( - data.as_ptr() as *const i8, + data.as_ptr() as *const c_char, data.len() as u32, hb_memory_mode_t::HB_MEMORY_MODE_READONLY, ptr::null_mut(), @@ -250,7 +251,7 @@ impl Buffer { unsafe { hb_buffer_add_utf8( self.buf, - buf.as_ptr() as *const i8, + buf.as_ptr() as *const c_char, buf.len() as i32, 0, buf.len() as i32,