Commit Graph

93 Commits

Author SHA1 Message Date
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
cef39cdcc0 Add is_windows_subsystem_for_linux to detect WSL 2018-02-07 12:49:11 -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
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
Fabian Homborg
f9d883dd74 Add and use str2wcstring(string, size_t)
This is just for convenience.
2017-12-20 14:31:29 +01: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
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
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
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
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
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
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
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
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
c36ad27618 stop subclassing env_var_t from wcstring
This is the first step to implementing issue #4200 is to stop subclassing
env_var_t from wcstring. Not too surprisingly doing this identified
several places that were incorrectly treating env_var_t and wcstring as
interchangeable types. I'm not talking about those places that passed
an env_var_t instance to a function that takes a wcstring. I'm talking
about doing things like assigning the former to the latter type, relying
on the implicit conversion, and thus losing information.

We also rename `env_get_string()` to `env_get()` for symmetry with
`env_set()` and to make it clear the function does not return a string.
2017-08-06 13:24:34 -07:00
Mahmoud Al-Qudsi
7a18c37b39 Using write_ignore instead of write where the result is not checked
This silences warnings from the compiler about ignoring return value of
‘ssize_t write(int, const void*, size_t)’, declared with attribute
warn_unused_result [-Wunused-result].
2017-07-27 18:07:58 -07:00
Kurtis Rader
a9aa234a64 implement helper functions for fish script vars
This is the first step in implementing a better abstraction for handling
fish script vars in the C++ code. It implements a new function (with two
signatures) to provide a standard method for construct the flag string
representation of a fish script array.

Partial fix for #4200
2017-07-08 13:14:30 -07:00
Fabian Homborg
bb90a4e4a9 Always initalize "success" in unescape_string
gcc warns about this.
2017-07-04 23:52:39 +02:00
Kurtis Rader
f3cb625802 implement string unescape
Fixes #3543
2017-06-23 22:23:01 -07:00
Kurtis Rader
60bca14b37 implement string escape --style=xxx
We need a way to encode arbitrary strings into valid fish variable
names. It would also be nice if we could convert strings to valid URLs
without using the slow and hard to understand `__fish_urlencode` function.
In particular, eliminating the need to manipulate the locale.

Fixes #4150
2017-06-23 22:23:01 -07:00
Alan Somers
652faa1a13 Rename __assert to __fish_assert
FreeBSD and possibly other platforms define __assert in their C
libraries.

Fixes #4133
2017-06-17 22:41:24 -07:00
Kurtis Rader
be2b6bfdc9 fix lint errors that have crept in 2017-05-06 22:08:07 -07:00
Kurtis Rader
275d658616 simplify and clarify valid identifiers
This is the first step in addressing issue #3965. It renames some of the
functions involved in validating variable and function names to clarify
their purpose. It also augments the documentation to make the rules for
such identifiers clearly documented.
2017-04-21 21:55:06 -07:00
Marc Garcia Sastre
8213885491 Capture read command contents without displaying it via a silent flag.
Implement a `read --silent` flag. This echos the input using an
obfuscation character.
2017-04-11 19:06:48 -07:00
Kurtis Rader
03571b82be cleanup env code and contains()
Switch from null terminated arrays to `wcstring_list_t` for lists of
special env var names. Rename `list_contains_string` to `contains` and
modify the latter interface to not rely on a `#define`.

Rename `list_contains_string()` to `contains()` and eliminate the
current variadic implementation. Update all callers of the removed
version to use the string list version.
2017-04-05 17:09:12 -07:00
Kurtis Rader
ae0321778f empty CDPATH elements are equivalent to "."
In the process of fixing the issue I decided it didn't make sense to
have two, incompatible, ways of converting variable strings to arrays.
Especially since the one I'm removing does not return empty array elements.

Fixes #2106
2017-03-22 19:30:42 -07:00
Kurtis Rader
84cf391faa style cleanups 2017-03-15 14:06:58 -07:00
Kurtis Rader
8efe88201e correct escape_string corner case
Fixes #3892
2017-03-13 20:38:57 -07:00
Kurtis Rader
e0f62c178f make not blocking signals the default
This is the next step in determining whether we can disable blocking
signals without a good reason to do so. This makes not blocking signals
the default behavior. If someone finds a problem they can add this to
their ~/config/fish/config.fish file:

set FISH_NO_SIGNAL_BLOCK 0

Alternatively set that env var before starting fish. I won't be surprised
if people report problems. Till now we have relied on people opting in
to this behavior to tell us whether it causes problems. This makes the
experimental behavior the default that has to be opted out of. This will
give us a lot more confidence this change doesn't cause problems before
the next minor release.

Note that there are still a few places where we force blocking of
signals. Primarily to keep SIGTSTP from interfering with the shell in
response to manipulating the controlling tty. Bash is more selective
in the signals it blocks around the problematic syscalls (c.f., its
`git_terminal_to()` function). However, I don't see any value in that
refinement.
2017-03-10 21:34:24 -08:00
Kurtis Rader
4ad5b756e4 more sanity involving fatal errors
This folds the "VOMIT_*" family of macros into the assert and DIE
family.

Another change related to issue #3276.
2017-02-14 21:09:15 -08:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
69731f6642 more IWYU fixes
I'm starting to wonder if IWYU is worth the effort. Nonetheless, this
makes it lint clean on macOS and reduces the number of warnings on
FreeBSD and Linux.
2017-02-12 20:36:37 -08:00
Kurtis Rader
4ffb0adb78 lint cleanups 2017-02-11 21:30:38 -08:00
Kurtis Rader
0a929f7a0b don't export COLUMNS/LINES unless already exported
Fixes #3839
2017-02-10 15:20:09 -08:00
ridiculousfish
0fefdb458f Revert "Adopt owning_lock and some cleanup of termsize storage in common.cpp"
Tests are failing on Travis but not locally

This reverts commit c5d9e7e391.
2017-01-29 19:33:30 -08:00
ridiculousfish
c5d9e7e391 Adopt owning_lock and some cleanup of termsize storage in common.cpp 2017-01-29 18:15:38 -08:00
ridiculousfish
e78cefd759 Defeat "enumeral mismatch" g++ warnings through typecasting 2017-01-26 17:18:38 -08:00
ridiculousfish
1efb81456b Use std::move instead of swap in a few places where it improves clarity 2017-01-26 16:14:50 -08:00
Kurtis Rader
2be1288cac handling when stty reports zero for termsize
If the kernel reports a size of zero for the rows or columns (i.e., what
`stty -a` reports) fall back to the `COLUMNS` and `LINES` variables. If
the resulting values are not reasonable fallback to using 80x24.

Fixes #3740
2017-01-20 15:34:29 -08:00
Kurtis Rader
fd6d814ea4 remove unnecessary signal management
The shell was doing a log of signal blocking/unblocking that hurts
performance and can be avoided. This reduced the elapsed time for a
simple benchmark by 25%.

Partial fix for #2007
2017-01-14 20:51:54 -08:00
Kurtis Rader
56e05dab02 another attempt to workaround a glibc bug
This is another attempt to fix issue #3644 that we believe is due to issue
https://sourceware.org/bugzilla/show_bug.cgi?id=20632.
2017-01-13 21:18:34 -08:00
Kurtis Rader
2e9a349dd0 normalize use of stdio functions taking a stream
We should never use stdio functions that use stdout implicitly. Saving a
few characters isn't worth the inconsistency. Too, using the forms such
as `fwprintf()` which take an explicit stream makes it easier to find
the places we write to stdout versus stderr.

Fixes #3728
2017-01-13 20:48:55 -08:00
Fabian Homborg
177e06808c Replace all printf invocations with wprintf
Remember, GNU doesn't allow mixing narrow and wide IO.
2017-01-07 14:05:42 +01:00
Kurtis Rader
6f8775499f don't warn about EPIPE errors
Emitting warnings about EPIPE errors when writing to stdout or stderr is
more annoying than helpful. So suppress that specific warning message.

Fixes #2516
2017-01-06 23:59:06 -08:00
Kurtis Rader
b118ed69d3 convert narrow stderr output to wide forms
On some platforms, notably GNU libc, you cannot mix narrow and wide
stdio functions on a stream like stdout or stderr. Doing so will drop
the output of one or the other. This change makes all output to the
stderr stream consistently use the wide forms.

This change also converts some fprintf(stderr,...) calls to debug()
calls where appropriate.

Fixes #3692
2017-01-03 16:14:42 -08:00
Kurtis Rader
7c40abe4a6 switch from \1xb to \e in the code
Using `\e` is clearer and shorter than `\x1b`. It's also consistent with how
we write related control chars; e.g., we don't write `\x0a` we write '\n'.
2016-12-24 12:15:28 -08:00