diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 608328717..fe6cbd63b 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -113,7 +113,7 @@ function __fish_config_interactive -d "Initializations that should be performed # Generating completions from man pages needs python (see issue #3588). # Don't do this if we're being invoked as part of running unit tests. if command -qs python - and not set -q FISH_UNIT_TESTS_RUNNING + and not set -q FISH_UNIT_TESTS_RUNNING # We cannot simply do `fish_update_completions &` because it is a function. Hence the # need for the convoluted `eval` to run it in a subshell. eval (string escape "$__fish_bin_dir/fish") "-c 'fish_update_completions >/dev/null ^/dev/null' &" diff --git a/src/autoload.cpp b/src/autoload.cpp index 0b25b6f4d..e63997863 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -48,9 +48,7 @@ file_access_attempt_t access_file(const wcstring &path, int mode) { autoload_t::autoload_t(const wcstring &env_var_name_var, command_removed_function_t cmd_removed_callback) - : lock(), - env_var_name(env_var_name_var), - command_removed(cmd_removed_callback) { + : lock(), env_var_name(env_var_name_var), command_removed(cmd_removed_callback) { pthread_mutex_init(&lock, NULL); } diff --git a/src/autoload.h b/src/autoload.h index 15ab14f27..7a661b4b4 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -73,8 +73,7 @@ class autoload_t : public lru_cache_t { void entry_was_evicted(wcstring key, autoload_function_t node); // Create an autoload_t for the given environment variable name. - autoload_t(const wcstring &env_var_name_var, - command_removed_function_t callback); + autoload_t(const wcstring &env_var_name_var, command_removed_function_t callback); ~autoload_t(); diff --git a/src/common.h b/src/common.h index 34edc3079..964b350c8 100644 --- a/src/common.h +++ b/src/common.h @@ -545,7 +545,7 @@ class scoped_lock { // No copying. scoped_lock &operator=(const scoped_lock &) = delete; - scoped_lock(const scoped_lock &) = delete; + scoped_lock(const scoped_lock &) = delete; public: scoped_lock(scoped_lock &&rhs) : lock_obj(rhs.lock_obj), locked(rhs.locked) { @@ -569,7 +569,7 @@ class rwlock_t { ~rwlock_t() { VOMIT_ON_FAILURE_NO_ERRNO(pthread_rwlock_destroy(&rwlock)); } rwlock_t &operator=(const rwlock_t &) = delete; - rwlock_t(const rwlock_t &) = delete; + rwlock_t(const rwlock_t &) = delete; }; // Scoped lock class for rwlocks. @@ -604,16 +604,15 @@ class scoped_rwlock { // Or for simple cases: // name.acquire().value = "derp" // -template +template class acquired_lock { scoped_lock lock; - acquired_lock(mutex_lock_t &lk, DATA *v) : lock(lk), value(*v) - {} + acquired_lock(mutex_lock_t &lk, DATA *v) : lock(lk), value(*v) {} - template + template friend class owning_lock; - public: + public: // No copying, move only acquired_lock &operator=(const acquired_lock &) = delete; acquired_lock(const acquired_lock &) = delete; @@ -625,7 +624,7 @@ class acquired_lock { // A lock that owns a piece of data // Access to the data is only provided by taking the lock -template +template class owning_lock { // No copying owning_lock &operator=(const scoped_lock &) = delete; @@ -636,13 +635,11 @@ class owning_lock { mutex_lock_t lock; DATA data; -public: + public: owning_lock(DATA d) : data(std::move(d)) {} owning_lock() : data() {} - acquired_lock acquire() { - return {lock, &data}; - } + acquired_lock acquire() { return {lock, &data}; } }; /// A scoped manager to save the current value of some variable, and optionally set it to a new diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 2a179e233..c1a350a63 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1180,9 +1180,7 @@ static void test_lru(void) { // Stable-sort ints in reverse order // This a/2 check ensures that some different ints compare the same // It also gives us a different order than we started with - auto comparer = [](int a, int b){ - return a/2 > b/2; - }; + auto comparer = [](int a, int b) { return a / 2 > b / 2; }; std::vector ints = cache.ints(); std::stable_sort(ints.begin(), ints.end(), comparer); @@ -1194,13 +1192,13 @@ static void test_lru(void) { for (int v : vs) { append_format(ret, L"%d,", v); } - if (! ret.empty()) ret.pop_back(); + if (!ret.empty()) ret.pop_back(); return ret; }; - err(L"LRU stable sort failed. Expected %ls, got %ls\n", commajoin(new_ints).c_str(), commajoin(ints).c_str()); + err(L"LRU stable sort failed. Expected %ls, got %ls\n", commajoin(new_ints).c_str(), + commajoin(ints).c_str()); } - cache.evict_all_nodes(); do_test(cache.evicted.size() == size_t(total_nodes)); } @@ -2900,7 +2898,7 @@ void history_tests_t::test_history_races(void) { // History is enumerated from most recent to least // Every item should be the last item in some array size_t hist_idx; - for (hist_idx = 1; ; hist_idx++) { + for (hist_idx = 1;; hist_idx++) { history_item_t item = hist.item_at_index(hist_idx); if (item.empty()) break; @@ -2921,14 +2919,13 @@ void history_tests_t::test_history_races(void) { break; } } - if (! found) { + if (!found) { err(L"Line '%ls' found in history, but not found in some array", item.str().c_str()); for (wcstring_list_t &list : expected_lines) { - if (! list.empty()) { + if (!list.empty()) { fprintf(stderr, "\tRemaining: %ls\n", list.back().c_str()); } } - } } diff --git a/src/history.cpp b/src/history.cpp index 66ab93a6a..780bc2841 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -88,7 +88,7 @@ class history_output_buffer_t { buffer.reserve(buffer.size() + additional_length); // Append - for (size_t i=0; i < ptr_count; i++) { + for (size_t i = 0; i < ptr_count; i++) { if (lengths[i] > 0) { buffer.insert(buffer.end(), ptrs[i], ptrs[i] + lengths[i]); } @@ -189,7 +189,7 @@ class history_lru_cache_t : public lru_cache_t>> histories; - public: + public: history_t &get_creating(const wcstring &name); void save(); }; @@ -704,7 +704,7 @@ history_t &history_collection_t::get_creating(const wcstring &name) { // using something like shared_ptr auto hs = histories.acquire(); std::unique_ptr &hist = hs.value[name]; - if (! hist) { + if (!hist) { hist = make_unique(name); } return *hist; @@ -1203,15 +1203,14 @@ bool history_t::rewrite_to_temporary_file(int existing_fd, int dst_fd) const { infer_file_type(local_mmap_start, local_mmap_size); size_t cursor = 0; for (;;) { - size_t offset = offset_of_next_item(local_mmap_start, local_mmap_size, - local_mmap_type, &cursor, 0); + size_t offset = + offset_of_next_item(local_mmap_start, local_mmap_size, local_mmap_type, &cursor, 0); // If we get back -1, we're done. if (offset == (size_t)-1) break; // Try decoding an old item. - const history_item_t old_item = decode_item(local_mmap_start + offset, - local_mmap_size - offset, - local_mmap_type); + const history_item_t old_item = + decode_item(local_mmap_start + offset, local_mmap_size - offset, local_mmap_type); if (old_item.empty() || deleted_items.count(old_item.str()) > 0) { // debug(0, L"Item is deleted : %s\n", old_item.str().c_str()); @@ -1225,15 +1224,14 @@ bool history_t::rewrite_to_temporary_file(int existing_fd, int dst_fd) const { // Insert any unwritten new items for (auto iter = new_items.cbegin() + this->first_unwritten_new_item_index; - iter != new_items.cend(); - ++iter) { + iter != new_items.cend(); ++iter) { lru.add_item(*iter); } // Stable-sort our items by timestamp // This is because we may have read "old" items with a later timestamp than our "new" items // This is the essential step that roughly orders items by history - lru.stable_sort([](const history_lru_item_t &item1, const history_lru_item_t &item2){ + lru.stable_sort([](const history_lru_item_t &item1, const history_lru_item_t &item2) { return item1.timestamp < item2.timestamp; }); @@ -1245,7 +1243,7 @@ bool history_t::rewrite_to_temporary_file(int existing_fd, int dst_fd) const { append_yaml_to_buffer(item.text, item.timestamp, item.required_paths, &buffer); if (buffer.output_size() >= HISTORY_OUTPUT_BUFFER_SIZE) { ok = buffer.flush_to_fd(dst_fd); - if (! ok) { + if (!ok) { debug(2, L"Error %d when writing to temporary history file", errno); break; } @@ -1254,7 +1252,7 @@ bool history_t::rewrite_to_temporary_file(int existing_fd, int dst_fd) const { if (ok) { ok = buffer.flush_to_fd(dst_fd); - if (! ok) { + if (!ok) { debug(2, L"Error %d when writing to temporary history file", errno); } } @@ -1298,15 +1296,15 @@ bool history_t::save_internal_via_rewrite() { } bool done = false; - for (int i=0; i < max_save_tries && ! done; i++) { + for (int i = 0; i < max_save_tries && !done; i++) { // Open any target file, but do not lock it right away int target_fd_before = wopen_cloexec(target_name, O_RDONLY | O_CREAT, history_file_mode); - file_id_t orig_file_id = file_id_for_fd(target_fd_before); // possibly invalid + file_id_t orig_file_id = file_id_for_fd(target_fd_before); // possibly invalid bool wrote = this->rewrite_to_temporary_file(target_fd_before, tmp_fd); if (target_fd_before >= 0) { close(target_fd_before); } - if (! wrote) { + if (!wrote) { // Failed to write, no good break; } @@ -1325,14 +1323,13 @@ bool history_t::save_internal_via_rewrite() { new_file_id = file_id_for_path(target_name); } bool can_replace_file = (new_file_id == orig_file_id || new_file_id == kInvalidFileID); - if (! can_replace_file) { + if (!can_replace_file) { // The file has changed, so we're going to re-read it // Truncate our tmp_fd so we can reuse it if (ftruncate(tmp_fd, 0) == -1 || lseek(tmp_fd, 0, SEEK_SET) == -1) { debug(2, L"Error %d when truncating temporary history file", errno); } - } - else { + } else { // The file is unchanged, or the new file doesn't exist or we can't read it // We also attempted to take the lock, so we feel confident in replacing it @@ -1404,11 +1401,12 @@ bool history_t::save_internal_via_appending() { signal_block(); // We are going to open the file, lock it, append to it, and then close it - // After locking it, we need to stat the file at the path; if there is a new file there, it means + // After locking it, we need to stat the file at the path; if there is a new file there, it + // means // the file was replaced and we have to try again // Limit our max tries so we don't do this forever int history_fd = -1; - for (int i=0; i < max_save_tries; i++) { + for (int i = 0; i < max_save_tries; i++) { int fd = wopen_cloexec(history_path, O_WRONLY | O_APPEND); if (fd < 0) { // can't open, we're hosed @@ -1479,8 +1477,10 @@ bool history_t::save_internal_via_appending() { } // Since we just modified the file, update our mmap_file_id to match its current state - // Otherwise we'll think the file has been changed by someone else the next time we go to write - // We don't update the mapping since we only appended to the file, and everything we appended + // Otherwise we'll think the file has been changed by someone else the next time we go to + // write + // We don't update the mapping since we only appended to the file, and everything we + // appended // remains in our new_items this->mmap_file_id = file_id_for_fd(history_fd); diff --git a/src/history.h b/src/history.h index eb8506536..c64625eed 100644 --- a/src/history.h +++ b/src/history.h @@ -196,8 +196,8 @@ class history_t { // Do a private, read-only map of the entirety of a history file with the given name. Returns // true if successful. Returns the mapped memory region by reference. - bool map_file(const wcstring &name, const char **out_map_start, - size_t *out_map_len, file_id_t *file_id) const; + bool map_file(const wcstring &name, const char **out_map_start, size_t *out_map_len, + file_id_t *file_id) const; // Like map_file but takes a file descriptor bool map_fd(int fd, const char **out_map_start, size_t *out_map_len) const; diff --git a/src/input.cpp b/src/input.cpp index 75fb91a36..17b5c6dcc 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -56,8 +56,8 @@ struct input_mapping_t { /// New mode that should be switched to after command evaluation. wcstring sets_mode; - input_mapping_t(const wcstring &s, const std::vector &c, - const wcstring &m, const wcstring &sm) + input_mapping_t(const wcstring &s, const std::vector &c, const wcstring &m, + const wcstring &sm) : seq(s), commands(c), mode(m), sets_mode(sm) { static unsigned int s_last_input_map_spec_order = 0; specification_order = ++s_last_input_map_spec_order; @@ -221,7 +221,7 @@ wcstring input_get_bind_mode() { void input_set_bind_mode(const wcstring &bm) { // Only set this if it differs to not execute variable handlers all the time. // modes may not be empty - empty is a sentinel value meaning to not change the mode - assert(! bm.empty()); + assert(!bm.empty()); if (input_get_bind_mode() != bm.c_str()) { env_set(FISH_BIND_MODE_VAR, bm.c_str(), ENV_GLOBAL); } diff --git a/src/intern.cpp b/src/intern.cpp index 1f83b2f82..bd1f60124 100644 --- a/src/intern.cpp +++ b/src/intern.cpp @@ -12,9 +12,7 @@ #include "fallback.h" // IWYU pragma: keep #include "intern.h" -bool string_less_than_string(const wchar_t *a, const wchar_t *b) { - return wcscmp(a, b) < 0; -} +bool string_less_than_string(const wchar_t *a, const wchar_t *b) { return wcscmp(a, b) < 0; } /// The table of intern'd strings. owning_lock> string_table; @@ -27,8 +25,8 @@ static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) { std::vector &string_table = lock_string_table.value; const wchar_t *result; - auto iter = std::lower_bound(string_table.begin(), string_table.end(), - in, string_less_than_string); + auto iter = + std::lower_bound(string_table.begin(), string_table.end(), in, string_less_than_string); if (iter != string_table.end() && wcscmp(*iter, in) == 0) { result = *iter; } else { diff --git a/src/lru.h b/src/lru.h index 4dcc1f314..d7632cec8 100644 --- a/src/lru.h +++ b/src/lru.h @@ -118,19 +118,18 @@ class lru_cache_t { // and a binary func F implementing less-than, return // the list in sorted order template - static lru_link_t *merge(lru_link_t *left, size_t left_len, - lru_link_t *right, size_t right_len, + static lru_link_t *merge(lru_link_t *left, size_t left_len, lru_link_t *right, size_t right_len, const F &func) { assert(left_len > 0 && right_len > 0); - auto popleft = [&](){ + auto popleft = [&]() { lru_link_t *ret = left; left = left->next; left_len--; return ret; }; - auto popright = [&](){ + auto popright = [&]() { lru_link_t *ret = right; right = right->next; right_len--; @@ -140,8 +139,8 @@ class lru_cache_t { lru_link_t *head; lru_link_t **cursor = &head; while (left_len && right_len) { - bool goleft = ! func(static_cast(left)->value, - static_cast(right)->value); + bool goleft = !func(static_cast(left)->value, + static_cast(right)->value); *cursor = goleft ? popleft() : popright(); cursor = &(*cursor)->next; } @@ -154,7 +153,7 @@ class lru_cache_t { // mergesort the given list of the given length // This only sets the next pointers, not the prev ones - template + template static lru_link_t *mergesort(lru_link_t *node, size_t length, const F &func) { if (length <= 1) { return node; @@ -165,7 +164,7 @@ class lru_cache_t { lru_link_t *left = node; lru_link_t *right = node; - for (size_t i=0; i < left_len; i++) { + for (size_t i = 0; i < left_len; i++) { right = right->next; } @@ -178,9 +177,7 @@ class lru_cache_t { } public: - - // Constructor - // Note our linked list is always circular! + // Constructor. Note our linked list is always circular. explicit lru_cache_t(size_t max_size = 1024) : max_node_count(max_size) { mouth.next = mouth.prev = &mouth; } @@ -242,13 +239,11 @@ class lru_cache_t { } // Number of entries - size_t size() const { - return this->node_map.size(); - } + size_t size() const { return this->node_map.size(); } - // Sorting support - // Given a binary function F implementing less-than on the contents, place the nodes in sorted order - template + // Given a binary function F implementing less-than on the contents, place the nodes in sorted + // order. + template void stable_sort(const F &func) { // Perform the sort. This sets forward pointers only size_t length = this->size(); @@ -261,7 +256,7 @@ class lru_cache_t { // Go through and set back back pointers lru_link_t *cursor = sorted; lru_link_t *prev = &mouth; - for (size_t i=0; i < length; i++) { + for (size_t i = 0; i < length; i++) { cursor->prev = prev; prev = cursor; cursor = cursor->next; diff --git a/src/screen.cpp b/src/screen.cpp index db4a0f5ef..3bccc2411 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -236,15 +236,14 @@ static bool is_color_escape_seq(const wchar_t *code, size_t *resulting_length) { /// displayed other than the color. static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length) { if (!cur_term) return false; - char *const esc2[] = {enter_bold_mode, exit_attribute_mode, enter_underline_mode, - exit_underline_mode, enter_standout_mode, exit_standout_mode, - flash_screen, enter_subscript_mode, exit_subscript_mode, - enter_superscript_mode, exit_superscript_mode, enter_blink_mode, - enter_italics_mode, exit_italics_mode, enter_reverse_mode, - enter_shadow_mode, exit_shadow_mode, enter_standout_mode, - exit_standout_mode, enter_secure_mode, enter_dim_mode, - enter_blink_mode, enter_protected_mode, enter_alt_charset_mode, - exit_alt_charset_mode}; + char *const esc2[] = { + enter_bold_mode, exit_attribute_mode, enter_underline_mode, exit_underline_mode, + enter_standout_mode, exit_standout_mode, flash_screen, enter_subscript_mode, + exit_subscript_mode, enter_superscript_mode, exit_superscript_mode, enter_blink_mode, + enter_italics_mode, exit_italics_mode, enter_reverse_mode, enter_shadow_mode, + exit_shadow_mode, enter_standout_mode, exit_standout_mode, enter_secure_mode, + enter_dim_mode, enter_blink_mode, enter_protected_mode, enter_alt_charset_mode, + exit_alt_charset_mode}; for (size_t p = 0; p < sizeof esc2 / sizeof *esc2; p++) { if (!esc2[p]) continue;