Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

Linux: C23 strtol family for glibc 2.35, so ONNX Runtime links on Ubuntu 22.04

Gabriele Lozupone1dc422849ff9
diff --git a/crates/qls-core/src/glibc_compat.rs b/crates/qls-core/src/glibc_compat.rs
new file mode 100644
index 0000000..d79f646
--- /dev/null
+++ b/crates/qls-core/src/glibc_compat.rs
@@ -0,0 +1,54 @@
+//! The C23 number parsers glibc 2.38 added, for glibc 2.35 (Ubuntu 22.04, which the .deb, .rpm and
+//! Docker image are built on and run on). The ONNX Runtime `ort` downloads for Linux (AI watermark,
+//! fast stickers) was compiled against glibc 2.38+, where `strtol` and friends become
+//! `__isoc23_strtol` etc.: linking it on 22.04 failed with exactly these three undefined (0.12.0,
+//! 2026-11-04). They differ from the classic ones only in also reading a "0b" prefix with base 0 or 2,
+//! which ONNX Runtime does not use (it parses its own model and config numbers); on newer glibc these
+//! stand in for glibc's with the same results.
+
+use std::os::raw::{c_char, c_int, c_long, c_longlong, c_ulonglong};
+
+unsafe extern "C" {
+ fn strtol(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_long;
+ fn strtoll(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_longlong;
+ fn strtoull(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_ulonglong;
+}
+
+/// # Safety
+/// As C `strtol`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn __isoc23_strtol(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_long {
+ unsafe { strtol(s, end, base) }
+}
+
+/// # Safety
+/// As C `strtoll`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn __isoc23_strtoll(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_longlong {
+ unsafe { strtoll(s, end, base) }
+}
+
+/// # Safety
+/// As C `strtoull`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn __isoc23_strtoull(s: *const c_char, end: *mut *mut c_char, base: c_int) -> c_ulonglong {
+ unsafe { strtoull(s, end, base) }
+}
+
+#[cfg(test)]
+mod tests {
+ use std::ffi::CString;
+
+ #[test]
+ fn they_parse_like_the_classic_ones() {
+ let s = CString::new(" -42xyz").unwrap();
+ let mut end = std::ptr::null_mut();
+ let v = unsafe { super::__isoc23_strtol(s.as_ptr(), &mut end, 10) };
+ assert_eq!(v, -42);
+ assert_eq!(unsafe { end.offset_from(s.as_ptr()) }, 5);
+ let h = CString::new("ff").unwrap();
+ assert_eq!(unsafe { super::__isoc23_strtoll(h.as_ptr(), std::ptr::null_mut(), 16) }, 255);
+ let u = CString::new("18446744073709551615").unwrap();
+ assert_eq!(unsafe { super::__isoc23_strtoull(u.as_ptr(), std::ptr::null_mut(), 10) }, u64::MAX);
+ }
+}
diff --git a/crates/qls-core/src/lib.rs b/crates/qls-core/src/lib.rs
index 1515667..0da1a88 100644
--- a/crates/qls-core/src/lib.rs
+++ b/crates/qls-core/src/lib.rs
@@ -12,6 +12,8 @@ pub mod heif;
pub mod imaging;
pub mod installer;
pub mod lora;
+#[cfg(all(target_os = "linux", target_env = "gnu"))]
+mod glibc_compat;
pub mod lut;
pub mod matting;
pub mod mac_bench;