Skip to content

Commit

Permalink
Use FFI types directly instead of maintaining own c_char definition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vlovich committed Jan 29, 2025
1 parent 68178db commit 8fc37d3
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions llama-cpp-2/src/sampling.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8fc37d3

Please sign in to comment.