Commit Graph

496 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
0233c0c437 fix is_windows_subsystem_for_linux(), check for post-fork-safety
This function only ever returns true if target_os=linux, so we need to invert
the OS check.

In the first invocation, this function may allocate heap memory.
Clarify that this is safe.

[ja: I don't have the original commit handy so I made up the log message]
2023-10-08 20:48:24 +02:00
Johannes Altmanninger
0a48f4b55c common: remove deprecated methods 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
b583c51238 Sort clippy lints 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d15e475440 event: reduce lock scope to allow re-locking in event handler
The following "Port execution" commit will use RefCell for the wait handle
store.  If we hold a borrow while we are running an event (which may run
script code) there will be a borrowing conflict. Avoid this by returning
the borrow earlier.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
575c271461 job_group: reuse RelaxedAtomicBool 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d764625069 getcwd: fix bad error message 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
ad75c72621 flog: reuse write_to_fd 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
637926a7fd env: fix porting regression recording inherited vars 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d8de497ebc Use shorter escape() function 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
0b25793097 wildcard: use "zelf" over "this" for consistency
The following "Port execution" commit will add lots of variables called "zelf".
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
e8712af0c3 builtin random: make option parsing consistent with other builtins again
As suggested in a comment on2fb352a9e (Address some clippy lints from nightly
clippy, 2023-10-03).
2023-10-08 20:46:53 +02:00
Fabian Boehm
86803e4442
Reduce stat calls for wildcards ending in "/" (#10032)
This makes it so expand_intermediate_segment knows about the case
where it's last, only followed by a "/".

When it is, it can do without the file_id for finding links (we don't
resolve the files we get here), which allows us to remove a stat()
call.

This speeds up the case of `...*/` by quite a bit.

If that last component was a directory with 1000 subdirectories we
could skip 1000 stat calls!

One slight weirdness: We refuse to add links to directories that we already visited, even if they are the last component and we don't actually follow them. That means we can't do the fast path here either, but we do know if something is a link (if we get d_type), so it still works in common cases.
2023-10-08 16:46:59 +02:00
ridiculousfish
f7e7396c69 Fix a deadlock affecting fish_config
This fixes the following deadlock. The C++ functions path_get_config and
path_get_data lazily determine paths and then cache those in a C++ static
variable. The path determination requires inspecting the environment stack.
If these functions are first called while the environment stack is locked
(in this case, when fetching the $history variable) we can get a deadlock.

The fix is to call them eagerly during env_init. This can be removed once
the corresponding C++ functions are removed.

This issue caused fish_config to fail to report colors and themes.

Add a test.
2023-10-07 15:20:14 -07:00
ridiculousfish
b315b66cb0 Minor comment cleanup of main.rs 2023-10-07 14:39:24 -07:00
Johannes Altmanninger
79bbf5247a builtin set_color: use naming convention 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
28a38946a5 common: port err!() test helper
Unlike our C++ tests, our Rust tests fail as soon as an assertion fails.
Whether this is desired is debatable; it seems fine for
most cases and is easier to implement.

This means that Rust tests usually don't need to print anything besides
what assert!/assert_eq! already provide.
One exception is the history merge test. Let's add a simple err!() macro to
support this. Unlike the C++ err() it does not yet print colors.

Currently all of our macros live in common.rs, to keep the import graph simple.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
618834c4b5 Port UVAR_FILE_SET_MTIME_HACK
Notably this exposes config.h to Rust (for UVAR_FILE_SET_MTIME_HACK).
In future we should move the CMake checks into build.rs so we can potentially
get rid of CMake.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
3020c90856 Upgrade bitflags
This allows us to use some newer functionality (I forgot which one I ended
up using).
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
1bfdc33f76 Make stream.append call sites consistent
Maybe the wrong direction.. but this seems to be the majority.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2fb352a9e4 Address some clippy lints from nightly clippy
Note that in general we should not respect nightly clippy because it might
contradict stable clippy which is run in CI.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
10fed02572 Work around ASan complaining about buffer overflow in DirIter
On the following "Port execution" commit, ASan will complain if we read
beyond a terminating null byte in get_autosuggestion_performer().  This is
actually working as intended but we need to appease ASan somehow..
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
379ad03d9d parse_util: return Result in parse_util_detect_errors_in_argument
This makes it consistent with some other public parse_util_* functions.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2334424234 parse_util: fix regressions from port
Tested by the upcoming highlighting unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
c7c0bb9bb2 env: fix boolean sense in get_pwd_slash()
get_pwd_slash() uses "if var.is_empty()" but it should be "if !var.is_empty()".
This wasn't a problem so far because in practice most code paths use the
get_pwd_slash() override from EnvStackImpl. The generic one is used in the
upcoming unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
ffbb56c4a9 common: port test_format 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
408161f4d6 Port test_tokenizer 2023-10-07 19:30:46 +02:00
Fabian Boehm
6775b0b1ad Implement PartialEq manually to shut up clippy 2023-10-06 17:10:59 +02:00
Fabian Boehm
1073f59929 Shut up Clippy 1.72 2023-10-06 16:54:16 +02:00
Fabian Boehm
3ce67ecbd2 printf: Fix octal escapes with leading zeroes
Octal escapes can be written as `\057` or as `\0057`.

Simply ported wrong initially.
2023-10-05 15:39:50 +02:00
Hauke Strasdat
4ab34f2e86 fix: don't make assumptions about signedness of libc::c_char 2023-10-01 13:27:10 -07:00
Gregory Anders
b32cc65166 Do not use is_some_and
This was stabilized in Rust 1.70.0, but CI uses 1.67.0 where this function was
still marked unstable.
2023-09-30 10:09:52 +02:00
Gregory Anders
33c6eee9d2 Check terminfo for ts capability to determine title setting support 2023-09-30 10:09:52 +02:00
ridiculousfish
555171cb55 Adopt Rust postfork code
This adopts the Rust postfork code, bridging it from C++ exec module.

We use direct function calls for the bridge, rather than cxx/autocxx, so that we
can be sure that no memory allocations or other shenanigans are happening.
2023-09-24 13:04:00 -07:00
ridiculousfish
c862a06874 Implement postfork code in Rust
This implements the "postfork" code in Rust, including calling fork(),
exec(), and all the bits that have to happen in between. postfork lives
in the fork_exec module.

It is not yet adopted.
2023-09-24 13:04:00 -07:00
ridiculousfish
c5d770c78a Introduce flog_safe module in fork_exec module
This introduces a new module called fork_exec, which will be for posix_spawn,
postfork, and flog_safe - stuff concerned with actually executing binaries,
and error reporting.

Add a FLOG_SAFE! macro which writes errors to the flog fd in an
async-signal-safe way. This implementation differs from the C++ in that we
allow printing integers directly - no requiring them to be converted to a
buffer first.
2023-09-24 13:04:00 -07:00
ridiculousfish
6a6cde50d5 Stop using widestrs macro in flog
Use L! directly. Fewer proc-macros is good.
2023-09-24 13:04:00 -07:00
Fabian Boehm
4d2f7b0c0d
ast: Require --help to parse more keywords as decorated statement (#10000)
This makes it so

```fish
if -e foo
    # do something
end
```

complains about `-e` not being a command instead of `end` being used
outside of an if-block.

That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!

The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).

The same goes for switch, while and begin.

It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
2023-09-19 17:34:13 +02:00
Henrik Hørlück Berg
731f06bdb9 fixup! Forward-port #9931 2023-09-15 15:10:14 +02:00
Henrik Hørlück Berg
0cc1aef725
Forward-port #9931 2023-09-15 14:58:54 +02:00
Henrik Hørlück Berg
6ee81c0f15
Crash if invariant is broken 2023-09-15 14:46:53 +02:00
Henrik Hørlück Berg
5407d0b785
Apply code review fixes 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d6a9ad66a7
Allow CancelChecker to be FnMut 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d277a50564
Combine previous attempt into this
*singing it's the best of both worlds*
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
e0bbf3eee9
Port wilcard.{cpp,h} to Rust
- This is untested and unused, string ownership is very much subject to change
- Ports the minimally necessary parts of complete.rs as well
- This should fix an infinite loop in `create_directory` in `path.rs`, the first
  `wstat` loop only breaks if it fails with an error that's different from
  EAGAIN
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
80d92dcc6d
Port the easy part of wildcard.{h,cpp}
- wildcard_match is now closer to the original that is linked in a comment, as
  pointer-arithmetic translates very poorly. The act of calling wildcard
  patterns wc or wildcard is kinda confusing when wc elsewhere is widechar.
2023-09-15 14:38:30 +02:00
Johannes Altmanninger
e1f5751ba0 fixup! builtin status: use program name constant again 2023-09-14 20:46:42 +02:00
Johannes Altmanninger
61d506afd0 builtin status: use program name constant again 2023-09-14 20:42:25 +02:00
Fabian Boehm
fa390334a8 Remove wcs/wcwidth ffi calls
This was ported a while back, we can just call the rust version
2023-09-05 21:57:38 +02:00
Henrik Hørlück Berg
676c3c9bc2 Re-use DEFAULT_PATH in setup_path
- No need to hard-code a different default
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
008764a2cd Make DEFAULT_PATH allow overriding system binaries
This is in regards to a comment on 290d07a833, which resulted in 46c967903d.
Those commits handled the default path when it is unset on startup.
DEFAULT_PATH is used when PATH is unset at runtime as far as I can tell.

As far as I can tell this has had the non-overidding ordering behavior since inception
(or at least 17 years ago ea998b03f2).
2023-09-05 11:38:59 +02:00