fix(config): match Zig's numeric grammar, NUL handling and diagnostics
Resolves the 6 differential gap groups in docs/rewrite/notes/review- rv9-codex.md (details in final-Z11.md): - ghostty_os::zig_fmt ports std.fmt.parseInt/parseUnsigned/parseFloat (underscores, 0x/0o/0b prefixes, hex floats, inf/nan) with the Zig std tests and replaces every int/float parse in config, keybind parameters, ssh-cache and desktop detection. - Interior NUL no longer panics in font names and ends C strings like Zig's backing bytes (fontconfig, C config getters, title actions, clipboard callback, relative paths, config-file, shaders, background image, GTK CSS). - GTK new-window arguments are trimmed of ASCII whitespace only. - Command tokenization uses a port of std.process.ArgIteratorGeneral (incl. CR/LF separators) with its std tests. - UTF-8 validation happens where Zig's field parsers do it, so error kinds match (metric modifiers, quick-terminal size, link, ...). A scripted differential run of 202 fields x ~220 hostile/valid values against /usr/bin/ghostty (+validate-config and +show-config: exit code, stdout, stderr) now has zero mismatches besides build-specific defaults (theme resources path, auto-update-channel, gtk-opengl-debug); it also surfaced and fixed background-blur failure state, NaN formatting and NaN/-0 finalize clamps. Regression tests: ghostty-config/tests/ zig_parity.rs. Test Plan: - cargo test --workspace --no-fail-fast (3456 passed, exit 0) - just check-macos (both), just check-windows, just check-wasm
This commit is contained in:
1 parent
61e7a680ac
commit
a57ff41d34
26 files changed
+1835
-228
No files matched your search
@@ -34,16 +34,15 @@ pub struct Keep {
|
||||
}
|
||||
|
||||
impl Keep {
|
||||
/// A NUL terminated copy of `s` (interior NULs are dropped).
|
||||
/// A NUL terminated copy of `s` (it ends at the first interior NUL).
|
||||
fn cstr(&mut self, s: &str) -> *const c_char {
|
||||
self.cstr_bytes(s.as_bytes())
|
||||
}
|
||||
|
||||
/// [`Keep::cstr`] for raw bytes.
|
||||
fn cstr_bytes(&mut self, s: &[u8]) -> *const c_char {
|
||||
let mut s = s.to_vec();
|
||||
s.retain(|&b| b != 0);
|
||||
let c = CString::new(s).unwrap_or_default();
|
||||
let end = s.iter().position(|&b| b == 0).unwrap_or(s.len());
|
||||
let c = CString::new(&s[..end]).unwrap_or_default();
|
||||
let ptr = c.as_ptr();
|
||||
// The heap buffer of a CString doesn't move when the Vec grows.
|
||||
self.strings.push(c);
|
||||
@@ -241,6 +240,26 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn c_title_actions_end_at_the_first_interior_nul() {
|
||||
use ghostty_os::osbytes::EncodedOs;
|
||||
let mut keep = Keep::default();
|
||||
for tab in [false, true] {
|
||||
let title = SetTitle {
|
||||
title: EncodedOs::from_bytes(b"a\0b"),
|
||||
};
|
||||
let action = if tab {
|
||||
Action::SetTabTitle(title)
|
||||
} else {
|
||||
Action::SetTitle(title)
|
||||
};
|
||||
let c = action_to_c(&action, &mut keep);
|
||||
// SAFETY: both title union members have identical layout, pointer owned by keep.
|
||||
let title = unsafe { std::ffi::CStr::from_ptr(c.action.set_title.title) };
|
||||
assert_eq!(title.to_bytes(), b"a");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn c_title_actions_and_key_table_names_forward_original_bytes() {
|
||||
use ghostty_os::osbytes::EncodedOs;
|
||||
|
||||
Reference in new issue
Block a user