From 11e16ef6df02a2a15733688b1fb23bd7d3dcdc27 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 8 Apr 2023 09:24:30 +0200 Subject: [PATCH] env.rs: rename flags::EnvMode to EnvMode The "flags" module was introduced when these where standalone constants. Now that we define them as bitflags, we no longer need the extra namespace. --- fish-rust/src/builtins/abbr.rs | 2 +- fish-rust/src/builtins/pwd.rs | 2 +- fish-rust/src/env.rs | 87 ++++++++++++++++++---------------- fish-rust/src/ffi.rs | 2 +- fish-rust/src/termsize.rs | 2 +- 5 files changed, 50 insertions(+), 45 deletions(-) diff --git a/fish-rust/src/builtins/abbr.rs b/fish-rust/src/builtins/abbr.rs index 68935eb6e..422692c32 100644 --- a/fish-rust/src/builtins/abbr.rs +++ b/fish-rust/src/builtins/abbr.rs @@ -5,8 +5,8 @@ STATUS_CMD_OK, STATUS_INVALID_ARGS, }; use crate::common::{escape_string, valid_func_name, EscapeStringStyle}; -use crate::env::flags::EnvMode; use crate::env::status::{ENV_NOT_FOUND, ENV_OK}; +use crate::env::EnvMode; use crate::ffi::parser_t; use crate::re::{regex_make_anchored, to_boxed_chars}; use crate::wchar::{wstr, L}; diff --git a/fish-rust/src/builtins/pwd.rs b/fish-rust/src/builtins/pwd.rs index 09a9f96c1..93b3a510a 100644 --- a/fish-rust/src/builtins/pwd.rs +++ b/fish-rust/src/builtins/pwd.rs @@ -4,7 +4,7 @@ use crate::{ builtins::shared::{io_streams_t, BUILTIN_ERR_ARG_COUNT1}, - env::flags::EnvMode, + env::EnvMode, ffi::parser_t, wchar::{wstr, WString, L}, wchar_ffi::{WCharFromFFI, WCharToFFI}, diff --git a/fish-rust/src/env.rs b/fish-rust/src/env.rs index 2b76043b9..df3a2650b 100644 --- a/fish-rust/src/env.rs +++ b/fish-rust/src/env.rs @@ -1,47 +1,52 @@ -/// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get(). -pub mod flags { - use autocxx::c_int; - use bitflags::bitflags; +//! Prototypes for functions for manipulating fish script variables. - bitflags! { - /// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get(). - #[repr(C)] - pub struct EnvMode: u16 { - /// Default mode. Used with `env_stack_t::get()` to indicate the caller doesn't care what scope - /// the var is in or whether it is exported or unexported. - const DEFAULT = 0; - /// Flag for local (to the current block) variable. - const LOCAL = 1 << 0; - const FUNCTION = 1 << 1; - /// Flag for global variable. - const GLOBAL = 1 << 2; - /// Flag for universal variable. - const UNIVERSAL = 1 << 3; - /// Flag for exported (to commands) variable. - const EXPORT = 1 << 4; - /// Flag for unexported variable. - const UNEXPORT = 1 << 5; - /// Flag to mark a variable as a path variable. - const PATHVAR = 1 << 6; - /// Flag to unmark a variable as a path variable. - const UNPATHVAR = 1 << 7; - /// Flag for variable update request from the user. All variable changes that are made directly - /// by the user, such as those from the `read` and `set` builtin must have this flag set. It - /// serves one purpose: to indicate that an error should be returned if the user is attempting - /// to modify a var that should not be modified by direct user action; e.g., a read-only var. - const USER = 1 << 8; - } - } +use autocxx::c_int; +use bitflags::bitflags; - impl From for c_int { - fn from(val: EnvMode) -> Self { - c_int(i32::from(val.bits())) - } +// Limit `read` to 100 MiB (bytes not wide chars) by default. This can be overridden by the +// fish_read_limit variable. +const DEFAULT_READ_BYTE_LIMIT: usize = 100 * 1024 * 1024; +pub static mut read_byte_limit: usize = DEFAULT_READ_BYTE_LIMIT; +pub static mut curses_initialized: bool = true; + +bitflags! { + /// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get(). + #[repr(C)] + pub struct EnvMode: u16 { + /// Default mode. Used with `env_stack_t::get()` to indicate the caller doesn't care what scope + /// the var is in or whether it is exported or unexported. + const DEFAULT = 0; + /// Flag for local (to the current block) variable. + const LOCAL = 1 << 0; + const FUNCTION = 1 << 1; + /// Flag for global variable. + const GLOBAL = 1 << 2; + /// Flag for universal variable. + const UNIVERSAL = 1 << 3; + /// Flag for exported (to commands) variable. + const EXPORT = 1 << 4; + /// Flag for unexported variable. + const UNEXPORT = 1 << 5; + /// Flag to mark a variable as a path variable. + const PATHVAR = 1 << 6; + /// Flag to unmark a variable as a path variable. + const UNPATHVAR = 1 << 7; + /// Flag for variable update request from the user. All variable changes that are made directly + /// by the user, such as those from the `read` and `set` builtin must have this flag set. It + /// serves one purpose: to indicate that an error should be returned if the user is attempting + /// to modify a var that should not be modified by direct user action; e.g., a read-only var. + const USER = 1 << 8; } - impl From for u16 { - fn from(val: EnvMode) -> Self { - val.bits() - } +} + +impl From for c_int { + fn from(val: EnvMode) -> Self { + c_int(i32::from(val.bits())) + } +} +impl From for u16 { + fn from(val: EnvMode) -> Self { + val.bits() } } diff --git a/fish-rust/src/ffi.rs b/fish-rust/src/ffi.rs index 7e2558939..31f1c6637 100644 --- a/fish-rust/src/ffi.rs +++ b/fish-rust/src/ffi.rs @@ -4,7 +4,7 @@ use ::std::pin::Pin; #[rustfmt::skip] use ::std::slice; -use crate::env::flags::EnvMode; +use crate::env::EnvMode; pub use crate::wait_handle::{ WaitHandleRef, WaitHandleRefFFI, WaitHandleStore, WaitHandleStoreFFI, }; diff --git a/fish-rust/src/termsize.rs b/fish-rust/src/termsize.rs index 7442bc227..089d62f6c 100644 --- a/fish-rust/src/termsize.rs +++ b/fish-rust/src/termsize.rs @@ -1,6 +1,6 @@ // Support for exposing the terminal size. use crate::common::assert_sync; -use crate::env::flags::EnvMode; +use crate::env::EnvMode; use crate::ffi::{environment_t, parser_t, Repin}; use crate::flog::FLOG; use crate::wchar::{WString, L};