Adopt the new printf crate

This drops our usage of printf-compat.
This commit is contained in:
ridiculousfish 2024-05-12 15:40:00 -07:00 committed by Peter Ammon
parent 585dac6b08
commit f16a1361c5
15 changed files with 28 additions and 54 deletions

28
Cargo.lock generated
View File

@ -62,12 +62,6 @@ dependencies = [
"parking_lot_core",
]
[[package]]
name = "either"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
[[package]]
name = "errno"
version = "0.2.8"
@ -109,7 +103,7 @@ dependencies = [
"num-traits",
"once_cell",
"pcre2",
"printf-compat",
"printf",
"rand",
"rand_pcg",
"rsconf",
@ -150,15 +144,6 @@ version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]]
name = "jobserver"
version = "0.1.31"
@ -356,17 +341,6 @@ dependencies = [
"widestring",
]
[[package]]
name = "printf-compat"
version = "0.1.1"
source = "git+https://github.com/fish-shell/printf-compat.git?branch=fish#ff460021ba11e2a2c69e1fe04cb1961d6a75be15"
dependencies = [
"bitflags 1.3.2",
"itertools",
"libc",
"widestring",
]
[[package]]
name = "proc-macro2"
version = "1.0.82"

View File

@ -22,7 +22,6 @@ default-run = "fish"
[dependencies]
pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] }
fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" }
printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" }
bitflags = "2.4.0"
errno = "0.2.8"
@ -35,6 +34,7 @@ lru = "0.10.0"
nix = { version = "0.25.0", default-features = false, features = ["inotify", "resource", "fs"] }
num-traits = "0.2.15"
once_cell = "1.17.0"
printf = { path = "./printf" }
rand = { version = "0.8.5", features = ["small_rng"] }
widestring = "1.0.2"
terminfo = "0.9.0"

View File

@ -18,7 +18,7 @@ use crate::{
wutil::{fish_wcstoi, wgettext_fmt},
};
use libc::c_int;
use printf_compat::sprintf;
use printf::sprintf;
use std::num::NonZeroU32;
use std::sync::atomic::Ordering;

View File

@ -57,8 +57,7 @@ use crate::wutil::{
wcstoi::{wcstoi_partial, Options as WcstoiOpts},
wstr_offset_in,
};
use printf_compat::args::ToArg;
use printf_compat::printf::sprintf_locale;
use printf::{sprintf_locale, ToArg};
/// Return true if `c` is an octal digit.
fn is_octal_digit(c: char) -> bool {
@ -266,10 +265,10 @@ impl<'a, 'b> builtin_printf_state_t<'a, 'b> {
if !self.early_exit {
sprintf_locale(
&mut self.buff,
$fmt,
$fmt.as_char_slice(),
&self.locale,
&[$($arg.to_arg()),*]
)
&mut [$($arg.to_arg()),*]
).expect("sprintf failed");
}
}
}

View File

@ -1,5 +1,5 @@
use pcre2::utf32::{Captures, Regex, RegexBuilder};
use printf_compat::sprintf;
use printf::sprintf;
use std::collections::HashMap;
use super::*;

View File

@ -16,7 +16,7 @@ use crate::{
};
use bitflags::bitflags;
use once_cell::sync::Lazy;
use printf_compat::sprintf;
use printf::sprintf;
use crate::{
abbrs::with_abbrs,

View File

@ -41,8 +41,8 @@ impl ToWString for MaybeJobId {
}
}
impl<'a> printf_compat::args::ToArg<'a> for MaybeJobId {
fn to_arg(self) -> printf_compat::args::Arg<'a> {
impl<'a> printf::ToArg<'a> for MaybeJobId {
fn to_arg(self) -> printf::Arg<'a> {
self.as_num().to_arg()
}
}

View File

@ -1,5 +1,3 @@
use std::rc::Rc;
use libc::VERASE;
use crate::{
@ -376,9 +374,9 @@ impl std::fmt::Display for Key {
}
}
impl printf_compat::args::ToArg<'static> for Key {
fn to_arg(self) -> printf_compat::args::Arg<'static> {
printf_compat::args::Arg::BoxedStr(Rc::new(WString::from(self).into_boxed_utfstr()))
impl printf::ToArg<'static> for Key {
fn to_arg(self) -> printf::Arg<'static> {
printf::Arg::WString(self.into())
}
}

View File

@ -1,5 +1,5 @@
/// Support for the "current locale."
pub use printf_compat::locale::{Locale, C_LOCALE};
pub use printf::locale::{Locale, C_LOCALE};
use std::sync::Mutex;
/// Lock guarding libc `setlocale()` or `localeconv()` calls to avoid races.

View File

@ -235,9 +235,9 @@ impl ParseKeyword {
}
}
impl printf_compat::args::ToArg<'static> for ParseKeyword {
fn to_arg(self) -> printf_compat::args::Arg<'static> {
printf_compat::args::Arg::Str(self.to_wstr())
impl printf::ToArg<'static> for ParseKeyword {
fn to_arg(self) -> printf::Arg<'static> {
printf::Arg::WStr(self.to_wstr())
}
}

View File

@ -32,7 +32,7 @@ use crate::wchar::{wstr, WString, L};
use crate::wutil::{perror, wgettext, wgettext_fmt};
use crate::{function, FLOG};
use libc::c_int;
use printf_compat::sprintf;
use printf::sprintf;
use std::cell::{Ref, RefCell, RefMut};
use std::ffi::{CStr, OsStr};
use std::os::fd::{AsRawFd, OwnedFd, RawFd};

View File

@ -31,7 +31,7 @@ use libc::{
_SC_CLK_TCK,
};
use once_cell::sync::Lazy;
use printf_compat::sprintf;
use printf::sprintf;
use std::cell::{Cell, Ref, RefCell, RefMut};
use std::fs;
use std::io::{Read, Write};

View File

@ -191,9 +191,10 @@ impl From<TokenizerError> for &'static wstr {
}
}
impl printf_compat::args::ToArg<'static> for TokenizerError {
fn to_arg(self) -> printf_compat::args::Arg<'static> {
printf_compat::args::Arg::Str(self.into())
impl printf::ToArg<'static> for TokenizerError {
fn to_arg(self) -> printf::Arg<'static> {
let msg: &'static wstr = self.into();
printf::Arg::WStr(msg)
}
}

View File

@ -21,12 +21,14 @@ use crate::wchar_ext::WExt;
use crate::wcstringutil::{join_strings, wcs2string_callback};
use errno::errno;
pub use gettext::{wgettext, wgettext_fmt, wgettext_maybe_fmt, wgettext_str};
pub use printf::sprintf;
use std::ffi::{CStr, OsStr};
use std::fs::{self, canonicalize};
use std::io::{self, Write};
use std::os::unix::prelude::*;
extern crate printf as extern_printf;
pub use extern_printf::sprintf;
pub use wcstoi::*;
/// Wide character version of opendir(). Note that opendir() is guaranteed to set close-on-exec by

View File

@ -1,5 +1,5 @@
// Re-export sprintf macro.
pub use printf_compat::sprintf;
pub use printf::sprintf;
#[cfg(test)]
mod tests {