Commit Graph

358 Commits

Author SHA1 Message Date
ridiculousfish
b16f617fb3 Migrate string and lock tests into their own files
Get some stuff out of the common module, which is growing large.

Also migrate the tests into "native" Rust tests so they will run in parallel.
We have to use an explicit setlocale() call to get a multibyte locale, for the
"crazy" tests.
2023-07-04 13:27:53 -07:00
ridiculousfish
eaf8e73c42 Make escape/unescape string_var hew more closely to the C++ 2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
970ed610df Avoid string copying to speed up asan 2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
595d593732 Fully migrate to Rust escape string tests and code
Co-Authored-By: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
0a4bcf7430 Port (un)escape-tests, fix a couple bugs 2023-07-04 13:27:53 -07:00
ridiculousfish
ec28a30bd6 Fix a clippy lint warning 2023-07-04 13:26:19 -07:00
ridiculousfish
35f8f421fe topic_monitor to migrate from wperror to perror
This avoids needing to use the ffi
2023-07-04 13:26:19 -07:00
ridiculousfish
15361f62ed signal.rs to stop using wperror
This needed to cross the ffi which is annoying in tests. Use the Rust perror()
instead.
2023-07-04 13:26:19 -07:00
ridiculousfish
1076642770 Remove future_feature_flags_init
Make Features just a global. After the Rust port we can make it use atomics and
no longer be mut.

This allows feature flags to be used in Rust tests.
2023-07-04 13:26:19 -07:00
ridiculousfish
37fed01642 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.
2023-07-04 13:26:19 -07:00
ridiculousfish
2ec482e94a Move the Option out of ParsedSourceRef, and use Arc instead of Rc
Two small fixes:

1. ParsedSourceRef, if present, should not be None; express that in the type.
2. ParsedSourceRef is intended to be shareable across threads; make it so.
2023-07-02 17:46:04 -07:00
Fabian Boehm
a996c8c7dd Fix clippy
As always: Some petty complaints of no actual use
2023-07-02 10:10:29 +02:00
ridiculousfish
12dfbc14d7 Make builtin status long options const
By using an explicit match instead of unwrap(), we can avoid the use of Lazy.
2023-07-01 16:05:10 -07:00
ridiculousfish
1c5c1993dd Make wdirname and wbasename go &wstr -> &wstr
There is no reason for either of these functions to allocate, so have
them not do it.
2023-07-01 15:41:46 -07:00
ridiculousfish
d26d4f36b0 Minor fixes to builtin status
Use as_wstr() instead of from_ffi() in a few places to avoid an allocation,
and make job_control_t work in &wstr instead of &str to reduce complexity at
the call sites.
2023-07-01 15:33:11 -07:00
Henrik Hørlück Berg
4061c7250c Replace status_cmd with an option
- Using an option makes it much clearer that the check for empty args is
  redundant.
- Also prefer implementing TryFrom only for &str, to not hide the string
  conversion and allocation happening.
2023-07-01 15:33:01 -07:00
Henrik Hørlück Berg
7b3637cd1f Port builtins/status to fish
- Also port tests of wdirname and wbasename, as they were bugged
2023-07-01 15:33:01 -07:00
ridiculousfish
37337683cb Revert "Fix Rust wdirname and wbasename and port the C++ tests"
This reverts commit 6b1c2e169c.

We're about to rework these in the builtin status changes.
2023-07-01 13:38:38 -07:00
ridiculousfish
6b1c2e169c Fix Rust wdirname and wbasename and port the C++ tests
These functions were rather buggy; add tests and fix the test failures.
2023-07-01 12:45:11 -07:00
David Adam
ce9f95128a type/command: implement optimisation for --all
This was present in the C++ version for command, though never for type.

Checking over all elements of PATH can be slow on some platforms eg
WSL2, so only do that when used with `--all`.

Based on discussion in
https://github.com/fish-shell/fish-shell/pull/9856
2023-06-30 10:05:01 +08:00
David Adam
14cfd268d8 path: drop path_get_paths_ffi
f77dc24 provides the pieces to call path_get_paths directly from Rust
code. Drop the C++ implementation and its FFI.
2023-06-30 10:05:01 +08:00
Henrik Hørlück Berg
1f67bcbb39 Update dependencies for asan to work
Rust nightly changed the name of a preview feature, which broke proc-macro2,
see https://github.com/rust-lang/rust/issues/113152
2023-06-29 20:02:43 -05:00
Fabian Boehm
c7b43b3abf Truncate builtin arguments on NUL
This restores the status quo where builtins are like external commands
in that they can't see anything after a 0x00, because that's the c-style
string terminator.
2023-06-24 21:26:44 +02:00
David Adam
78940a6026 print_help: make function public 2023-06-24 18:21:21 +08:00
Fabian Boehm
11c8d9684e
Make NULs work for builtins (#9859)
* Make NULs work for builtins

This switches from passing a c-string to output_stream_t::append to
passing a proper string.

That means a builtin that prints a NUL no longer crashes with "thread '' panicked
at 'String contained intermediate NUL character: ".

Instead, it will actually handle the NUL, even as an argument.

That means something like

`echo foo\x00bar` will now actually print a NUL instead of truncating
after the `foo` because we passed c-strings around everywhere.

The former is *necessary* for e.g. `string`, the latter is a change
that on the whole makes dealing with NULs easier, but it is a
behavioral change.

To restore the c-string behavior we would have to truncate arguments
at NUL.

See #9739.

* Use AsRef instead of trait bound
2023-06-22 20:50:22 +02:00
ridiculousfish
f77dc2451e Expose Rust EnvStack from parser_t
Prior to this change, parser_t exposed an environment_t, and Rust had to go
through that. But because we have implemented Environment in Rust, it is
better to just expose the native Environment from parser_t. Make that
change and update call sites.
2023-06-19 13:45:54 -07:00
ridiculousfish
6936c944c1 Add some fixes atop argparse
This switches to using the WExt functions, which deal directly in chars
and char indices.
2023-06-19 13:45:54 -07:00
Henrik Hørlück Berg
292f7b2be1 Port builtins/argparse to Rust 2023-06-19 13:45:54 -07:00
David Adam
6229f08200 rust/print_help: simplify use of OsStrings
See discussion in https://github.com/fish-shell/fish-shell/pull/9818#discussion_r1210829722
2023-06-19 21:57:53 +08:00
ridiculousfish
99c2e476ac Bravely remove writembs macro
The writembs macro was ported from C++, which attempted to detect when a NULL
termcap was used. However we have never gotten a bug report from this. Bravely
remove it.
2023-06-17 16:04:34 -07:00
ridiculousfish
21f08ee9fd Simplify some curses stuff and enforce that caps are nonempty
The outputter code has a lot of checks that string capabilities are non-empty;
just enforce that at the curses layer so we can remove those checks.

Also remove some types and traits, replacing them with simple functions.
2023-06-17 13:52:53 -07:00
ridiculousfish
dec5a64232 Outputter to implement Write
By implementing Write directly, we can remove some local buffers and uses of
Cursor. This both simplifies and optimizes the code.
2023-06-17 12:14:42 -07:00
ridiculousfish
64a40d2410 write_color_escape to stop returning bool
This bool return was always true, so we don't need it.
2023-06-17 12:14:42 -07:00
ridiculousfish
51a971bf16 Remove tparm0
Per code review, we think that tparm does nothing when there are no parameters,
and it is safe to remove it, even though this is a break from C++. This
simplifies some code.
2023-06-17 12:14:42 -07:00
ridiculousfish
a09947cd99 Implement builtin set_color in Rust
This rewrites the set_color builtin in Rust, restoring italics support in
iTerm2.
2023-06-17 12:14:42 -07:00
ridiculousfish
84b24d5615 Adopt the new output.rs
This switches output.cpp from C++ to Rust.
2023-06-17 12:14:42 -07:00
ridiculousfish
8f38e175ce Add from_ffi() to rgb_color_t
This allows converting a C++ rgb_color_t to a Rust RgbColor.
2023-06-17 12:14:42 -07:00
ridiculousfish
8604be9a4f Port (but do not yet adopt) output.cpp to Rust 2023-06-17 12:14:42 -07:00
ridiculousfish
76205e5b55 Port debug_thread_error() to Rust 2023-06-17 12:14:42 -07:00
Clemens Wasser
c2f58cd312 Port killring 2023-06-04 12:18:19 -07:00
ridiculousfish
cfdcaf880f Simplify scoped_push and ScopedGuard
This makes some simplifications to scoped_push and ScopeGuard:

1. ScopeGuard no longer uses ManuallyDrop; the memory management is now
   trivial and no longer requires `unsafe`.

2. The functions `cancel` and `rollback` have been removed, as
   these were unused. They can be added back later if needed.

3. `scoped_push` has been simplified in both signature and implementation.

4. `Projection` is no longer required and has been removed.

Also add some tests.
2023-06-04 12:14:53 -07:00
ridiculousfish
777ba6f9d8 Use consistent formatting in the parse_rgb test 2023-06-03 12:15:45 -07:00
ridiculousfish
1bbd60c597 Fix a bug in the color.rs port
This was incorrectly parsing FFF as 0x0F0F0F instead of 0xFFFFFF.
2023-06-03 12:13:57 -07:00
David Adam
688a28c1d2 Rewrite and adopt print_help in Rust 2023-06-01 23:17:13 +08:00
ridiculousfish
3d447dec3a Fix a multiplicative overflow in color.rs
Also add a test.
2023-05-29 13:22:46 -07:00
Mahmoud Al-Qudsi
5ecd584063 Merge VarDispatchTable tables
There was only one entry in the named table, so the previous layout was quite
wasteful. This should speed up lookups and reduce memory overhead.
2023-05-26 22:59:55 -05:00
Mahmoud Al-Qudsi
6638c78b30 Port env_dispatch to Rust and integrate with C++ code 2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
cce78eeb43 Update env_var_to_ffi() to take an Option<EnvVar>
It wasn't possible to handle cases where vars.get() returned `None` then forward
that to C++, but now we can.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
6bb2725f67 Make sure rust's fish_setlocale() inits global C++ variables
We can't just call the Rust version of `fish_setlocale()` without also either
calling the C++ version of `fish_setlocale()` or removing all `src/complete.cpp`
variables that are initialized and aliasing them to their new rust counterparts.

Since we're not interested in keeping the C++ code around, just call the C++
version of the function via ffi until we don't have *any* C++ code referencing
`src/common.h` at all.

Note that *not* doing this and then calling the rust version of
`fish_setlocale()` instead of the C++ version will cause errant behavior and
random segfaults as the C++ code will try to read and use uninitialized values
(including uninitialized pointers) that have only had their rust counterparts
init.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
c71342b933 Add safe Rust wrapper around system curses library
This is not yet used but will take eventually take the place of all (n)curses
access. The curses C library does a lot of header file magic with macro voodoo
to make it easier to perform certain tasks (such as access or override string
capabilities) but this functionality isn't actually directly exposed by the
library's ABI.

The rust wrapper eschews all of that for a more straight-forward implementation,
directly wrapping only the basic curses library calls that are required to
perform the tasks we care about. This should let us avoid the subtle
cross-platform differences between the various curses implementations that
plagued the previous C++ implementation.

All functionality in this module that requires an initialized curses TERMINAL
pointer (`cur_term`, traditionally) has been subsumed by the `Term` instance,
which once initialized with `curses::setup()` can be obtained at any time with
`curses::Term()` (which returns an Option that evaluates to `None` if `cur_term`
hasn't yet been initialized).
2023-05-25 16:54:07 -05:00