From 8fc37d308fe79ab3638e027d869ec5c007ea6085 Mon Sep 17 00:00:00 2001 From: Vitali Lovich Date: Wed, 29 Jan 2025 08:04:01 -0800 Subject: [PATCH] Use FFI types directly instead of maintaining own c_char definition The standard library predefines c_char exactly for this purpose to get rid of manual CChar type aliases. While the alias in theory looks fine it was making cargo-ndk unhappy for some reason whereas using the natural stdlib c_char type works perfectly. --- llama-cpp-2/src/sampling.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/llama-cpp-2/src/sampling.rs b/llama-cpp-2/src/sampling.rs index b3a2cf4f..d79f351b 100644 --- a/llama-cpp-2/src/sampling.rs +++ b/llama-cpp-2/src/sampling.rs @@ -1,7 +1,7 @@ //! Safe wrapper around `llama_sampler`. use std::borrow::Borrow; -use std::ffi::CString; +use std::ffi::{c_char, CString}; use std::fmt::{Debug, Formatter}; use crate::context::LlamaContext; @@ -20,14 +20,6 @@ impl Debug for LlamaSampler { } } -// this is needed for the dry sampler to typecheck on android -// ...because what is normally an i8, is an u8 -#[cfg(target_os = "android")] -type CChar = u8; - -#[cfg(not(target_os = "android"))] -type CChar = i8; - impl LlamaSampler { /// Sample and accept a token from the idx-th output of the last evaluation #[must_use] @@ -266,7 +258,7 @@ impl LlamaSampler { .into_iter() .map(|s| CString::new(s.as_ref()).expect("A sequence breaker contains null bytes")) .collect(); - let mut seq_breaker_pointers: Vec<*const CChar> = + let mut seq_breaker_pointers: Vec<*const c_char> = seq_breakers.iter().map(|s| s.as_ptr()).collect(); let sampler = unsafe {