Commit Graph

37 Commits

Author SHA1 Message Date
ridiculousfish
5899694233 Allow setting universal path variables
Support for path and unpath in universal variables.
Fixes #5271
2018-10-27 01:05:00 -07:00
ridiculousfish
7b5296817a Teach universal variables to not overwrite future file formats 2018-10-26 16:06:50 -07:00
ridiculousfish
adc69f94da Support parsing the new universal variable format 2018-10-26 16:06:50 -07:00
ridiculousfish
d98874bd08 Improve testability factoring of env_universal_t 2018-10-26 16:06:47 -07:00
ridiculousfish
11d523e61a Build out support for multiple file formats in uvars
This is in preparation for adjusting the file format to support path
variables.
2018-10-21 15:56:05 -07:00
ridiculousfish
a23894ca37 Simplify callback_data_t
SET_EXPORT no longer makes sense; remove it.
2018-10-21 15:56:05 -07:00
Mahmoud Al-Qudsi
e045b045da Move get_runtime_path() to env.cpp and expose it in env.h
It was previously a file-local static function in env_universal.cpp.
2018-09-28 11:33:11 -05:00
Jon Eyolfson
c3ca108dbe Added const to methods which 'ought to be const' based on Const Checker 2018-08-09 19:05:47 -07:00
ridiculousfish
ff10e504a1 Remove MAC address from universal variables file
This switches the universal variables file from a machine-specific
name to the fixed '.config/fish/fish_universal_variables'. The old file
name is migrated if necessary.

Fixes #1912
2018-04-01 17:43:12 -07:00
Mahmoud Al-Qudsi
a756049dac Implement $hostname variable
The value is not electrified or tied and is read-only. It isn't cached
in the get_hostname_identifier() function as the ENV_GLOBAL $hostname
will cache it for its duration.
2018-03-09 15:02:32 -06: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
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
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
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
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
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
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
Kurtis Rader
8f548962b7 fix regression how fish_escape_delay_ms is handled
Fish 2.6.0 introduced a regression that keeps setting
`fish_escape_delay_ms` as a uvar from working. This also fixes a related
problem: callbacks generated from the initial loading of universal vars
were not being acted on.

Fixes #4196
2017-07-19 19:09:55 -07: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
5b6cc5af6d time for another make style-all
Gotta keep the entropy (i.e., disorder) from increasing.
2017-01-26 20:05:46 -08:00
ridiculousfish
6f745762bb Make universal_notifier_t use unique_ptr instead of raw pointers 2017-01-21 16:56:45 -08:00
Kurtis Rader
574424dc5a fix uvar tests
I noticed that universal variable tests were failing on Cygwin and
Dragonfly BSD. The failures were because we are attempting to verify the
correct behavior of mechanisms that are known to be broken on those
platforms. There are still uvar test failures on those platforms with
this change but they are due to actual problems rather than bugs in the
tests.

Fixes #3587
2016-12-25 21:17:27 -08:00
Kurtis Rader
eaa3741336 improve error msg about invalid HOME/XDG_* var
This change increases the amount of useful information when fish is
unable to create or use its config or data directory. We now make it
clear when neither var is set or one is set to an unusable location.

Fixes #3545
2016-12-01 20:40:25 -08:00
Fredrik Fornwall
df12ac24b2 Fix build on systems without shm_open()
Notably, this fixes building on Android.
2016-11-26 16:14:15 -05:00
Aaron Gyes
fa78a7101c Make IWYU output in lint.cpp less messy
And re-run IWYU, adjust #includes.
2016-06-23 17:26:08 -07:00
Kurtis Rader
690ceeeaa7 restyle env_universal module to match project style
Reduces lint errors from 121 to 52 (-57%). Line count from 1916 to 1671 (-13%).

Another step in resolving issue #2902.
2016-04-28 19:17:28 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
Kurtis Rader
411d573ba9 convert atypical env_universal_common logging
This is a quick and dirty conversion of the atypical, and undocumented,
logging done by env_universal_common.cpp to the usual `debug()` pattern. I
didn't want to drop the messages because they could be useful when
debugging future issues. So I simply converted them to the lowest debug
level using the normal debug() function.

Fixes #2887
2016-04-03 20:23:43 -07:00
ridiculousfish
10f3ea0008 Mark a bunch of constructors as explicit
This prevents undesired implicit conversions
2016-02-27 19:38:15 -08:00
ridiculousfish
45dfa2d864 Attempt to fix the sporadic uvar test failures on Linux
We identify when the universal variable file has changed out from under us by
comparing a bunch of fields from its stat: inode, device, size, high-precision
timestamp, generation. Linux aggressively reuses inodes, and the size may be
the same by coincidence (which is the case in the tests). Also, Linux
officially has nanosecond precision, but in practice it seems to only uses
millisecond precision for storing mtimes. Thus if there are three or more
updates within a millisecond, every field we check may be the same, and we are
vulnerable to the ABA problem. I believe this explains the occasional test
failures.

The solution is to manually set the nanosecond field of the mtime timestamp to
something unlikely to be duplicated, like a random number, or better yet, the
current time (with nanosecond precision). This is more in the spirit of the
timestamp, and it means we're around a million times less likely to collide.
This seems to fix the tests.
2015-11-08 23:48:32 -08:00
ridiculousfish
871a822379 Remove some dead #defines 2015-08-11 01:00:05 -07:00
David Adam
3929e9de0e Merge branch 'master' into iwyu 2015-07-26 10:20:13 +08:00
ridiculousfish
b4f53143b0 Migrate source files into src/ directory
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.

Fixes #1866
2015-07-24 00:59:27 -07:00