Skip to content

Commit

Permalink
Fix tiktoken_c_version
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Aug 26, 2024
1 parent d0492b5 commit 4f170df
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use log::warn;
use simple_logger::SimpleLogger;
use std::ffi::{CStr, CString};
use std::ffi::CStr;
use std::os::raw::c_char;
use tiktoken_rs;
use tiktoken_rs::CoreBPE;
Expand Down Expand Up @@ -462,22 +462,14 @@ pub extern "C" fn tiktoken_corebpe_decode(

#[no_mangle]
pub extern "C" fn tiktoken_c_version() -> *const c_char {
const TIKTOKEN_C_VERSION: &str = env!("CARGO_PKG_VERSION");
let c_str = match CString::new(TIKTOKEN_C_VERSION.to_string()) {
Ok(c_str) => c_str,
Err(_) => {
warn!("Failed to convert to CString!");
// "unknown" version
CString::new("unknown".to_string()).unwrap()
}
};
let ptr = c_str.into_raw();
ptr
static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");
VERSION.as_ptr() as *const c_char
}

#[cfg(test)]
mod tests {
use super::*;
use std::ffi::CString;

#[test]
fn test_tiktoken_c_version() {
Expand Down

0 comments on commit 4f170df

Please sign in to comment.