diff --git a/fish-rust/src/future_feature_flags.rs b/fish-rust/src/future_feature_flags.rs index 3b1d86e42..1eeeb8781 100644 --- a/fish-rust/src/future_feature_flags.rs +++ b/fish-rust/src/future_feature_flags.rs @@ -18,7 +18,7 @@ mod future_feature_flags_ffi { /// The list of flags. #[repr(u8)] - enum feature_flag_t { + enum FeatureFlag { /// Whether ^ is supported for stderr redirection. stderr_nocaret, @@ -34,7 +34,7 @@ enum feature_flag_t { /// Metadata about feature flags. struct feature_metadata_t { - flag: feature_flag_t, + flag: FeatureFlag, name: UniquePtr, groups: UniquePtr, description: UniquePtr, @@ -43,20 +43,20 @@ struct feature_metadata_t { } extern "Rust" { - type features_t; - fn test(self: &features_t, flag: feature_flag_t) -> bool; - fn set(self: &mut features_t, flag: feature_flag_t, value: bool); - fn set_from_string(self: &mut features_t, str: wcharz_t); - fn fish_features() -> *const features_t; - fn feature_test(flag: feature_flag_t) -> bool; - fn mutable_fish_features() -> *mut features_t; + type Features; + fn test(self: &Features, flag: FeatureFlag) -> bool; + fn set(self: &mut Features, flag: FeatureFlag, value: bool); + fn set_from_string(self: &mut Features, str: wcharz_t); + fn fish_features() -> *const Features; + fn feature_test(flag: FeatureFlag) -> bool; + fn mutable_fish_features() -> *mut Features; fn feature_metadata() -> [feature_metadata_t; 4]; } } -pub use future_feature_flags_ffi::{feature_flag_t, feature_metadata_t}; +pub use future_feature_flags_ffi::{feature_metadata_t, FeatureFlag}; -pub struct features_t { +pub struct Features { // Values for the flags. // These are atomic to "fix" a race reported by tsan where tests of feature flags and other // tests which use them conceptually race. @@ -66,7 +66,7 @@ pub struct features_t { /// Metadata about feature flags. struct FeatureMetadata { /// The flag itself. - flag: feature_flag_t, + flag: FeatureFlag, /// User-presentable short name of the feature flag. name: &'static wstr, @@ -101,7 +101,7 @@ fn from(md: &FeatureMetadata) -> feature_metadata_t { #[widestrs] const metadata: [FeatureMetadata; 4] = [ FeatureMetadata { - flag: feature_flag_t::stderr_nocaret, + flag: FeatureFlag::stderr_nocaret, name: "stderr-nocaret"L, groups: "3.0"L, description: "^ no longer redirects stderr (historical, can no longer be changed)"L, @@ -109,7 +109,7 @@ fn from(md: &FeatureMetadata) -> feature_metadata_t { read_only: true, }, FeatureMetadata { - flag: feature_flag_t::qmark_noglob, + flag: FeatureFlag::qmark_noglob, name: "qmark-noglob"L, groups: "3.0"L, description: "? no longer globs"L, @@ -117,7 +117,7 @@ fn from(md: &FeatureMetadata) -> feature_metadata_t { read_only: false, }, FeatureMetadata { - flag: feature_flag_t::string_replace_backslash, + flag: FeatureFlag::string_replace_backslash, name: "regex-easyesc"L, groups: "3.1"L, description: "string replace -r needs fewer \\'s"L, @@ -125,7 +125,7 @@ fn from(md: &FeatureMetadata) -> feature_metadata_t { read_only: false, }, FeatureMetadata { - flag: feature_flag_t::ampersand_nobg_in_token, + flag: FeatureFlag::ampersand_nobg_in_token, name: "ampersand-nobg-in-token"L, groups: "3.4"L, description: "& only backgrounds if followed by a separator"L, @@ -135,29 +135,29 @@ fn from(md: &FeatureMetadata) -> feature_metadata_t { ]; /// The singleton shared feature set. -static mut global_features: *const UnsafeCell = std::ptr::null(); +static mut global_features: *const UnsafeCell = std::ptr::null(); pub fn future_feature_flags_init() { unsafe { // Leak it for now. - global_features = Box::into_raw(Box::new(UnsafeCell::new(features_t::new()))); + global_features = Box::into_raw(Box::new(UnsafeCell::new(Features::new()))); } } -impl features_t { +impl Features { fn new() -> Self { - features_t { + Features { values: array::from_fn(|i| AtomicBool::new(metadata[i].default_value)), } } /// Return whether a flag is set. - pub fn test(&self, flag: feature_flag_t) -> bool { + pub fn test(&self, flag: FeatureFlag) -> bool { self.values[flag.repr as usize].load(Ordering::SeqCst) } /// Set a flag. - pub fn set(&mut self, flag: feature_flag_t, value: bool) { + pub fn set(&mut self, flag: FeatureFlag, value: bool) { self.values[flag.repr as usize].store(value, Ordering::SeqCst) } @@ -209,18 +209,18 @@ pub fn set_from_string<'a>(&mut self, str: impl Into<&'a wstr>) { } /// Return the global set of features for fish. This is const to prevent accidental mutation. -pub fn fish_features() -> *const features_t { +pub fn fish_features() -> *const Features { unsafe { (*global_features).get() } } /// Perform a feature test on the global set of features. -pub fn feature_test(flag: feature_flag_t) -> bool { +pub fn feature_test(flag: FeatureFlag) -> bool { unsafe { &*(*global_features).get() }.test(flag) } /// Return the global set of features for fish, but mutable. In general fish features should be set /// at startup only. -pub fn mutable_fish_features() -> *mut features_t { +pub fn mutable_fish_features() -> *mut Features { unsafe { (*global_features).get() } } @@ -232,11 +232,11 @@ pub fn mutable_fish_features() -> *mut features_t { #[test] #[widestrs] fn test_feature_flags() { - let mut f = features_t::new(); + let mut f = Features::new(); f.set_from_string("stderr-nocaret,nonsense"L); - assert!(f.test(feature_flag_t::stderr_nocaret)); + assert!(f.test(FeatureFlag::stderr_nocaret)); f.set_from_string("stderr-nocaret,no-stderr-nocaret,nonsense"L); - assert!(f.test(feature_flag_t::stderr_nocaret)); + assert!(f.test(FeatureFlag::stderr_nocaret)); // Ensure every metadata is represented once. let mut counts: [usize; metadata.len()] = [0; metadata.len()]; @@ -248,7 +248,7 @@ fn test_feature_flags() { } assert_eq!( - metadata[feature_flag_t::stderr_nocaret.repr as usize].name, + metadata[FeatureFlag::stderr_nocaret.repr as usize].name, "stderr-nocaret"L ); } diff --git a/src/builtins/status.cpp b/src/builtins/status.cpp index e1eb72ca6..23e1fa3aa 100644 --- a/src/builtins/status.cpp +++ b/src/builtins/status.cpp @@ -23,7 +23,7 @@ #include "../proc.h" #include "../wgetopt.h" #include "../wutil.h" // IWYU pragma: keep -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" enum status_cmd_t { STATUS_CURRENT_CMD = 1, diff --git a/src/builtins/string.cpp b/src/builtins/string.cpp index e938bc48d..424dd2afe 100644 --- a/src/builtins/string.cpp +++ b/src/builtins/string.cpp @@ -29,7 +29,7 @@ #include "../wgetopt.h" #include "../wildcard.h" #include "../wutil.h" // IWYU pragma: keep -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" // Empirically determined. // This is probably down to some pipe buffer or some such, diff --git a/src/common.cpp b/src/common.cpp index f8af1c14c..25c9e4940 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -36,7 +36,7 @@ #include "expand.h" #include "fallback.h" // IWYU pragma: keep #include "flog.h" -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "global_safety.h" #include "iothread.h" #include "signals.h" diff --git a/src/fish.cpp b/src/fish.cpp index 4384e068d..12375b0b8 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -49,7 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "fish_version.h" #include "flog.h" #include "function.h" -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "global_safety.h" #include "history.h" #include "io.h" diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index c30c3bdd1..a39f1aae6 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -43,7 +43,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "ffi_init.rs.h" #include "fish_version.h" #include "flog.h" -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "global_safety.h" #include "highlight.h" #include "maybe.h" diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 21eda2426..c2772817e 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -65,7 +65,7 @@ #include "ffi_init.rs.h" #include "ffi_tests.rs.h" #include "function.h" -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "global_safety.h" #include "highlight.h" #include "history.h" diff --git a/src/future_feature_flags.h b/src/future_feature_flags.h new file mode 100644 index 000000000..29f91f0c2 --- /dev/null +++ b/src/future_feature_flags.h @@ -0,0 +1,8 @@ +#ifndef FISH_FUTURE_FEATURE_FLAGS_H +#define FISH_FUTURE_FEATURE_FLAGS_H + +#include "future_feature_flags.rs.h" +using feature_flag_t = FeatureFlag; +using features_t = Features; + +#endif diff --git a/src/highlight.cpp b/src/highlight.cpp index b4b47e0eb..292570c16 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -25,7 +25,7 @@ #include "expand.h" #include "fallback.h" // IWYU pragma: keep #include "function.h" -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "history.h" #include "maybe.h" #include "operation_context.h" diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 5080df7c8..4faef9ebb 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -20,7 +20,7 @@ #include "common.h" #include "expand.h" #include "fallback.h" // IWYU pragma: keep -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "operation_context.h" #include "parse_constants.h" #include "parse_tree.h" diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index fa0742df3..942ceacc0 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -15,7 +15,7 @@ #include "common.h" #include "fallback.h" // IWYU pragma: keep -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "wutil.h" // IWYU pragma: keep // _(s) is already wgettext(s).c_str(), so let's not convert back to wcstring diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 021ebb450..40612f3b2 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -23,7 +23,7 @@ #include "enum_set.h" #include "expand.h" #include "fallback.h" // IWYU pragma: keep -#include "future_feature_flags.rs.h" +#include "future_feature_flags.h" #include "maybe.h" #include "path.h" #include "wcstringutil.h"