Commit Graph

9364 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
8dddc62aeb Optimize ASSERT_IS_NOT_FORKED_CHILD()
Use `pthread_atfork()` to mark child processes as dirty when `fork()` is
invoked rather than needing to call into the kernel each time
`ASSERT_IS_NOT_FORKED_CHILD()` is called.

This makes simple test cases that hit `ASSERT_IS_NOT_FORKED_CHILD()` 1.8x faster.

                        ------------------------

With a7998c4829 reverted but before this optimization:

```
mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     717.8 ms ±  14.9 ms    [User: 503.4 ms, System: 216.2 ms]
  Range (min … max):   692.3 ms … 740.2 ms
```

With a7998c4829 reverted and with this optimization:

```
mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     397.2 ms ±  22.3 ms    [User: 322.1 ms, System: 79.3 ms]
  Range (min … max):   376.0 ms … 444.0 ms
```

Without a7998c4829 reverted and with this optimization:

mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     423.4 ms ±  51.6 ms    [User: 363.2 ms, System: 61.3 ms]
  Range (min … max):   378.4 ms … 541.1 ms
```
2018-12-30 19:55:24 -06:00
Mahmoud Al-Qudsi
840619197e Optimize ASSERT_IS_MAIN_THREAD()
By using a user-land thread-local integer and lock-free (at least under
x86/x64) atomics, we can implement a safe `assert_is_main_thread()`
without calling into the kernel. Thread-local variables are part of
C++11.

This is called a lot in some performance-sensitive areas, so it is worth
optimizing.
2018-12-30 19:25:50 -06:00
Mahmoud Al-Qudsi
259cf02aac Wait on individual processes in a job in reverse order
This fixes #5438 by having fish block while waiting on a foreground job
via its individual processes by enumerating the procs in reverse order,
such that we hang waiting for the last job in the IO chain to terminate,
rather than the first.
2018-12-30 19:02:38 -06:00
Fabian Homborg
b0072482e4 Only warn on exec for background jobs
If it's a foreground job, it is related to the currently running exec.

This fixes exec in functions, i.e.

    function reload
        exec fish
    end

would previously always ask about the "function reload" job.

Fixes #5449.

Fixes oh-my-fish/oh-my-fish#664.
2018-12-30 22:32:07 +01:00
Fabian Homborg
e33d29a5d8 tinyexpr: Reserve arity parameters
This somehow fixes heap-buffer-overflow? I thought this was supposed
to be safe.
2018-12-30 20:34:13 +01:00
Fabian Homborg
2e11e6c692 tinyexpr: Make te_expr a class
Removes some #define weirdness.
2018-12-30 19:34:46 +01:00
Fabian Homborg
b8697e7795 tinyexpr: Rename te_variable to te_builtin
Variables aren't a thing here anymore.
2018-12-30 19:34:46 +01:00
Fabian Homborg
a433868363 tinyexpr: Make parameters te_expr* instead of void* 2018-12-30 19:34:46 +01:00
Fabian Homborg
e504faeb38 tinyexpr: Add Comments 2018-12-30 19:34:46 +01:00
Fabian Homborg
c3c1ae18c6 tinyexpr: C++ify find_builtin 2018-12-30 19:34:45 +01:00
Fabian Homborg
b193df8b42 tinyexpr: Move enums together and stop explicit numbering
We should _not_ be doing bit-fiddling with these, so there's no reason
to care about the number.

This also removes the unused "TE_VARIABLE" symbol.
2018-12-30 19:34:45 +01:00
Fabian Homborg
3bbec871e4 tinyexpr: Free all parameters again
This used implicit fallthrough to free all.

We still iterate back-to-front (i--) because maybe that's important?
2018-12-30 19:34:45 +01:00
Fabian Homborg
4674784a0b Make autotools build use tinyexpr.cpp 2018-12-30 19:34:45 +01:00
Fabian Homborg
26dfca67e5 Fix cmake build
Screwed up a rebase there!
2018-12-30 19:34:45 +01:00
Fabian Homborg
84ca265b48 tinyexpr: Unfiddle the bits
Mainly this removes the "TYPE_MASK" macro that just masks off the
higher bits, which I don't think were ever actually used.

Much of this seems like anticipation of future direction, but we're
going somewhere else.
2018-12-30 19:34:44 +01:00
Fabian Homborg
61e7f84e29 tinyexpr: Remove PURE flag
This was unused because all functions were marked as pure. We don't
have any plans to add any that aren't, and if we did we'd still have
this in git.
2018-12-30 19:34:41 +01:00
Fabian Homborg
cbc25d7829 [tinyexpr] Port to C++
This removes the need to run c-compilation on one file, and allows us
to in future c++-ify this a bit.

There's a lot of bit-fiddling here that is quite unnecessary, better
error-handling would be nice...

So far this removes a few more unused things (because I would have had
to port them), including:

- Functions with ARITY > 3 (even 3 isn't used, but just so we don't
get complacent)

- Variables

- Most functions moved out of the header, because only te_interp is used.

- The te_print function
2018-12-30 19:34:06 +01:00
Fabian Homborg
dabd05f2e3 Remove string fallback function
We already have a fallback here, and upgrading from 2.3.0 to 3.X will be rare.

This costs every shell on every start.

See #5279.
2018-12-30 19:24:03 +01:00
Fabian Homborg
a7998c4829 Don't ASSERT_IS_NOT_FORKED_CHILD so much
This is hammered sooo much that it actually hurts performance.

    for i in (seq 100000); test 1 = 1; end

is about 40% (!) slower with it.
2018-12-30 18:59:41 +01:00
Mahmoud Al-Qudsi
040d921fa1 Fix check for valid disowned pgids
The function `add_disowned_pgid` adds process *group* ids and not
process ids. It multiplies the value by negative 1 to indicate a wait
on a process group, so the original value must be positive.
2018-12-30 10:15:07 -06:00
Fabian Homborg
4a3ac6e91e Don't wait for disowned pgids if they are special
If a job is disowned that, for some reason, has a pgid that is special
to waitpid, like 0 (process with pgid of the calling process), -1 (any
process), or our actual pgid, that would lead to us waiting for too
many processes when we later try to reap the disowned processes (to
stop zombies from appearing).

And that means we'd snag away the processes we actually do want to
wait for, which would end with us in a waiting loop.

This is tough to reproduce, the easiest I've found was

    fish -ic 'sleep 5 &; disown; set -g __fish_git_prompt_showupstream auto; __fish_git_prompt'

in a git repo.

What we do is to not allow special pgids in the disowned_pids list.
That means we might leave a zombie around (though we probably wait on
0 somewhere), but that's preferable to infinitely looping.

See #5426.
2018-12-30 16:04:57 +01:00
David Adam
32e6bf6f64 debian packaging/fish.spec: drop bc dependency 2018-12-29 23:16:09 +08:00
David Adam
8261eb18d2 pcre2: add maintainer mode and disable by default 2018-12-29 22:54:54 +08:00
David Adam
b60a9d8c4a pcre2: move to PCRE2 10.32
Closes #5353.
2018-12-29 22:54:40 +08:00
Fabian Homborg
742fde0dd6 Don't use less in highlighting test
It doesn't have to be installed.

`cat` is in our dependencies, so we can assume it's there.

Fixes #5436.
2018-12-28 17:57:53 +01:00
David Adam
9e4ece8d89 CHANGELOG: next-minor updates, up to 05222a055a
[ci skip]
2018-12-28 22:18:35 +08:00
David Adam
05222a055a Merge branch 'Integration_3.0.0' 2018-12-28 22:10:49 +08:00
David Adam
938ce48d25 Bump version for 3.0.0 2018-12-28 21:01:03 +08:00
David Adam
0c25d7a49c CHANGELOG: 3.0.0 updates 2018-12-28 20:56:17 +08:00
hrvoj3e
69a1c5a3a1 Fix typos in anchor to fish_opt 2018-12-27 14:45:14 +01:00
Mahmoud Al-Qudsi
fb679ac9c3 Add completions for pkg [info|show|list] 2018-12-23 20:06:25 -06:00
David Adam
d6e315d25d cmake: define _GNU_SOURCE
Fixes the build on Cygwin. Analogous to AC_USE_SYSTEM_EXTENSIONS under Autoconf.

Closes #5423.
2018-12-20 21:36:01 +08:00
Fabian Homborg
50fbc36b73 sample_prompts/sorin: Correct git_action function name
We renamed this, and apparently missed it.

[ci skip]
2018-12-19 09:35:26 +01:00
Leonard Hecker
082450b1e7 Severely extended the sorin theme (#5411)
* Severely extended the sorin theme

This theme should now mostly match the original.

* Removed superfluous whitespace

* Inlined external links as ASCII art

* Made myself the author of the sorin theme

* Removed superfluous read delemiter

* Renamed __fish_git_action to fish_print_git_action

* Adde a minor comment
2018-12-18 15:01:38 +01:00
Fabian Homborg
14ee19cc1b Use HAVE_WCSTOD_L also in header 2018-12-18 11:03:33 +01:00
Aaron Gyes
57d6124e6e builtin_test: don't exit 1 for eval errors, add tests for big args
Return STATUS_INVALID_ARGS when failing due to evaluation errors,
so we can tell the difference between an error and falseness.

Add a test for the ERANGE error
2018-12-16 14:51:26 -08:00
Aaron Gyes
cf2b40040a STATUS_INVALID_ARGS = 2
The rest of the high-numbered exit codes are not values used by scripts
or builtins, they are internal to fish and come out of
the parser for example.

Prior to adding STATUS_INVALID_ARGS, builtins were usually exiting 2
if they had a special exit status for the situation of bad arguments.

Set it to 2.
2018-12-16 14:51:18 -08:00
Aaron Gyes
b404b9392c builtin_test.cpp: split a long line, add braces 2018-12-16 14:51:10 -08:00
Aaron Gyes
1f871c4d0c builtin_test.cpp: check for ERANGE and special fish_wcstoll errno
We were not parsing an in-range number when we claimed we were,
and were thus failing to error with invalid numbers and returned
a wrong test result. Fixed #5414

Also, provide the detail we can for the other error cases.
2018-12-16 14:51:02 -08:00
Aaron Gyes
1adcd2d591 builtin_test: don't exit 1 for eval errors, add tests for big args
Return STATUS_INVALID_ARGS when failing due to evaluation errors,
so we can tell the difference between an error and falseness.

Add a test for the ERANGE error
2018-12-15 22:05:19 -08:00
Aaron Gyes
b8113f8e97 STATUS_INVALID_ARGS = 2
The rest of the high-numbered exit codes are not values used by scripts
or builtins, they are internal to fish and come out of
the parser for example.

Prior to adding STATUS_INVALID_ARGS, builtins were usually exiting 2
if they had a special exit status for the situation of bad arguments.

Set it to 2.
2018-12-15 21:05:27 -08:00
Fabian Homborg
e07b45f447 Revert "completions/git: Allow aliases with whitespace in the command"
This reverts commit 081e14fd21, which was bogus.
2018-12-15 11:13:38 +01:00
Mahmoud Al-Qudsi
3855c2217f Remove scripted XDG_CONFIG_HOME uses
Cleaned up the code to no longer replicate in fishscript what fish
already does (and caches to boot) in C++ in setting up the paths to the
user configuration directory.

Also introduced a `$__fish_user_data_dir` instead of the sporadic
definitions of `$userdatadir` that may or may not go through
`XDG_DATA_HOME`.
2018-12-14 22:09:29 -06:00
Aaron Gyes
1634c0fa49 builtin_test.cpp: split a long line, add braces 2018-12-14 12:43:18 -08:00
Aaron Gyes
4aa069a8ff builtin_test.cpp: check for ERANGE and special fish_wcstoll errno
We were not parsing an in-range number when we claimed we were,
and were thus failing to error with invalid numbers and returned
a wrong test result. Fixed #5414

Also, provide the detail we can for the other error cases.
2018-12-14 11:42:23 -08:00
Aaron Gyes
c1be3284c1 __fish_config_interactive: inline combinational logic
Boost readability of this long, logic-heavy script with the new
&& and || syntax added to fish 3.
2018-12-14 05:49:08 -08:00
Aaron Gyes
ba9c387590 __fish_config_interactive: tighten up checks for OSC 7 feature
I spent some time figuring out $TERM_PROGRAM_VERSION and Terminal.app's
capabilities over time. [1]

Only use OSC 7 if running on the version of Terminal.app that added it
or newer. In the past this would have been harder because `test` couldn't
do float comparisons.

cleanup:
Don't bother setting a local $TERM_PROGRAM if it's unset: quoting
is enough to keep test happy. For the version numbers, 0"$var" is safe
against unset variables for numerical comparisons.

[1]: https://github.com/fish-shell/fish-shell/wiki/Terminal.app-characteristics
2018-12-14 05:00:55 -08:00
David Adam
f8338d63ed Merge branch 'Integration_3.0.0'
Post-3.0b1 fixes merge.
2018-12-14 13:09:39 +08:00
David Adam
5959114103 Revert "history.fish: colorize with fish_indent -d0"
This reverts commit 7ebef0a396 in order to
make merging the changes that drop fish_indent easier and history more
understandable.
2018-12-14 13:09:00 +08:00
Fabian Homborg
081e14fd21 completions/git: Allow aliases with whitespace in the command
Fixes #5412.
2018-12-13 22:49:12 +01:00