Commit Graph

8172 Commits

Author SHA1 Message Date
Fabian Homborg
304d9da6a0 Document fish_exit event 2018-02-19 20:21:02 +01:00
Fabian Homborg
f7adaeb97b Use the new fish_exit event 2018-02-19 20:21:02 +01:00
Fabian Homborg
b67a614d86 Replace the process-exit event with generic "fish_exit" event
Turns out the process-exit is only ever used in conjunction with
`%self`. Make that explicit by just adding a new "fish_exit" event,
and deprecate the general process-exit machinery.

Fixes #4700.
2018-02-19 20:21:02 +01:00
ridiculousfish
9444c65ee8 Remove an unused variable from expand_cmdsubst 2018-02-18 20:31:35 -08:00
ridiculousfish
137c2559d9 Remove parser_error
It was unused.
2018-02-18 20:29:28 -08:00
ridiculousfish
5c44d897ea Mark overriding virtual functions as override instead of virtual 2018-02-18 19:12:45 -08:00
ridiculousfish
51c9ad1359 Mark trivial constructors/destructors as default 2018-02-18 19:12:45 -08:00
ridiculousfish
da84b38430 Constructors to accept more parameters by value
In cases where the constructor needs to take ownership of parameters,
pass them by value and use std::move.
2018-02-18 19:12:45 -08:00
ridiculousfish
74e6a82849 Remove explicit 'void' parameters. 2018-02-18 19:12:45 -08:00
Mahmoud Al-Qudsi
50541544f2 Distinguish between function and block IO for fork debug log messages 2018-02-18 16:49:27 -06:00
Mahmoud Al-Qudsi
fedce06687 Decrease error level for 'already has control of terminal' messages 2018-02-18 16:49:27 -06:00
ridiculousfish
fd2a0dffa9 Reflect newlines after pipes in fish grammar
The previous attempt to support newlines after pipes changed the lexer to
swallow newlines after encountering a pipe. This has two problems that are
difficult to fix:

1. comments cannot be placed after the pipe
2. fish_indent won't know about the newlines, so it will erase them

Address these problems by removing the lexer behavior, and replacing it
with a new parser symbol "optional_newlines" allowing the newlines to be
reflected directly in the fish grammar.
2018-02-18 14:44:08 -08:00
ridiculousfish
ea4e997dc9 Remove ends_with_pipe from reader
Now that parse_util_detect_errors() can report incomplete pipelines,
we no longer have to detect this in the reader.
2018-02-18 13:17:45 -08:00
ridiculousfish
ddd1afc57c Teach parse_util_detect_errors about unterminated pipelines
Allow it to return PARSER_TEST_INCOMPLETE for code like
`echo | `
2018-02-18 13:13:58 -08:00
slama
26ea8dc362 add tests for a pipe at the end of the line 2018-02-18 13:01:38 -08:00
slama
38418d6356 Enable multi-line edit when the line ends with a pipe (#1285) 2018-02-18 13:01:38 -08:00
ridiculousfish
cefb9e6d03 Factor our plain statement case of parse_util_detect_errors
Factors out a lot of code into a separate function.
2018-02-18 13:00:46 -08:00
ridiculousfish
81b3baaa9c Correct handling of unescapable entities in quotes
Prior to this fix, if you attempt to complete from inside a quote and the
completion contained an entity that cannot be represented inside quotes
(i.e. \n \r \t \b), the result would be a broken mess of quotes. Rewrite
the implementation so that it exits the quotes, emits the correct unquoted
escape, and then re-enters the quotes.
2018-02-17 15:18:46 -08:00
ridiculousfish
01d87455e1 Teach parse_util_escape_string_with_quote about tildes
Properly escape literal tildes in tab completion results. Currently we
always escape tildes in unquoted arguments; in the future we may escape
only leading tildes.

Fixes #2274
2018-02-17 15:18:43 -08:00
ridiculousfish
a261beef02 Minor cleanup of complete.cpp 2018-02-17 13:27:30 -08:00
ridiculousfish
0b2d8fd37e Switch some loops in handle_completions to C++11 range-based for looops 2018-02-17 13:10:05 -08:00
ridiculousfish
cdfdc994f1 Clean up completion_t constructors
Use some move semantics and default implementations.
2018-02-16 21:28:53 -08:00
ridiculousfish
9cd952588f Reset autoloads in response to variable changes
Prior to this fix, autoloads like function and completion autoloads
would check their path variable (like fish_function_path) on every
autoload request. Switch to invalidating it in response to the variable
changing.

This improves time on a microbenchmark:

    for i in (seq 50000)
      setenv test_env val$i
    end

from ~11 seconds to ~6.5 seconds.
2018-02-15 22:20:57 -08:00
Mahmoud Al-Qudsi
be13ac353b Refactor job control to make functions act like their names imply
The job control functions were a bit messy, in particular
`set_child_group`'s name would imply that all it does is set the child
group, but in reality it used to set the child group (via `setpgid`),
set the job's pgrp if it hasn't been set, and possibly assign control of
the terminal to the newly-created job.

These have been split into separate functions. Now `set_child_group`
does just (and only) that, `maybe_assign_terminal` might assign the
terminal to the new pgrp, and `on_process_created` is used to set the
job properties the first time an external process is created. This might
also speed things up (but probably not noticeably) as there are no more
repeated calls to `getpgrp()` if JOB_CONTROL is not set.

Additionally, this closes #4715 by no longer unconditionally calling
`setpgid` on all new processes, including those created by `posix_spawn`
which does not need this since the child's pgrep is set at in the
arguments to that API call.
2018-02-14 19:08:12 -06:00
ridiculousfish
8cf476fbf4 Merge branch 'functions_use_nodes'
This merges a set of changes that switch functions from executing source
to executing an already parsed tree (the same tree used when the function
is defined). This speeds up function execution, reduces memory usage, and
avoids annoying double parsing.

A simple microbenchmark of function execution:

    for i in (seq 10000)
      setenv test_env val$i
    end

time improves from 1.63 to 1.32 seconds.
2018-02-12 11:56:38 -08:00
ridiculousfish
5b5a3f78e1 Eliminate parse_execution_context_t::get_offset
This was used to find the index given a pointer to a node. It's now unused.
2018-02-12 10:56:08 -08:00
ridiculousfish
d536b152f7 Simplify the parser_t::eval() return type to void
The return value was unused.
2018-02-12 10:55:55 -08:00
ridiculousfish
4eb73862fc Switch parser_t::execution_contexts to only storing one
We only ever need the topmost (currently executing) context. We can
store the stack via the C stack rather than an explicit std::vector.
2018-02-12 10:55:42 -08:00
ridiculousfish
92d5c28730 Move eval_level into parser_t
This avoids the ping-ponging of eval_level through
parse_execution_context. Simply store the global eval level in the
parser_t.
2018-02-12 10:55:31 -08:00
ridiculousfish
8bddce2633 Remove fake_block_t
It was unused.
2018-02-12 10:55:28 -08:00
ridiculousfish
3e063e7c13 Remove node_offset from block_t
It was not used. Also clean up the constructor some.
2018-02-12 10:55:26 -08:00
ridiculousfish
8251d949f1 Switch executing_node_idx to storing a tnode_t
Avoids annoying index<->node conversions.
2018-02-12 10:55:20 -08:00
ridiculousfish
c3f1961e36 Stop copying out function definition when executing a function
This switches function execution from the function's source code to
its stored node and pstree. This means we no longer have to re-parse
the function every time we execute it.
2018-02-12 10:55:00 -08:00
ridiculousfish
976514597d Migrate function getters to use function_get_properties
This replaces some of the teensy function getters with the function
that just returns a shared_ptr to the properties struct.
2018-02-12 10:53:22 -08:00
ridiculousfish
db33ed0fc7 Migrate some function properties into a shared_ptr
The idea is that we can return the shared pointer directly, avoiding
lots of annoying little getter functions that each need to take locks.
It also helps to pull together the data structures used to initialize
functions versus store them.
2018-02-12 10:52:55 -08:00
ridiculousfish
41ba0dfadb Evaluate tnode_t instead of parse_node_t
This concerns block nodes with redirections, like
begin ... end | grep ...
Prior to this fix, we passed in a pointer to the node. Switch to passing
in the tnode and parsed source ref. This improves type safety and better
aligns with the function-node plans.
2018-02-12 10:51:39 -08:00
ridiculousfish
9cd24c042a Migrate function_info_t from header into .cpp file
This struct was not used outside of the .cpp file.
2018-02-12 10:51:31 -08:00
ridiculousfish
2fa705e4b2 Use a for-in loop in function.cpp 2018-02-12 10:51:08 -08:00
ridiculousfish
de23ce6ac1 Functions to store nodes
Prior to this fix, functions stored a string representation of their
contents. Switch them to storing a parsed source reference and the
tnode of the contents. This is part of an effort to avoid reparsing
a function's contents every time it executes.
2018-02-12 10:49:22 -08:00
ridiculousfish
ba7b8a9584 Remove various empty or useless functions
In particular remove init()/destroy() functions that do nothing, or
destroy functions that only free memory.
2018-02-10 17:21:55 -08:00
ridiculousfish
3a45cad12e Introduce fish_mutex_t wrapping std::mutex
Add a fish-specific wrapper around std::mutex that records whether it is
locked in a bool. This is to make ASSERT_IS_LOCKED() simpler (it can just
check the boolean instead of relying on try_lock) which will make Coverity
Scan happier.

Some details: Coverity Scan was complaining about an apparent double-unlock
because it's unaware of the semantics of try_lock(). Specifically fish
asserts that a lock is locked by asserting that try_lock fails; if it
succeeds fish prints an error and then unlocks the lock (so as not to leave
it locked). This unlock is of course correct, but it confused Coverity Scan.
2018-02-08 22:18:59 -08:00
Mahmoud Al-Qudsi
8069939112 fixup! Fix memory leak in term_env 2018-02-08 17:36:29 -06:00
Mahmoud Al-Qudsi
22a67885e1 Fix memory leak in term_env
Use wcstring/string instead of a character array. The variable
`term_env` was not being freed before the function exited.

Fixes defect 7520324 in coverity scan.
2018-02-08 17:17:26 -06:00
Mahmoud Al-Qudsi
6108b1d813 Assert value of tok_begin after call to parse_util_token_extent
We later assign the value of `tok_begin` to a `wcstring` which would
cause a null dereference if `tok_begin` were still null.
2018-02-08 17:10:51 -06:00
Mahmoud Al-Qudsi
fbc6c68f3d Handle error opening /dev/null in redirect_tty_output
This fixes coverity scan defect number 7520299
2018-02-08 17:05:13 -06:00
Mahmoud Al-Qudsi
3083e0ea80 Work around false positive RESOURCE_LEAK in coverity scan
Fixes defect number 7520322
2018-02-08 16:59:38 -06:00
Mahmoud Al-Qudsi
82b7e6de69 Fix unused code (coverity defect #7520283)
Due to the logic above, isz cannot be zero if we take the else branch.
2018-02-08 16:54:28 -06:00
ridiculousfish
56a46a0bab Merge 'Rearchitect WSL compatibility from SIGCONT to keepalive process'
This merges a sequence of commits that undoes the SIGCONT orchestration
used for WSL compatibility. The essential problem is this: In Unix and
Linux, exited processes are still valid until it is reaped; you can, say,
make an exited process a group leader. But in Windows, when a process
exits, it is gone, and most syscalls (other than, say, waitpid) fail for
it. This is known as the WSL Rick Grimes problem.

This manifests as various race conditions in WSL between a parent operating
on a child, and the child exiting. Prior to this merge, these were
addressed by having the child wait for the parent to send it a SIGCONT.
This resolved the race.

This merge removes this approach and replaces it with a simpler mechanism
that leverages the existing keepalive machinery. A keepalive process is
created for all platforms when we have a pipeline that contains a builtin.
This is necessary to keep the whole process group alive. The fix is, on
WSL, we always create a keepalive and make it the group leader. Because the
keepalive does not call exec and its lifetime is bound to a C++ stack
frame, it is easy to resolve the race.

This improves performance a bit (except on WSL), since child processes no
longer have to synchronize with the parent process, but the big win is
simplicity. This removes the notion of the single global stopped child, of
which there could only be one, and which had be resumed at the right
time(s), of which there were several.
2018-02-07 12:57:01 -08:00
ridiculousfish
cb03be9fe6 Remove unused 'pgrp_set' variable 2018-02-07 12:54:26 -08:00
ridiculousfish
8de266afb4 Improve commenting regarding process groups and builtins. 2018-02-07 12:49:12 -08:00