Commit Graph

1418 Commits

Author SHA1 Message Date
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
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
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
ridiculousfish
0c18f68cc2 Remove support for blocking children
This removes support for blocking children via signals, which was used
to orchestrate processes on WSL. Now we use the keepalive mechanism
instead.
2018-02-07 12:49:12 -08:00
ridiculousfish
080521071f Teach keepalives to exit when their parent dies
keepalive processes are typically killed by the main shell process.
However if the main shell exits the keepalive may linger. In WSL
keepalives are used more often, and the lingering keepalives are both
leaks and prevent the tests from finishing.

Have keepalives poll for their parent process ID and exit when it
changes, so they can clean themselves up. The polling frequency can be
low.
2018-02-07 12:49:12 -08:00
ridiculousfish
14880ce7d1 Resume setting group ID in both parent and child 2018-02-07 12:49:12 -08:00
ridiculousfish
e9f676a7f4 Provide a way to stop blocking children via s_block_children
This is to investigate alternatives to the existing kill(SIGSTOP)
WSL compatibility thing.
2018-02-07 12:49:11 -08:00
ridiculousfish
1b1fd5ab9b Mark needs_keepalive more often for WSL
Have WSL use a keepalive whenever the first process is external.
This works around the fact that WSL prohibits setting an exited
process as the group leader.
2018-02-07 12:49:11 -08:00
ridiculousfish
cef39cdcc0 Add is_windows_subsystem_for_linux to detect WSL 2018-02-07 12:49:11 -08:00
Mahmoud Al-Qudsi
7fafdee98e
Merge pull request #4704 from fish-shell/curses_ncurses
Fix curses includes on platforms offering real libcurses.
2018-02-06 10:44:29 -06:00
ridiculousfish
72208a9438 Use the layout cache instead of static variables for caching prompts
This correctly reacts to changes in TERM (which might affect prompt
width due to escape code differences), and eliminates some ugly
static variables.
2018-02-04 16:20:55 -08:00
ridiculousfish
1bd5946d23 Add prompt layout caching to layout_cache_t 2018-02-04 16:20:55 -08:00
ridiculousfish
d1436486e2 Rename cached_esc_sequences_t to layout_cache_t
Preparation for migrating the prompt cache into this struct.
2018-02-04 16:20:55 -08:00
ridiculousfish
a87970fbb5 Have the pager use a simple newline count to determine reserved lines
When the pager wants to use the full screen to show many options, it reserves
space at the top to see the command. Previously it pretended the command was a
prompt and engaged the prompt layout mechanism to compute these lines. Instead
let's juts count newlines since escape sequences within commands are very rare.
2018-02-04 14:14:37 -08:00
slama
27c1c06ed4 improve the size of completions page to show the entire prompt 2018-02-04 14:04:08 -08:00
ridiculousfish
9ba6b62791 Remove some ancient "#if 0' code and fix formatting errors 2018-02-04 14:03:08 -08:00
Mahmoud Al-Qudsi
63c8a197e5 [cmake] Clean up curses vs ncurses includes
There were several issues with the way that the include tests for curses.h
were being done that were ultimately causing fish to use the headers from
ncurses but link against curses on platforms that provide an actual
libcurses.so that isn't just a symlink to libncurses.so

In particular, the old code was first testing for curses's cureses.h and then
falling back to libncurses's implementation of the same - but that logic was
reversed when it came to including term.h, in which case it was testing for
the ncurses term.h and falling back to the curses.h header. Long story short,
while cmake will link against libcurses.so if both libcurses.so and
libncurses.so are present (unless CURSES_NEED_NCURSES evaluates to TRUE, but
that makes ncurses a hard requirement), but we were brining in some of the
defines from the ncurses headers, causing SIGSEGV panics when fish ultimately
tried to access variables that weren't exported or were mapped to undefined
areas of memory in the other library.

Additionally it is an error to include termios.h prior to including the plain
Jane curses.h (not ncurses/curses.h), causing errors about unimplemented types
SGTTY/chtype. So far as I can tell, both curses.h and ncurses/curses.h pull in
termios.h themselves so it shouldn't even be necessary to manually include it,
but I have just moved its #include below that of curses.h
2018-02-04 03:11:22 -06:00
ridiculousfish
85fba3a316 Remove HISTORY_SEARCH_TYPE_*_PCRE
These were unused and unimplemented.
2018-02-03 14:41:01 -08:00
ridiculousfish
89709c3a89 Clean up some history search interfaces 2018-02-03 14:41:01 -08:00
Fabian Homborg
5262719995 Don't fire exit events for jobs with pgid == -2
This fixes a hang common on WSL, when fish has PID 2.

Fixes #4582.
2018-02-03 16:22:57 +01:00
David Adam
fb53a96a1c Add configure-time check for std::make_unique
Fixes the build on Clang 6 and closes #4685.
2018-01-31 13:43:05 +08:00
ridiculousfish
54cefeb5b1 Make sliced history (e.g. $history[1]) much faster
This special cases expansion of $history variables, so that slicing
history no longer needs to construct the entire history array. Speedup
is around 100x in my test.

Fixes #4650
2018-01-30 18:34:46 -08:00
ridiculousfish
816d35de43 Clean up expand_variables
Partially rewrite this function to be shorter and easier to follow.
2018-01-30 17:45:34 -08:00
ridiculousfish
3d1975c6a6 Convert variable_is_colon_delimited_var to a const array 2018-01-30 13:32:15 -08:00
ridiculousfish
39a02f8ead Turn the set of read-only variables into a const array 2018-01-30 13:28:49 -08:00
ridiculousfish
f025269195 env_var_t to forget its name
Store properties associated with the name via flags instead
2018-01-30 12:36:50 -08:00
ridiculousfish
5c2e6734c1 Normal text input to disable paging instead of search
Prior to this fix, if the user typed normal characters while the
completion pager was shown, it would begin searching. This feature was
not well liked, so we are going to instead just append the characters as
normal and disable paging. Control-S can be used to toggle the search
field.

Fixes #2249
2018-01-30 09:58:08 -08:00
ridiculousfish
d0d7bb75cd Add new pager-toggle-search input function
This adds a new input binding pager-toggle-search which toggles the
search field on and off when the pager is showing.
2018-01-30 09:58:08 -08:00
ridiculousfish
d03aff8742 Encapsulate input function name and code into a single struct
Reduces the reliance in ugly parallel arrays.
2018-01-29 19:15:16 -08:00
ridiculousfish
43c839ab0e Rename R_MIN and R_MAX to R_BEGIN/END_INPUT_FUNCTIONS
This makes the names more obvious.
We also make the range half-open as is the convention.
2018-01-29 11:53:44 -08:00
ridiculousfish
9ce3ac5b93 Remove R_SENTINAL
It was unused and misspelled.
2018-01-29 11:30:11 -08:00
ridiculousfish
5b3729842c tnode_t::try_get_child() to properly implement null check.
try_get_child() was taking the address of a reference; clang was thereby
assuming it could not be null and so was dropping the null check. Ensure
we do not dereference a null pointer.

Fixes #4678
2018-01-28 15:07:19 -08:00
Fabian Homborg
cddd0d7538 [Pager] Adjust tests for changes in behavior
Since moving west no longer gets stuck in the top row (but instead
wraps around to the bottom row), this needs to have some indices
changed.
2018-01-25 13:26:53 +01:00
Fabian Homborg
dc95bfc1b1 [Pager] Make up without selected contents jump back into the pager
This makes it possible to select the last element of the completions
with just one keypress.

Fixes #3115.
2018-01-25 13:26:53 +01:00
Fabian Homborg
13079911bc [Pager] Wrap cardinal direction movement
Fixes #4669.
2018-01-25 13:26:53 +01:00
ridiculousfish
a39c57c1b6 Report errors for arguments to 'end'
For example, `begin ; end arg` will now report an error.

Fixes #986
2018-01-22 13:31:39 -08:00
ridiculousfish
9d48c68f24 Remove argument_or_redirection type
This was a symbol that represented either an argument or a redirection.
This was only used as part of argument_or_redirection_list.
It's simpler to just have these types be alternatives in the list type.
2018-01-22 13:18:34 -08:00
ridiculousfish
f81eef5ee1 Improve type checking of certain tnode_t interfaces 2018-01-22 13:13:28 -08:00
ridiculousfish
3b64a256b6 Add type checking to find_child()
Ensure that find_child() with impossible child nodes will now error
at compile time.
2018-01-22 11:09:29 -08:00
ridiculousfish
ae9b5871fb Fix a tnode-related crash in syntax highlighting
Adds a new test too.
2018-01-21 02:17:21 -08:00
ridiculousfish
04162b05ea Remove the giant 'Fish grammar' comment
The fish grammar is now captured more precisely in parse_grammar.h
2018-01-20 14:09:40 -08:00
ridiculousfish
852cf183a6 Remove some unused parameters 2018-01-20 14:09:36 -08:00
ridiculousfish
0f8e8d1cea Migrate tnode implementation to tnode.cpp
Also improve commenting.
2018-01-20 13:33:09 -08:00
ridiculousfish
094e853a20 Migrate tnode_t into new header tnode.h 2018-01-20 12:15:28 -08:00
ridiculousfish
1c2943bd8b Make statement_is_in_pipeline a free typesafe function 2018-01-20 11:45:43 -08:00
ridiculousfish
194f7f34d9 Eliminate parse_node_tree::find_nodes 2018-01-20 11:45:43 -08:00
ridiculousfish
242512f0df Migrate argument_list_is_root out of parse_node_tree_t 2018-01-20 11:45:43 -08:00
ridiculousfish
c1b60fa8e1 Remove header_node_for_block_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
d7c28c9316 Eliminate job_should_be_backgrounded 2018-01-20 11:45:43 -08:00
ridiculousfish
3e7e92dfff Remove specific_statements_for_job 2018-01-20 11:45:43 -08:00
ridiculousfish
05e8cf13f7 Eliminate parse_execution_context_t::get_child 2018-01-20 11:45:43 -08:00
ridiculousfish
5e4e0dab2c Convert run_job_list to tnode_T 2018-01-20 11:45:43 -08:00
ridiculousfish
4c93cece58 Convert run_1_job to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
fa0f552fe9 Convert populate_block_process to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
2bf96493fc Continued adoption of tnode in parse_execution.cpp 2018-01-20 11:45:43 -08:00
ridiculousfish
9c88d71e2f Convert handle_command_not_found to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
298db6e11a Convert populate_plain_process to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
8a14a4a5ff Continued adoption of tnode_t in parse_execution
Migrate boolean statements
2018-01-20 11:45:43 -08:00
ridiculousfish
7a3d5ddeae Convert run_begin_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
6f99c9a904 Adopt tnode_t in run_function_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
edc3d92eda Adopt tnode in run_while_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
554bef93ba Switch run_switch_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
3981accf05 Adopt tnode_t in run_if_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
ce173e86b5 Adopt tnode_t in run_for_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
b23c6ebcba Migrate run_block_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
cdc0167ba1 Switching symbol_job to use tnode_t in parse_execution.cpp 2018-01-20 11:45:43 -08:00
ridiculousfish
4768c42f5d Early adoption of tnode_t in parse_execution.cpp 2018-01-20 11:45:40 -08:00
ridiculousfish
6f4db9f8ad Add type safety to tnode_t::try_get_child
Detect when no options in an alternation type match the requested type,
and ensure such cases do not compile.
2018-01-20 11:31:40 -08:00
ridiculousfish
f0f56a6910 Teach decoration_for_plain_statement about tnode, rename it get_decoration 2018-01-20 11:31:40 -08:00
ridiculousfish
84dcb24682 Namespace alias grammar to 'g' in highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
d4f9fcc7c7 Adopt tnode_t in detect_errors_in_backgrounded_job 2018-01-20 11:31:40 -08:00
ridiculousfish
539e9bf970 Continued adoption of tnode_t in highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
b0c892d26f More tnode_t adoption in highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
18a120d00e Migrate command_for_plain_statement to tnode_t 2018-01-20 11:31:40 -08:00
ridiculousfish
f16ae9348f Continued adoption of tnode_t in complete.cpp and highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
baa0c73d81 Adopt tnode_t in autosuggest_parse_command() 2018-01-20 11:31:40 -08:00
ridiculousfish
55fc10ea6e Migrate parse_util_detect_errors_in_argument to tnode_t 2018-01-20 11:31:40 -08:00
ridiculousfish
f69055b5e9 Adopt tnode_t in parse_util_detect_errors 2018-01-20 11:31:40 -08:00
ridiculousfish
4d68877f51 tnode_t adoption of find_nodes 2018-01-20 11:31:40 -08:00
ridiculousfish
618996a166 Some adopton of tnode_t in complete.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
cfe355554c Adopt tnode in reader_expand_abbreviation_in_command 2018-01-20 11:31:40 -08:00
ridiculousfish
3d4dd4abef Introduce tnode 2018-01-20 11:31:40 -08:00
ridiculousfish
cf116e4880 Rejigger alts
Messing around
2018-01-20 11:31:40 -08:00
ridiculousfish
a012320a9a Add grammar in type system 2018-01-20 11:31:40 -08:00
ridiculousfish
de8ccf1751 Stop warning on invalid PATHs and CDPATHs if any element is valid
Some dotfile users like to add directories to PATH that point at
non-existent directories (because those directories exist on other
machines). Stop warning in that case, unless those directories contain
a colon, in which case it's probably a user error.
2018-01-08 23:04:30 -08:00
ridiculousfish
46db0dd5eb Stop checking EXPAND_SPECIAL_FOR_CD if ..._AUTOSUGGEST is set
If EXPAND_SPECIAL_FOR_CD_AUTOSUGGEST is set, EXPAND_SPECIAL_FOR_CD
is necessarily also set; simplify things by only checking for the
latter.
2018-01-08 22:34:14 -08:00
Matthew Brock
bf63e061c9 Fix overzealous cd tab completion
Changed cd completion to differentiate between cd autosuggest and cd tab
completion. cd autosuggest will find deepest unique hierarchy and cd tab
completion will not.

Issue #4402
2018-01-08 22:32:06 -08:00
ridiculousfish
d09210c08b [cmake] Untangle the CMake versioning
This untangles the CMake versioning issues (I hope) as discussed in #4626.
Note most of the advice found on the Internet about how to inject git
versions into CMake is just wrong.

The behavior we want is to unconditionally run the script
build_tools/git_version_gen.sh at build time (i.e. when you invoke ninja or
make, and not when you invoke cmake, which is build system generation time).
This script is careful to only update the FISH-BUILD-VERSION-FILE if the
contents have changed, to avoid spurious rebuilding dependencies of
FISH-BUILD-VERSION-FILE. Assuming the git version hasn't changed, the script
will run, but not update FISH-BUILD-VERSION-FILE, and therefore
fish_version.o will not have to be rebuilt.

This might normally rebuild more than is necessary even if the timestamp is
not updated, because ninja computes the dependency chain ahead of time. But
Ninja also supports the 'restat' option for just this case, and CMake is rad
and exposes this via BYPRODUCTS. So mark FISH-BUILD-VERSION-FILE as a
byproduct and make the script always update a dummy file
(fish-build-version-witness.txt). Note this is the use case for which
BYPRODUCTS is designed.

We also have fish_version.cpp #include "FISH-BUILD-VERSION-FILE", and do a
semi-silly thing and make FISH-BUILD-VERSION-FILE valid C++ (so there's just
one version file). This means we have to filter out the quotes in other
cases..
2018-01-08 22:28:10 -08:00
ridiculousfish
da8db7f6f0 Revert "Generate FISH_BUILD_VERSION info for cmake builds"
This reverts commit 25839b8c36.

This was an attempt to simplify the version generation, but it
computed the version at build sytem generation time rather than
at build time, requiring another run of CMake to update it.
2018-01-08 22:28:10 -08:00
Fabian Homborg
aa58cae601 Don't count successive "," as literal in brace expansion
This was highly surprising.

Fixes #3002.
2018-01-07 15:00:44 +01:00
Fabian Homborg
55ebf4430f Make literal "{}" expand to itself
This caused major annoyances with e.g. `find -exec`, and it's utterly
useless - "{}" expands to nothing, so why have it at all?

Fixes #1109.
2018-01-07 15:00:44 +01:00
Fabian Homborg
75ac482cec Don't crash when setting fish_history before reader is initialized
Not crashing is just soo much nicer.

Fixes #4619.
2018-01-01 13:02:39 +01:00
Mahmoud Al-Qudsi
25839b8c36 Generate FISH_BUILD_VERSION info for cmake builds
Correctly generate FISH_BUILD_VERSION for use in fish_version.h/cpp and
fish.pc to allow `fish --version` and `echo $version` to work again.

Not needing the same convoluted measures used by Makefile builds to
prevent the regeneration of the fish version file when it hasn't
changed.

Purposely created a new `cmake_git_version_gen.sh` file so that the old
`git_version_gen.sh` remains compatible with the existing Makefile build
script. Same reason why `fish.pc.in` was not modified to use a lowercase
variable name to match the CMAKE variable of the same name.

Closes #4626
2017-12-30 17:38:09 -06:00
ridiculousfish
3b3047c3f6 Remove unused functions from env_var_t 2017-12-24 00:03:28 -08:00
ridiculousfish
8f8e19bf7b Fix a misleading stale comment 2017-12-22 19:35:59 -08:00
ridiculousfish
d5d3712220 Correct some more memory management in env.cpp 2017-12-22 17:38:25 -08:00
ridiculousfish
efeb8e43a2 Remove a bunch of unnecessary copying in env.cpp 2017-12-22 17:31:25 -08:00
ridiculousfish
2c5b49c3fe Clean up env_var_t interface 2017-12-22 16:54:15 -08:00
ridiculousfish
05b5e8e4f8 Stop copying strings in var_stack_t::var_changed
var_stack_t::var_changed was doing tons of unnecessary string copies.
Fix that and make its name clearer.
2017-12-22 16:28:15 -08:00
ridiculousfish
aa22c744d2 Mark parsed_source_ref_t as storing a const pointer 2017-12-22 15:44:14 -08:00
ridiculousfish
457213a768 Turn debug() into a macro
A large portion of time was spent constructing strings and passing
them to debug(). Turn debug into a macro so that the strings are only
constructed if they're going to be printed.
2017-12-22 15:19:08 -08:00
ridiculousfish
a99eecfad8 Wrap up source code and a parse tree into a new type parsed_source_ref_t
This will make it unnecessary to carry around the parse tree and source
separately, and enable some simplifications.
2017-12-22 14:40:15 -08:00
ridiculousfish
d17b298a48 Factor out the code that executes a builtin from exec_job()
Very early work on untangling the exec_job spaghetti.
2017-12-22 13:41:29 -08:00
ridiculousfish
a2114233ac Fix some warnings 2017-12-21 15:48:48 -08:00
ridiculousfish
0c55b79cfc [string] Instance the argument parsing
This adds a new class arg_iterator_t which encapsulates decisions about
whether to read arguments from stdin or argv. It also migrates the
unread bytes buffer from a static variable to an instance variable.
2017-12-21 12:42:57 -08:00
Fabian Homborg
f9d883dd74 Add and use str2wcstring(string, size_t)
This is just for convenience.
2017-12-20 14:31:29 +01:00
Fabian Homborg
2de38ef7bf [string] Chunk reads
Profiling with callgrind revealed that about 60% of the time in a `something | string match` call
was actually spent in `string_get_arg_stdin()`,
because it was calling `read` one byte at a time.

This makes it read in chunks similar to builtin read.

This increases performance for `getent hosts | string match -v '0.0.0.0*'` from about 300ms to about 30ms (i.e. 90%).
At that point it's _actually_ quicker than `grep`.

To improve performance even more, we'd have to cut down on str2wcstring.

Fixes #4604.
2017-12-20 14:30:41 +01:00
ridiculousfish
11e6cfeb82 [math] Remove exception handling in builtin_math
This handles errors explicitly instead of catching them.
2017-12-18 23:01:16 -08:00
ridiculousfish
91c28449aa [muparser] Parser mathematical functions to return errors instead of throw
Remove exceptions from Parser functions such as sqrt, min, and others.
2017-12-18 23:01:16 -08:00
ridiculousfish
9649b132bd [muparser] Continue adopting ValueOrError 2017-12-18 23:01:15 -08:00
ridiculousfish
5655f255ef [muparser] Add a muParser ValueOrError type
First steps towards removing exceptions from muParser.
2017-12-18 23:01:15 -08:00
ridiculousfish
81dd4a4536 [math] Remove more bare variable support
Prior to this fix, a "bare variable" in math like 'x + 1' would be
looked up in the environment, i.e. equivalent to '$x + 1'. This appears
to have been done for performance. However this breaks the orthogonality
of fish; performance is not a sufficient justification to give math this
level of built-in power, especially because the performance of math is
not a bottleneck. The implementation is also ugly.

Remove this feature so that variables must be prefixed with the dollar
sign and undergo normal variable expansion. Reading 'git grep' output
does not show any uses of this in fish functions or completions.

Also added to changelog.

Fixes #4393
2017-12-17 12:40:09 -08:00
Alan Somers
8fb6d5db3b Fix the build on FreeBSD ARM and ARM64 (#4593)
Downstream bug:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224254

Fixes #4589
2017-12-12 22:45:17 -08:00
hazem samir
c45d4abaef Implement Linear glob match #4094 2017-12-10 20:12:40 -08:00
ridiculousfish
bc28bd7d6d Use some modern initialization syntax in builtin_wait
Avoids potentially dangling pointers.
2017-11-16 10:54:34 -08:00
ridiculousfish
7c8ed80e64 Fix up builtin_wait build system
Add missing CMake and Xcode files, and mark some variables as const
reference.
2017-11-16 10:48:21 -08:00
slama
c7a682ed05 add wait command 2017-11-16 10:48:21 -08:00
David Adam
ea5f3925ea drop USE_GETTEXT macro and use only HAVE_GETTEXT
There is no clear rationale for the two separate macros.
2017-11-16 21:29:42 +08:00
Andrew Stewart
9c060126b5 fixed small typo in src/builtin_jobs.cpp (#4530) 2017-11-10 11:41:02 -08:00
David Adam
848db48af5 Improve warning message when exiting with active jobs
Work on #4303.
2017-10-31 19:18:44 +08:00
David Adam
eb081481c6 warning message when exiting with active jobs uses PID of first process, not PGID
Work on #4303.
2017-10-31 19:17:21 +08:00
David Adam
b34b0cf1e3 Restore previous output of status current-{filename,function}
Closes #4499.

Partial reversion of 30368d5526.
2017-10-31 18:10:46 +08:00
Valery Ushakov
8f0f05ca44 Rewrite tparm_solaris_kludge to call tparm with default parameters
Closes #4502.
2017-10-31 16:48:35 +08:00
David Adam
216c4b811a only call ioctl to export new termsize if process is in the foreground
Closes #4477.
2017-10-21 07:21:17 +08:00
slama
7004c30f95 allow edit across newlines wherever the cursor is if the line ends with a backslash.
Fixes #4467
2017-10-18 11:58:01 -07:00
Aaron Gyes
a9283803d4 Revert "Non-exported vars: rename SHLVL to shlvl"
Duh, of course it is exported.

This reverts commit 5fc17dcc82.
2017-10-15 04:37:34 -07:00
Aaron Gyes
5fc17dcc82 Non-exported vars: rename SHLVL to shlvl
Fixes #4414
2017-10-15 04:33:27 -07:00
Aaron Gyes
fb8ae04f80 Rename $FISH_VERSION back to the original $version.
Order is restored in the universe. Fixes #4414
2017-10-14 08:33:02 -07:00
Aaron Gyes
7be8a1707c Rename FISH_READ_BYTE_LIMIT to fish_read_limit
Fixes #4414
2017-10-14 08:33:02 -07:00
Aaron Gyes
18b06f3768 Rename CMD_DURATION to cmd_duration
Fixes #4414
2017-10-14 08:33:02 -07:00
Mahmoud Al-Qudsi
0a1294758d Replace opts.stdout with opts.to_stdout
For some reason on Solaris the previous code was refusing to compile
with an error (regarding the declaration of stdout in the opts struct)

    error: declaration of ‘__iob’ as array of references

The obvious guess that it had something to do with the name of the
variable in question proved true; renaming it from `stdout` to
`opts.stdout` allows the build to go through.
2017-10-12 11:44:14 -05:00
ridiculousfish
1f130bcc9c Change wrealpath to return a maybe_t
Simplify the wrealpath interface and avoid manual invocations of free() by
changing wrealpath to return a maybe_t<wcstring>.
2017-10-11 00:08:26 -07:00
ridiculousfish
05c0cb713d Stop passing NULL for realpath()'s second param
macOS 10.5 and earlier do not support the convention of returning
a dynamically allocated string, plus this seems like an unnecessary
malloc. Always allocate a buffer for realpath() to write into.
2017-10-10 23:31:27 -07:00
Mahmoud Al-Qudsi
639faf1c7f Fix uninitialized memory access dependent on argc
It seems that `parse_cmd_opts` does not correctly handle no arguments,
and so argc was being decremented to -1 causing uninitialized memory
access when argv[0] was dereferenced at a later point.
2017-10-11 07:22:42 +02:00
Mahmoud Al-Qudsi
8ffc3ab242 Drop no-longer-needed iostream header from src/builtin_read.cpp 2017-10-10 08:23:24 +02:00
Mahmoud Al-Qudsi
d0bc04cb40 Change read to stdout behavior to kick in on no arguments only
No longer using `-` to indicate reading to stdout. Use lack of arguments
as stdout indicator. This prevents mixing of variables with stdout
reading and makes it clear that stdout may not be mixed with delimiters
or array mode.
2017-10-10 08:23:23 +02:00
Mahmoud Al-Qudsi
06afcb43b4 Support reading to stdout via builtin read -
Added an option to read to stdout via `read -`. While it may seem
useless at first blush, it lets you do things like include

    mysql -p(read --silent) ...

Without needing to save to a local variable and then echo it back.
Kicks in when `-` is provided as the variable name to read to. This is
in keeping with the de facto syntax for reading/writing from/to
stdin/stdout instead of a file in, e.g., tar, cat, and other standard
unix utilities.
2017-10-10 08:23:23 +02:00
Mahmoud Al-Qudsi
e99f137356 Merge branch 'master' into history-glob-search 2017-10-10 08:16:21 +02:00
Mahmoud Al-Qudsi
6e933f1c8f Add -s to builtin_bind's allowed parameter list 2017-10-03 11:20:17 +02:00
Mahmoud Al-Qudsi
46d1334f95 Silence bind errors in default key bindings
This silences binding errors due to keys not found in the current
termcap config in the default fish bindings.

Closes #4188, #4431, and obviates the original fix for #1155

It was necessary to re-implement builtin_bind as a class in order to
avoid passing around the options array from function to function and
as adding an opts parameter to `get_terminfo_sequence` would require
otps to be passed to all other builtin_bind_ functions so they could, in
turn, pass it to `get_terminfo_sequence`.
2017-10-03 11:20:17 +02:00
Sergei Trofimovich
53fd356850 fix 'printf "%o"' handling on powerpc64
On powerpc64 (big-endian platform) one test failed as:

  Testing file printf.in ... fail
  Output differs for file printf.in. Diff follows:
  --- printf.tmp.out      2017-10-02 18:14:17.740000000 -0700
  +++ printf.out  2017-10-02 18:11:59.370000000 -0700
  @@ -1,5 +1,5 @@
   Hello 1 2 3.000000 4.000000 5 6
  -a B 0 18446744073709551615
  +a B 10 18446744073709551615

It happens due to roughly the following code:
    swprintf(..., L"%o", (long long)8);
Here mismatch happens between "%o" (requires 32-bit value)
and 'long long' (requires 64-bit value).

The fix turns it effectively to:
    swprintf(..., L"%llo", (long long)8);
as it was previously done for 'x', 'd' and other int-like types.

Makes tests pass on powerpc64.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2017-10-03 04:17:56 +03:00
Aaron Gyes
635e714bb4 Make italics/dim work on MacOS
Work around ancient terminfo on MacOS by hard-coding the correct escapes.
Fixes #4436.
2017-09-29 14:25:09 -07:00
Mahmoud Al-Qudsi
c40188e40e Since cwd is a path, use PATH_MAX and not NAME_MAX 2017-09-26 10:00:23 -05:00
Mahmoud Al-Qudsi
b495c68f28 Fix non-standard getcwd() invocation
The POSIX standard specifies that a buffer should be supplied to
getcwd(), not doing so is undefined (or rather, platform-defined)
behavior. This was causing the getcwd errors on illumos (though not seen
on Solaris 11) reported in #3340

Closes #3340
2017-09-26 09:53:36 -05:00
Mahmoud Al-Qudsi
ffebe74885 Support building on Solaris 11
Took care of remaining issues preventing fish from building on Solaris.
Mainly caused by some assumptions that certain defines are POSIX when
they are not (`NAME_MAX`).

Moved `NAME_MAX` defines to common.h - for some reason, it was being
defined in a cpp file (`env_universal_common.cpp`) even though it is used
in multiple source files.

Now compiles on Solaris 11 with GNU Make. Still some warnings because
fish was written with GNU getopt in mind and the Solaris version doesn't
use `const char *` but rather just `char *` for getopt values, but it
builds nevertheless.

Assuming this closes #3340
2017-09-26 08:19:33 -05:00
Mahmoud Al-Qudsi
9fdfe44236 Fix type of pid_status variable
We had pid_status defined as a pid_t instance, which was fine since on
most platforms pid_t is an alias for int. However, that is not
universally the case and waitpid takes an int *, not a pid_t *.
2017-09-26 08:16:36 -05:00
Mahmoud Al-Qudsi
56c041b889 Work around WSL access(2) EINVAL bug
See Microsoft/BashOnWindows#2522, Microsoft/BashOnWindows#2448
2017-09-24 13:43:50 -05:00
David Adam
472e186c2b Rename FISH_HISTORY to fish_history
Work on #4414.
2017-09-24 14:07:45 +08:00
ridiculousfish
91ae39008a Correct prefix length calculation in completion measurement
A completion may have zero length; in this case the length of the
prefix was omitted and the completion was not visible. Correct the
calculation to account for zero-width completions.

Fixes #4424
2017-09-23 13:06:44 -07:00
Kurtis Rader
026cb48dce Remove unintended change from prev commit 2017-09-21 12:45:54 -07:00
Kurtis Rader
b241bf4140 Use \uXXXX consistently for unicode code points
A recent discussion involving whether `can_be_encoded()` was broken
caused me to notice that we are inconsistent about whether Unicode code
points are specified using `\xXXXX` or `\uXXXX` notation. Which is
harmless but silly and potentially confusing.
2017-09-20 22:00:14 -07:00
Kurtis Rader
67946b5509 Drop deprecated history search --with-time flag (#4403)
This flag was only documented for a few weeks before being renamed
`--show-time` and has been deprecated for a long time. Fish 3.0 is a good
opportunity to remove it.
2017-09-15 19:28:44 -07:00
Kurtis Rader
65dcd06ca1 mplement history search glob searches
Instead of treating the search term as a literal string to be matched
treat it as a glob. This allows the user to get a more useful set of
results by using the `*` glob character in the search term.

Partial fix for #3136
2017-09-15 13:43:45 -07:00
Kurtis Rader
ee1d310651 Implement history search --reverse (#4375)
* Implement `history search --reverse`

It should be possible to have `history search` output ordered oldest to
newest like nearly every other shell including bash, ksh, zsh, and csh.
We can't make this the default because too many people expect the
current behavior. This simply makes it possible for people to define
their own abbreviations or functions that provide behavior they are
likely used to if they are transitioning to fish from another shell.

This also fixes a bug in the `history` function with respect to how it
handles the `-n` / `--max` flag.

Fixes #4354

* Fix comment for format_history_record()
2017-09-14 15:44:17 -07:00
ridiculousfish
b688deb33e Reduce number of threads in history race test
Our lock-breaking timeout means this test may spuriously fail.
Reduce the torture element to make the test more likely to pass.
2017-09-11 22:34:59 -07:00
Peter Ammon
1413e20ed4 Fix thread sanitizer errors in iothread
This uses an atomic bool for main_thread_request_t::done.

Fixes #3895
2017-09-11 15:50:41 -07:00
Mahmoud Al-Qudsi
039c3c1673 Drop unused parameters to show_stackframe on non-Linux systems
Fixed a warning about unused parameters on systems where
HAVE_BACKTRACE_SYMBOLS is not defined.
2017-09-10 10:52:41 -05:00
Mahmoud Al-Qudsi
55b3c45f95 No longer put fish in own process group on startup
As discussed in #3805, this patch disables assigning fish to its own
process group at startup. This was trialled in #4349 alongside other
pgrp fixes which introduced additional problems, but this particular fix
seems to be OK.

Fixes #3805 and works around Microsoft/BashOnWindows#1653
2017-09-09 22:32:16 -05:00
Kurtis Rader
905766fca2 Hoist for loop control var to enclosing scope (#4376)
* Hoist `for` loop control var to enclosing scope

It should be possible to reference the last value assigned to a `for`
loop control var when the loop terminates. This makes it easier to detect
if we broke out of the loop among other things.  This change makes fish
`for` loops behave like most other shells.

Fixes #1935

* Remove redundant line
2017-09-08 21:14:26 -07:00
Fabian Homborg
527e102746 Fix string match -en error typo
Fixes #4386.
2017-09-08 16:33:34 +02:00
ridiculousfish
cb352317bd Simplify the cached_esc_sequences_t structure
The type cached_esc_sequences_t caches escape sequences, and is tasked
with finding an escape sequence that prefixes a given string. Before
this fix, it did so by storing the lengths of cached escape sequences,
and searching for substrings of that length. The new implementation
instead stores all cached escape sequences in a sorted vector, and uses
binary search to find the shortest escape sequence that is a prefix of
the input. This is a substantial simplification that also reduces
allocations.
2017-09-01 14:36:16 -07:00
ridiculousfish
95162ef19d Revert "Cache math expressions"
This reverts commit 56d9134534.

An LRU cache in the shell for math seems like overkill.
2017-09-01 00:25:40 -07:00
ridiculousfish
3d40292c00 Switch env_var to using maybe_t
This eliminates the "missing" notion of env_var_t. Instead
env_get returns a maybe_t<env_var_t>, which forces callers to
handle the possibility that the variable is missing.
2017-09-01 00:14:42 -07:00
ridiculousfish
18203a081c Add maybe_t template class
maybe_t is an implementation of the Maybe/Optional type, allowing
for an optional value to be stored. This will enable a more
principled approach for functions that return values or failure,
such as env_get.
2017-09-01 00:14:14 -07:00
ridiculousfish
c8cf8a6669 Clean up fish_uvars_test directory in tests
Allows running fish_tests directly without an initialization phase.
2017-08-30 01:02:18 -07:00
ridiculousfish
4baada25b9 Use move semantics instead of swap in env_set
This commit backs out certain optimizations around setting environment
variables, and replaces them with move semantics. env_set accepts a
list,  by value, permitting callers to use std::move to transfer
ownership.
2017-08-30 00:59:45 -07:00
David Adam
874a675e7f builtin_read: pickup MB_CUR_MAX from stdlib not xlocale
Fixes building on OpenBSD; work on #4184.
2017-08-28 01:44:07 +08:00
Mahmoud Al-Qudsi
dfeac760b9 Fix invalid memory access regression
Commit f872f25f introduced a freed memory access regression on line 460
of env.cpp, where an environment variable was converted to a temporary
string, the .c_str() address of which was stored while the string
temporary was destroyed.

This commit keeps a reference to the original string lying around so
that the c_str() pointer does not point to freed memory.
2017-08-26 19:24:05 -05:00
Mahmoud Al-Qudsi
e656654456 Fix uninitialized sigaction.sa_flags valgrind error
Valgrind warns that the sometimes uninitialized sigaction.sa_flags field
is sometimes used when passed to the signal handler.

This patch explicitly zeros out the sigaction.sa_flags field at creation
time.
2017-08-26 19:13:58 -05:00
Kurtis Rader
99d2a344c7 Fix indexing of $history
cherry-picked from krader1961/fish-shell commit b69df4fe72

Fixes #4353 (regression in indexing of history contents) and introduces
new unit tests to catch bad $history indexing in the future.
2017-08-25 20:28:45 -05:00
Kurtis Rader
56d9134534 Cache math expressions
This implements an LRU cache of recently seen math expressions. When
executing math inside loops and the like this can provide a 33% decrease
in the time to execute the `math` command.
2017-08-24 12:18:39 -07:00
Kurtis Rader
c95b9f06e1 Implement support for bare vars by math
This change allows you to type `math x + 3` rather than `math $x + 3`.

Another step to resolving issue #3157.
2017-08-23 20:41:45 -07:00
Kurtis Rader
b816cd6d50 Change how math rounds integer results
We need our `math` builtin to behave like `bc` with respect to rounding
floating point values to integer to avoid breaking to many existing
uses. So when scale is zero round down to the nearest integer.

Another change for #3157.
2017-08-23 17:31:04 -07:00
Kurtis Rader
24d251ff4b Implement support for multiple math expressions
The MuParser supports the concept of multiple expressions separated by
commas. This implements support for that so that you can do things like
this:

    set results (math '1+1, 4*2, 9^2')
2017-08-23 17:14:54 -07:00
Kurtis Rader
41a7b9457c Implement bare minimum builtin math command
This is the second baby step in resolving #3157. Implement a bare minimum
builtin `math` command. This is solely to ensure that fish can be built
and run in the Travis build environments. This is okay since anyone running
`builtin math` today is already getting an error response.

Also, more work is needed to support bare var references, multiple result
values, etc.
2017-08-23 14:43:45 -07:00
Kurtis Rader
ba53242b26 Report error when using read-only var in for loop
Using a read-only variable like `status` as a for loop control variable
has never worked. But without this change you simply get non-sensical
behavior that leaves you scratching your head in puzzlement. This change
replaces the non-sensical behavior with an explicit error message.

Fixes #4342
2017-08-20 12:02:45 -07:00
Kurtis Rader
704517e237 Fix set --local when var is not in local scope
Fixes #4321
2017-08-19 21:39:21 -07:00
Kurtis Rader
335f397277 Actually flip the order of the interpolated values
The previous commit was a no-op. Fix it.
2017-08-19 20:22:53 -07:00
Kurtis Rader
e9b24327d0 Make argparse error message deterministic
Recent changes to switch to unordered sets/maps can cause the order in
which items are returned to be non-deterministic. This change ensures
that the argparse "Mutually exclusive flags" error message to be
deterministic with respect to the order of the interpolated values.
2017-08-19 20:09:44 -07:00
Kurtis Rader
11400fb313 Another fish var performance improvement
Make setting fish vars more efficient by avoiding creating a
wcstring_list_t for the case where we're setting one value. For the case
where we're passing a list of values swap it with the list in the var
rather than copying it. This makes the benchmark in #4200 approximately
6% faster.
2017-08-19 20:01:06 -07:00
Mahmoud Al-Qudsi
a77cd98136 Removed XXHash and converted some wchar_t* to wcstring 2017-08-19 18:27:24 -05:00
Mahmoud Al-Qudsi
d54fbddb11 Using XXHash64 for all wcstring unordered_map/set hashing
Since we are including XXHash32/64 anyway for the wchar_t* hashing,
we might as well use it.

Use arch-specific hash size and xxhash for all wcstring hashing

Instead of using XXHash64 for all platforms, use the 32-bit version
when running on 32-bit platforms where XXHash64 is significantly slower
than XXHash32 (and the additional precision will not be used).

Additionally, manually specify wcstring_hash as hashing method for
non-const wcstring unordered_set/map instances (the const varieties
don't have an in-library hash and so already use our xxhash-based
specialization when calling std::hash<const wcstring>).
2017-08-19 15:36:45 -05:00
Mahmoud Al-Qudsi
d9f901f36d Squashed commit of the following:
commit 50f414a45d58fcab664ff662dd27befcfa0fdd95
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 13:43:35 2017 -0500

    Converted file_id_t set to unordered_set with custom hash

commit 83ef2dd7cc1bc3e4fdf0b2d3546d6811326cc3c9
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 13:43:14 2017 -0500

    Converted remaining set<wcstring> to unordered_set<wcstring>

commit 053da88f933f27505b3cf4810402e2a2be070203
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 13:29:21 2017 -0500

    Switched function sets to unordered_set

commit d469742a14ac99599022a9258cda8255178826b5
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 13:21:32 2017 -0500

    Converted list of modified variables to an unordered set

commit 5c06f866beeafb23878b1a932c7cd2558412c283
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 13:15:20 2017 -0500

    Convert const_string_set_t to std::unordered_set

    As it is a readonly-list of raw character pointer strings (not
    wcstring), this necessitated the addition of a hashing function since
    the C++ standard library does not come with a char pointer hash
    function.

    To that end, a zlib-licensed [0] port of the excellent, lightweight
    XXHash family of 32- and 64-bit hashing algorithms in the form of a C++
    header-only include library has been included. XXHash32/64 is pretty
    much universally the fastest hashing library for general purpose
    applications, and has been thoroughly vetted and is used in countless
    open source projects. The single-header version of this library makes it
    a lot simpler to include in the fish project, and the license
    compatibility with fish' GPLv2 and the zero-lib nature should make it an
    easy decision.

    std::unordered_set brings a massive speedup as compared to the default
    std::set, and the further use of the fast XXHash library to provide the
    string hashing should make all forms of string lookups in fish
    significantly faster (to a user-noticeable extent).

    0: http://create.stephan-brumme.com/about.html

commit 30d7710be8f0c23a4d42f7e713fcb7850f99036e
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 12:29:39 2017 -0500

    Using std::unordered_set for completions backing store

    While the completions shown to the user are sorted, their storage in
    memory does not need to be since they are re-sorted before they are
    shown in completions.cpp.

commit 695e83331d7a60ba188e57f6ea0d9b6da54860c6
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date:   Sat Aug 19 12:06:53 2017 -0500

    Updated is_loading to use unordered_set
2017-08-19 15:36:45 -05:00
Mahmoud Al-Qudsi
61b4900a70 Switch from std::map<> to std::unordered_map<> where possible
Didn't switch env_var_t map because it seems to be mostly iterated in
order, but that decision may be revisited at a later date.
2017-08-19 11:55:06 -05:00
David Adam
0dce9a2114 autoload: drop unused is_internalized property 2017-08-19 22:46:51 +08:00
Mahmoud Al-Qudsi
e76c1fd139 Remove custom lock types in favor of native C++11 mutexes
No longer using RAII wrappers around pthread_mutex_t and pthread_cond_t
in favor of the C++11 std::mutex, std::recursive_mutex, and
std::condition_variable data types.
2017-08-18 23:09:31 -05:00
Kurtis Rader
b1ac07a178 Reduce overhead of setting fish vars
The `react_to_variable_change()` function is called whenever a fish var
is set. Even as a consequence of statements like `for x in a b c`. It is
therefore critical that that function be as fast as possible. Especially
when setting the var doesn't have any side-effects which is true something
like 99.9999% of the time.

This change reduces the overhead of `react_to_variable_change()` to
unmeasurable levels. Making the synthetic benchmark in issue #4341
36% faster.

Fixes #4341
2017-08-18 20:13:13 -07:00
Kurtis Rader
55b2d36028 Remove unused vars identified by lint 2017-08-18 16:52:39 -07:00
Kurtis Rader
f872f25f5b change env_var_t to a vector of strings
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.

Fixes #4200
2017-08-18 16:24:30 -07:00
Kurtis Rader
ea45541d53 fix set --show of semi-empty var
A semi-empty var is one with a single empty string element. The
`env_var_t::empty()` method returns true for such vars but we want
`set --show` to report that it has a single empty element.
2017-08-16 13:39:48 -07:00
Mahmoud Al-Qudsi
e6bb7fc973 Silence unused result warnings on newer compilers
Newer versions of GCC and Clang are not satisfied by a cast to void,
this fix is adapted from glibc's solution.

New wrapper function ignore_result should be used when a function with
explicit _unused_attribute_ wrapper is called whose result will not be
handled.
2017-08-14 18:18:10 -07:00
Kurtis Rader
42ddab0cb4 make missing_var a singleton
Make the `env_var_t::missing_var()` object a singleton rather than a
dynamically constructed object. This requires some discipline in its use
since C++ doesn't directly support immutable objects. But it is slightly
more efficient and helps identify code that incorrectly mutates `env_var_t`
objects that should not be modified.
2017-08-14 18:18:10 -07:00
Kurtis Rader
58b604c5ba change order of env_set() args
It's bugged me forever that the scope is the second arg to `env_get()`
but not `env_set()`. And since I'll be introducing some helper functions
that wrap `env_set()` now is a good time to change the order of its
arguments.
2017-08-14 18:18:09 -07:00
peoro
5ceac038b1 Improved warning message when exiting with jobs still active
Fixes #4303
2017-08-14 18:18:09 -07:00
Kurtis Rader
74f0be2a53 remove more ENV_NULL references 2017-08-14 18:18:09 -07:00
Kurtis Rader
82b5ba1af4 fix bug in env_get() involving empty vars
My previous change to eliminate `class var_entry_t` caused me to notice
that `env_get()` turned a set but empty var into a missing var. Which
is wrong. Fixing that brought to light several other pieces of code that
were wrong as a consequence of the aforementioned bug.

Another step to fixing issue #4200.
2017-08-14 18:18:09 -07:00
Kurtis Rader
728a4634a1 replace var_entry_t with env_var_t
This is a step to storing fish vars as actual vectors rather than flat
strings.
2017-08-14 18:18:09 -07:00
Fabian Homborg
745a88f2f6 Revert "Fix clearing abandoned line with VTE (#4243)"
Unfortunately, this breaks the expect tests.

So, until I can figure out how to unbreak them:

This reverts commit 09cb31a172.
2017-08-14 18:17:34 -07:00
Fabian Homborg
cf00162340 Fix clearing abandoned line with VTE (#4243)
* Fix clearing abandoned line with VTE

With VTE-based terminals, resizing currently causes multi-line prompts
to go weird.

This changes the sequence we use to clear the line to one suggested by
a VTE
developer (https://bugzilla.gnome.org/show_bug.cgi?id=763390#c4).

It changes nothing in konsole 17.04.3 and urxvt 9.22, but they already
work.

Note that this does not fix the case where output did not end in a
newline, but that doesn't seem to be up to us. Also, it only affects
those lines.

Fixes #2320.

* Use terminfo definition instead of hardcoding

Thanks to @ixjlyons.
2017-08-14 18:17:34 -07:00
Kurtis Rader
a40d5d4ea6 fix botched merge 2017-08-09 12:30:33 -07:00
Kurtis Rader
29f933adfc Merge branch 'master' into major 2017-08-09 12:26:24 -07:00
David Adam
5d2a806ac6 set: update language of warning message 2017-08-09 14:23:00 +08:00
Kurtis Rader
55bef3cd2e remove deprecated . (dot) command
Fixes #4294
2017-08-07 18:31:20 -07:00
Kurtis Rader
fb7645659f Merge branch 'master' into major 2017-08-06 20:22:31 -07:00
Kurtis Rader
4f5bd08b20 improve set -U warning
Doing `set -U var` when a global named `var` exists can result in
confusing behavior. Try to limit the confusion by improving the warning
we write. Also, only write the warning if interactive.

Fixes #4267
2017-08-06 19:57:25 -07:00
Kurtis Rader
975a5bfbde make style-all time again
Recent changes have introduced some style deviations so clean them up.
2017-08-06 16:05:51 -07:00
Kurtis Rader
acdb81bbca lint and style cleanups 2017-08-06 15:47:01 -07:00
Kurtis Rader
083224d1c0 fixes to job control changes
The job control changes need a couple of fixes for compatibility with
changes I merged while @mqudsi was workin on his change.
2017-08-06 15:25:42 -07:00
Kurtis Rader
52d739c746 Revert "Revert "finish cleanup of signal blocking code""
This reverts commit 35ee28ff24.

Reapply the signal blocking cleanup change on top of the job control
changes made by @mqudsi.
2017-08-06 14:46:12 -07:00
Mahmoud Al-Qudsi
0594735714 Deduplication between INTERNAL_FUNCTION and INTERNAL_BLOCK_NODE 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
4dfb334db8 Corrected job_type for external command in debug log 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
384879704a Unified all child/parent forking code in exec_job 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
4a1de248bc Split internal_exec to its own function 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
711c81b8c8 Raised debug level for "Retrying setpgid" message 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
87db424e45 Removed unused <mutex> header include 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
7e23965250 Cleaned up terminal_give_to_job() code flow and comments
No longer using a lambda for pgroupTerminated, using a boolean flag
instead. The new code structure should be much more self-documenting.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
dabe718c52 Removed unused job_t * parameter from setup_child_process 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
628db65504 OS X EINVAL compatibility for waitpid
The return value on OS X is more along the lines of the documented
waitpid behavior; EINVAL is returned if the group no longer exists.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
8e63386203 Removed old/unneeded variants of block_child 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
16d2f4faff Added important comment about blocked_pid 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
15da6f0203 Minor refactoring 2017-08-06 14:40:18 -07:00