Commit Graph

2601 Commits

Author SHA1 Message Date
ridiculousfish
e3b8203187 Implement logger_t::log_fmt for narrow chars by trampolining to wide chars
This satifies the glibc.
2019-12-08 14:47:52 -08:00
ridiculousfish
92a16921bf Add a test to verify that processes get the right pgrps in pipelines 2019-12-08 13:45:24 -08:00
ridiculousfish
d47541a3d7 Add a tricky test to verify disowning an in-flight job
There's some logic in fish to prevent blowing up when an under-construction
job is disowned. Add a test for it.
2019-12-08 11:44:21 -08:00
ridiculousfish
2ec8cd3bca Remove a dead variable 2019-12-07 11:28:22 -08:00
ridiculousfish
f575c55f5b Migrate the logic to make empty functions succeed into the performer
This is a more natural place for this logic.
2019-12-07 11:06:54 -08:00
ridiculousfish
a7f6fd22d4 Factor block and fish function execution into a "performer" std::function
In preparation for concurrent execution, invert the control of function and
block execution. Allow a process to return an std::function that performs the
the execution. This can be run on either the main or a background thread
(eventually).
2019-12-07 10:29:06 -08:00
Michael Jarvis
1be8277f41 Minor tweak to silence warning
Silences a clang++ warning:

"using the result of an assignment as a condition without parentheses"
2019-12-03 19:34:37 -08:00
Fabian Homborg
86133b0a2b Add read --tokenize
This splits a string into variables according to the shell's
tokenization rules, considering quoting, escaping etc.

This runs an automatic `unescape` on the string so it's presented like
it would be passed to the command. E.g.

    printf '%s\n' a\ b

returns the tokens

printf
%s\n
a b

It might be useful to add another mode "--tokenize-raw" that doesn't
do that, but this seems to be the more useful of the two.

Fixes #3823.
2019-12-01 18:14:26 +01:00
ridiculousfish
fb8e90de28 clang-format .cpp files 2019-11-29 23:57:19 -08:00
Rosen Penev
e4a7e7d4f7 [clang-tidy] Use strcmp family properly
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
e45ae9df49 [clang-tidy] Enclose macro arguments in ()
Found with bugprone-macro-parentheses

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
9507c3a159 [clang-tidy] Don't initialize member functions
Found with readability-redundant-member-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
6f4a9d527c [clang-tidy] Use C++ using instead of C typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
7d1cc992e5 [clang-tidy] Simplify boolean expressions
Found with readability-simplify-boolean-expr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
4087b2ee15 [clang-tidy] Use bool literals
Found with modernize-use-bool-literals

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:50 -08:00
Rosen Penev
c3fa8c04bf [clang-tidy] Don't empty initialize strings
Found with readability-redundant-string-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:50 -08:00
ridiculousfish
b5d0075406 Use iothread pool for background fillthreads
Background fillthreads are used when we want to populate a buffer from an
external command. The most common is command substitution.

Prior to this commit, fish would spin up a fillthread whenever required.
This ended up being quite expensive.

Switch to using the iothread pool instead. This enables reusing the same
thread(s), which prevents needing to spawn new threads. This shows a big
perf win on the alias benchmark (766 -> 378 ms).
2019-11-27 12:03:56 -08:00
ridiculousfish
106af5f56a Migrate some iothread functions into member functions of thread_pool_t
This reintroduces commits 22230a1a0d
and 9d7d70c204, now with the bug fixed.

The problem was when there was one thread waiting in the pool. We enqueue
an item onto the pool and attempt to wake up the thread. But before the
thread runs, we enqueue another item - this second enqueue will see the
thread waiting and attempt to wake it up as well. If the two work items
were dependent (reader/writer) then we would have a deadlock.

The fix is to check if the number of waiting threads is at least as large
as the queue. If the number of enqueued items exceeds the number of waiting
threads, then spawn a new thread always.
2019-11-27 12:03:56 -08:00
Fabian Homborg
83f153eb4c Revert "builtin_printf: Use proper functions"
This reverts commit 1102b83b2d.

wcstold_l is not available on musl and we don't currently have our "own" implementation.

Revert for now until we do.
2019-11-27 18:50:28 +01:00
Fabian Homborg
662fb3f3d1 Fix line numbers in functions
This added the function offset *again*, but it's already included in
the line for the current file.

And yes, I have explicitly tested a function file with a function
defined at a later line.

Fixes #6350
2019-11-26 18:12:24 +01:00
Johannes Altmanninger
f36705bb66 Fix error messages for "and" and "or" after pipe
Fixes #6347
2019-11-26 14:03:53 +01:00
Johannes Altmanninger
97969a9363 Restore error messages for bare variable assignment
Since #6287, bare variable assignments do not parse, which broke
the "Unsupported use of '='" error message.

This commit catches parse errors that occur on bare variable assignments.
When a statement node fails to parse, then we check if there is at least one
prefixing variable assignment. If so, we emit the old error message.

See also #6347
2019-11-26 13:59:17 +01:00
ridiculousfish
267b8da935 Remove dead function reconstruct_orig_str
This function is no longer called.
2019-11-25 15:52:30 -08:00
Rosen Penev
1102b83b2d builtin_printf: Use proper functions
Removes unnecessary type conversions.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
69d0bb7c0d io.h: Add missing override
Found with clang's -Winconsistent-missing-destructor-override

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
586ac3dfa7 [clang-tidy] Convert loops to range based
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
8d54e928cd [clang-tidy] C to C++ headers
Found with modernize-deprecated-headers

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
0dfa7421f3 [clang-tidy] Convert C casts to C++ ones
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
7f62e30731 [clang-tidy] Replace size comparisons with empty
Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
Rosen Penev
5ca80a61e3 [clang-tidy] Fix inconsistent declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
Jason
3cf6ebc0e1 Amend typos and grammar errors 2019-11-25 13:07:15 +01:00
Johannes Altmanninger
7d5b44e828 Support FOO=bar syntax for passing variables to individual commands
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:

a=1 b=$a echo $b        # outputs 1

Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping).  Array indexing
(PATH[1]=/bin ls $PATH) is *not* yet supported, but can be added fairly
easily.

The right hand side may be any valid string token, like a command
substitution, or a brace expansion.

Since `a=* foo` is equivalent to `begin set -lx a *; foo; end`,
the assignment, like `set`, uses nullglob behavior, e.g. below command
can safely be used to check if a directory is empty.

x=/nothing/{,.}* test (count $x) -eq 0

Generic file completion is done after the equal sign, so for example
pressing tab after something like `HOME=/` completes files in the
root directory
Subcommand completion works, so something like
`GIT_DIR=repo.git and command git ` correctly calls git completions
(but the git completion does not use the variable as of now).

The variable assignment is highlighted like an argument.

Closes #6048
2019-11-25 09:20:51 +01:00
Rosen Penev
3b0f642de9 builtin-math: Use normal C trunc
uClibc-ng does not expose C++11 math
functions to the std namespace, breaking
compilation. This is fine as the argument
type is double.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-24 22:02:33 +01:00
ridiculousfish
80a4898e75 Revert "Migrate some iothread functions into member functions of thread_pool_t"
This reverts commit 22230a1a0d.
Also 9d7d70c204

There's some subtle bug here, needs to be tracked down and tested.
2019-11-23 23:35:34 -08:00
ridiculousfish
9023c2187f Make shutdown_fillthread_ a relaxed_atomic_bool_t
Reduces the noisiness of working with it.
2019-11-23 14:12:34 -08:00
ridiculousfish
22230a1a0d Migrate some iothread functions into member functions of thread_pool_t 2019-11-23 14:05:26 -08:00
ridiculousfish
9d7d70c204 Clean up some iothreads
Improve the iothread behavior by enabling an iothread to stick around for
a while waiting for work. This reduces the amount of iothread churn, which
is useful on platforms where threads are expensive.

Also do other modernization like clean up the locking discipline and use
FLOG.
2019-11-23 13:44:27 -08:00
ridiculousfish
a74fc7ef6d Remove the wait_for_threads_to_die parameter to execute_fork
This is always set to false so we can get rid of it.
2019-11-23 12:36:44 -08:00
ridiculousfish
3fb9159b09 Rename spawn_request_t to work_request_t and clean up the API a bit 2019-11-23 12:13:30 -08:00
ridiculousfish
03a289c9ef Add an aliases benchmark 2019-11-23 11:53:49 -08:00
Ray Hogenson
98a98b1424 Change vi selection mode to be inclusive
The current cursor position should be included in the selection to be
consistent with the behavior of vi.

Fixes #5770
2019-11-19 20:25:10 +01:00
ridiculousfish
64ce1088fd Make function_prepare_environment take argv instead of the process
This will help concurrent execution.
2019-11-14 17:58:39 -08:00
ridiculousfish
e18fd3cddb Allow unclosed subshells in interactive mode
If the user has an unclosed subshell in interactive mode, break the
line instead of producing an error.

Fixes #6316
2019-11-13 18:01:47 -08:00
Ankush Patil
ee982c4f6c Fixes #6280 : Added right associativity to 'pow' function 2019-11-13 13:51:01 -08:00
ideal
8aaccf1587 Reduce times of move and copy operation 2019-11-12 14:58:22 -08:00
ridiculousfish
ec08a50769 Eliminate function_data_t
This struct is now mostly useless and can go.
2019-11-12 11:25:41 -08:00
ridiculousfish
6d7a66592b Make function_add take the filename directly instead of a parser 2019-11-12 10:00:42 -08:00
ridiculousfish
b51edcfcac Simplify function_info_t and function_data_t
Work towards cleaning up function definition. Migrate inherit_vars into
props and capture their values at the point of definition.
2019-11-12 09:53:10 -08:00
ridiculousfish
b0cf94e3ba Refactor function_prepare_environment
Migrate it into exec.cpp to reduce the complexity of
exec_block_or_func_process.
2019-11-10 14:46:21 -08:00