From e1bcae0b6259f6d18455636f416cbf49c5d01e38 Mon Sep 17 00:00:00 2001 From: jonathanrainer Date: Mon, 16 Mar 2026 21:27:14 +0000 Subject: [PATCH] fix: use libc::c_char instead of i8 for char pointer casts On ARM64 Linux, C `char` is unsigned (u8), so the fyaml-sys bindings emit `*const u8` for `const char *` parameters. The hardcoded `as *const i8` casts fail to compile on aarch64-unknown-linux-musl. Replace all `as *const i8` with `as *const libc::c_char` (= i8 on x86_64, u8 on aarch64) so the casts match the platform-appropriate type produced by bindgen, enabling builds on both architectures. --- src/document.rs | 4 ++-- src/editor.rs | 15 ++++++++------- src/node_ref.rs | 4 ++-- src/parser.rs | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/document.rs b/src/document.rs index d01607a..8cf0f45 100644 --- a/src/document.rs +++ b/src/document.rs @@ -232,7 +232,7 @@ impl Document { // SAFETY: fy_document_build_from_string borrows the input - the String must // remain valid for the document's lifetime. We keep it in InputOwnership::OwnedString. let doc_ptr = - unsafe { fy_document_build_from_string(&cfg, s.as_ptr() as *const i8, s.len()) }; + unsafe { fy_document_build_from_string(&cfg, s.as_ptr() as *const libc::c_char, s.len()) }; if doc_ptr.is_null() { return Err(diag_error(diag, "fy_document_build_from_string failed")); } @@ -289,7 +289,7 @@ impl Document { // SAFETY: fy_document_build_from_string borrows the input - the Vec must // remain valid for the document's lifetime. We keep it in InputOwnership::OwnedBytes. let doc_ptr = unsafe { - fy_document_build_from_string(&cfg, bytes.as_ptr() as *const i8, bytes.len()) + fy_document_build_from_string(&cfg, bytes.as_ptr() as *const libc::c_char, bytes.len()) }; if doc_ptr.is_null() { return Err(diag_error(diag, "fy_document_build_from_string failed")); diff --git a/src/editor.rs b/src/editor.rs index 6e57aaf..2a655c2 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -7,6 +7,7 @@ use crate::ffi_util::malloc_copy; use crate::node_ref::NodeRef; use fyaml_sys::*; +use libc::c_char; use std::ptr::{self, NonNull}; // ============================================================================= @@ -231,7 +232,7 @@ impl<'doc> Editor<'doc> { let parent_ptr = unsafe { fy_node_by_path( root_ptr, - parent_path.as_ptr() as *const i8, + parent_path.as_ptr() as *const c_char, parent_path.len(), 0, ) @@ -315,7 +316,7 @@ impl<'doc> Editor<'doc> { let pair_ptr = unsafe { fy_node_mapping_lookup_pair_by_string( parent_ptr, - key.as_ptr() as *const i8, + key.as_ptr() as *const c_char, key.len(), ) }; @@ -329,7 +330,7 @@ impl<'doc> Editor<'doc> { } else { // Create new key and append let key_ptr = unsafe { - fy_node_create_scalar_copy(self.doc_ptr(), key.as_ptr() as *const i8, key.len()) + fy_node_create_scalar_copy(self.doc_ptr(), key.as_ptr() as *const c_char, key.len()) }; if key_ptr.is_null() { return Err(Error::Ffi("fy_node_create_scalar_copy failed")); @@ -438,7 +439,7 @@ impl<'doc> Editor<'doc> { let pair_ptr = unsafe { fy_node_mapping_lookup_pair_by_string( parent_ptr, - key.as_ptr() as *const i8, + key.as_ptr() as *const c_char, key.len(), ) }; @@ -547,7 +548,7 @@ impl<'doc> Editor<'doc> { /// The scalar style is automatically determined based on content. /// Use [`build_from_yaml`](Self::build_from_yaml) for explicit quoting. pub fn build_scalar(&mut self, value: &str) -> Result { - self.build_scalar_raw(value.as_ptr() as *const i8, value.len()) + self.build_scalar_raw(value.as_ptr() as *const c_char, value.len()) } /// Builds an empty sequence node. @@ -666,7 +667,7 @@ impl<'doc> Editor<'doc> { /// /// For example, `set_tag(&mut node, "!custom")` produces `!custom value`. pub fn set_tag(&mut self, node: &mut RawNodeHandle, tag: &str) -> Result<()> { - let ret = unsafe { fy_node_set_tag(node.as_ptr(), tag.as_ptr() as *const i8, tag.len()) }; + let ret = unsafe { fy_node_set_tag(node.as_ptr(), tag.as_ptr() as *const c_char, tag.len()) }; if ret != 0 { return Err(Error::Ffi("fy_node_set_tag failed")); } @@ -718,7 +719,7 @@ impl<'doc> Editor<'doc> { return Ok(root_ptr); } let node_ptr = - unsafe { fy_node_by_path(root_ptr, path.as_ptr() as *const i8, path.len(), 0) }; + unsafe { fy_node_by_path(root_ptr, path.as_ptr() as *const c_char, path.len(), 0) }; if node_ptr.is_null() { return Err(Error::Ffi("path not found")); } diff --git a/src/node_ref.rs b/src/node_ref.rs index 4eec5de..ddc1074 100644 --- a/src/node_ref.rs +++ b/src/node_ref.rs @@ -260,7 +260,7 @@ impl<'doc> NodeRef<'doc> { /// ``` pub fn at_path(&self, path: &str) -> Option> { let node_ptr = - unsafe { fy_node_by_path(self.as_ptr(), path.as_ptr() as *const i8, path.len(), 0) }; + unsafe { fy_node_by_path(self.as_ptr(), path.as_ptr() as *const libc::c_char, path.len(), 0) }; NonNull::new(node_ptr).map(|nn| NodeRef::new(nn, self.doc)) } @@ -344,7 +344,7 @@ impl<'doc> NodeRef<'doc> { return None; } let node_ptr = unsafe { - fy_node_mapping_lookup_by_string(self.as_ptr(), key.as_ptr() as *const i8, key.len()) + fy_node_mapping_lookup_by_string(self.as_ptr(), key.as_ptr() as *const libc::c_char, key.len()) }; NonNull::new(node_ptr).map(|nn| NodeRef::new(nn, self.doc)) } diff --git a/src/parser.rs b/src/parser.rs index fd119d2..6f1abc4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -172,7 +172,7 @@ impl FyParser { return Err(Error::Io("dup(stdin) failed")); } - let fp = unsafe { libc::fdopen(dup_fd, b"r\0".as_ptr() as *const i8) }; + let fp = unsafe { libc::fdopen(dup_fd, b"r\0".as_ptr() as *const libc::c_char) }; if fp.is_null() { unsafe { libc::close(dup_fd) }; return Err(Error::Io("fdopen failed")); @@ -187,7 +187,7 @@ impl FyParser { } let ret = unsafe { - fy_parser_set_input_fp(parser.inner.as_ptr(), b"stdin\0".as_ptr() as *const i8, fp) + fy_parser_set_input_fp(parser.inner.as_ptr(), b"stdin\0".as_ptr() as *const libc::c_char, fp) }; if ret != 0 { unsafe { libc::fclose(fp) };