mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
FLOG to stop depending on the ffi
Prior to this commit, FLOG used the ffi bridge to get the output fd. Invert this: have fish set the output fd within main. This allows FLOG to be used in pure Rust tests.
This commit is contained in:
parent
052823c120
commit
37fed01642
4 changed files with 23 additions and 5 deletions
|
@ -71,7 +71,6 @@ include_cpp! {
|
|||
|
||||
generate!("make_pipes_ffi")
|
||||
|
||||
generate!("get_flog_file_fd")
|
||||
generate!("log_extra_to_flog_file")
|
||||
|
||||
generate!("fish_wcwidth")
|
||||
|
|
|
@ -13,6 +13,7 @@ mod ffi2 {
|
|||
extern "Rust" {
|
||||
fn rust_init();
|
||||
fn rust_activate_flog_categories_by_pattern(wc_ptr: wcharz_t);
|
||||
fn rust_set_flog_file_fd(fd: i32);
|
||||
fn rust_invalidate_numeric_locale();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +30,11 @@ fn rust_activate_flog_categories_by_pattern(wc_ptr: wcharz_t) {
|
|||
crate::flog::activate_flog_categories_by_pattern(wc_ptr.into());
|
||||
}
|
||||
|
||||
/// FFI bridge for setting FLOG file descriptor.
|
||||
fn rust_set_flog_file_fd(fd: i32) {
|
||||
crate::flog::set_flog_file_fd(fd as libc::c_int);
|
||||
}
|
||||
|
||||
/// FFI bridge to invalidate cached locale bits.
|
||||
fn rust_invalidate_numeric_locale() {
|
||||
locale::invalidate_numeric_locale();
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use crate::ffi::{get_flog_file_fd, wildcard_match};
|
||||
use crate::ffi::wildcard_match;
|
||||
use crate::parse_util::parse_util_unescape_wildcards;
|
||||
use crate::wchar::{widestrs, wstr, WString};
|
||||
use crate::wchar_ext::WExt;
|
||||
use crate::wchar_ffi::WCharToFFI;
|
||||
use libc::c_int;
|
||||
use std::io::Write;
|
||||
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::os::unix::io::{FromRawFd, IntoRawFd};
|
||||
use std::sync::atomic::{AtomicI32, Ordering};
|
||||
|
||||
#[rustfmt::skip::macros(category)]
|
||||
#[widestrs]
|
||||
|
@ -162,7 +163,7 @@ pub trait FloggableDebug: std::fmt::Debug {
|
|||
|
||||
/// Write to our FLOG file.
|
||||
pub fn flog_impl(s: &str) {
|
||||
let fd = get_flog_file_fd().0 as RawFd;
|
||||
let fd = get_flog_file_fd();
|
||||
if fd < 0 {
|
||||
return;
|
||||
}
|
||||
|
@ -240,3 +241,14 @@ pub fn activate_flog_categories_by_pattern(wc_ptr: &wstr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The flog output fd. Defaults to stderr. A value < 0 disables flog.
|
||||
static FLOG_FD: AtomicI32 = AtomicI32::new(libc::STDERR_FILENO);
|
||||
|
||||
pub fn set_flog_file_fd(fd: c_int) {
|
||||
FLOG_FD.store(fd, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn get_flog_file_fd() -> c_int {
|
||||
FLOG_FD.load(Ordering::Relaxed)
|
||||
}
|
||||
|
|
|
@ -467,6 +467,7 @@ int main(int argc, char **argv) {
|
|||
set_cloexec(fileno(debug_output));
|
||||
setlinebuf(debug_output);
|
||||
set_flog_output_file(debug_output);
|
||||
rust_set_flog_file_fd(get_flog_file_fd());
|
||||
}
|
||||
|
||||
// No-exec is prohibited when in interactive mode.
|
||||
|
|
Loading…
Reference in a new issue