diff --git a/share/config.fish b/share/config.fish index a5db25a3b..cb153bbe3 100644 --- a/share/config.fish +++ b/share/config.fish @@ -160,8 +160,11 @@ if set -q MANPATH end set __fish_tmp_manpath $__fish_tmp_manpath[-1..1] end - test -r /etc/manpaths ; and __fish_load_manpath_helper_manpaths < /etc/manpaths - for manpathfile in /etc/manpaths.d/* ; __fish_load_manpath_helper_manpaths < $manpathfile ; end + test -r /etc/manpaths + and __fish_load_manpath_helper_manpaths parse_binary_primary(unsigned int start, unsigned int end); unique_ptr parse_just_a_string(unsigned int start, unsigned int end); - static unique_ptr parse_args(const wcstring_list_t &args, - wcstring &err, + static unique_ptr parse_args(const wcstring_list_t &args, wcstring &err, wchar_t *program_name); }; @@ -280,7 +279,8 @@ unique_ptr test_parser::parse_unary_expression(unsigned int start, u if (tok == test_bang) { unique_ptr subject(parse_unary_expression(start + 1, end)); if (subject.get()) { - return make_unique(tok, range_t(start, subject->range.end), move(subject)); + return make_unique(tok, range_t(start, subject->range.end), + move(subject)); } return NULL; } @@ -288,7 +288,8 @@ unique_ptr test_parser::parse_unary_expression(unsigned int start, u } /// Parse a combining expression (AND, OR). -unique_ptr test_parser::parse_combining_expression(unsigned int start, unsigned int end) { +unique_ptr test_parser::parse_combining_expression(unsigned int start, + unsigned int end) { if (start >= end) return NULL; std::vector> subjects; @@ -333,7 +334,8 @@ unique_ptr test_parser::parse_combining_expression(unsigned int star } // Our new expression takes ownership of all expressions we created. The token we pass is // irrelevant. - return make_unique(test_combine_and, range_t(start, idx), move(subjects), move(combiners)); + return make_unique(test_combine_and, range_t(start, idx), move(subjects), + move(combiners)); } unique_ptr test_parser::parse_unary_primary(unsigned int start, unsigned int end) { @@ -383,7 +385,8 @@ unique_ptr test_parser::parse_binary_primary(unsigned int start, uns const token_info_t *info = token_for_string(arg(start + 1)); if (!(info->flags & BINARY_PRIMARY)) return NULL; - return make_unique(info->tok, range_t(start, start + 3), arg(start), arg(start + 2)); + return make_unique(info->tok, range_t(start, start + 3), arg(start), + arg(start + 2)); } unique_ptr test_parser::parse_parenthentical(unsigned int start, unsigned int end) { @@ -410,7 +413,8 @@ unique_ptr test_parser::parse_parenthentical(unsigned int start, uns } // Success. - return make_unique(test_paren_open, range_t(start, close_index + 1), move(subexpr)); + return make_unique(test_paren_open, range_t(start, close_index + 1), + move(subexpr)); } unique_ptr test_parser::parse_primary(unsigned int start, unsigned int end) { @@ -444,8 +448,7 @@ unique_ptr test_parser::parse_3_arg_expression(unsigned int start, u subjects.push_back(move(left)); subjects.push_back(move(right)); result = make_unique(center_token->tok, range_t(start, end), - move(subjects), - move(combiners)); + move(subjects), move(combiners)); } } else { result = parse_unary_expression(start, end); @@ -461,7 +464,8 @@ unique_ptr test_parser::parse_4_arg_expression(unsigned int start, u if (first_token == test_bang) { unique_ptr subject(parse_3_arg_expression(start + 1, end)); if (subject.get()) { - result = make_unique(first_token, range_t(start, subject->range.end), move(subject)); + result = make_unique(first_token, range_t(start, subject->range.end), + move(subject)); } } else if (first_token == test_paren_open) { result = parse_parenthentical(start, end); @@ -499,7 +503,7 @@ unique_ptr test_parser::parse_expression(unsigned int start, unsigne } unique_ptr test_parser::parse_args(const wcstring_list_t &args, wcstring &err, - wchar_t *program_name) { + wchar_t *program_name) { // Empty list and one-arg list should be handled by caller. assert(args.size() > 1); diff --git a/src/color.h b/src/color.h index 99ae035fd..592fdc30b 100644 --- a/src/color.h +++ b/src/color.h @@ -19,7 +19,13 @@ class rgb_color_t { unsigned char type : 4; // Flags - enum { flag_bold = 1 << 0, flag_underline = 1 << 1, flag_italics = 1 << 2, flag_dim = 1 << 3, flag_reverse = 1 << 4 }; + enum { + flag_bold = 1 << 0, + flag_underline = 1 << 1, + flag_italics = 1 << 2, + flag_dim = 1 << 3, + flag_reverse = 1 << 4 + }; unsigned char flags : 5; union { diff --git a/src/common.h b/src/common.h index 38ddfc0cb..da91aa189 100644 --- a/src/common.h +++ b/src/common.h @@ -640,8 +640,8 @@ void append_formatv(wcstring &str, const wchar_t *format, va_list ap); using std::make_unique; #else /// make_unique implementation -template -std::unique_ptr make_unique(Args&&... args) { +template +std::unique_ptr make_unique(Args &&... args) { return std::unique_ptr(new T(std::forward(args)...)); } #endif @@ -683,7 +683,6 @@ ssize_t write_loop(int fd, const char *buff, size_t count); /// error. ssize_t read_loop(int fd, void *buff, size_t count); - /// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc. /// /// \param in The string to be escaped diff --git a/src/complete.cpp b/src/complete.cpp index bb17b0310..3e5ccc7bb 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -673,8 +673,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool // updated with choices for the user. expand_error_t ignore = expand_string(str_cmd, &this->completions, - EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), - NULL); + EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), NULL); USE(ignore); } @@ -864,9 +863,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop } else if (this->type() == COMPLETE_AUTOSUGGEST && !completion_autoloader.has_tried_loading(cmd)) { // Load this command (on the main thread) - iothread_perform_on_main([&](){ - complete_load(cmd, false); - }); + iothread_perform_on_main([&]() { complete_load(cmd, false); }); } // Make a list of lists of all options that we care about. @@ -1454,7 +1451,8 @@ void complete(const wcstring &cmd_with_subcmds, std::vector *out_c wcstring faux_cmdline = cmd; faux_cmdline.replace(cmd_node->source_start, cmd_node->source_length, wrap_chain.at(i)); - transient_cmd = make_unique(faux_cmdline); + transient_cmd = make_unique( + faux_cmdline); } if (!completer.complete_param(wrap_chain.at(i), previous_argument_unescape, diff --git a/src/env.cpp b/src/env.cpp index c0633fbe7..8a98355d1 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -76,8 +76,7 @@ class env_node_t { friend struct var_stack_t; env_node_t(bool is_new_scope) : new_scope(is_new_scope) {} -public: - + public: /// Variable table. var_table_t env; /// Does this node imply a new variable scope? If yes, all non-global variables below this one @@ -122,9 +121,7 @@ struct var_stack_t { void mark_changed_exported() { has_changed_exported = true; } void update_export_array_if_necessary(); - var_stack_t() : top(new env_node_t(false)) { - this->global_env = this->top.get(); - } + var_stack_t() : top(new env_node_t(false)) { this->global_env = this->top.get(); } // Pushes a new node onto our stack // Optionally creates a new scope for the node @@ -177,9 +174,9 @@ void var_stack_t::pop() { } } - // Actually do the pop! - // Move the top pointer into a local variable, then replace the top pointer with the next pointer - // afterwards we should have a node with no next pointer, and our top should be non-null + // Actually do the pop! Move the top pointer into a local variable, then replace the top pointer + // with the next pointer afterwards we should have a node with no next pointer, and our top + // should be non-null. std::unique_ptr old_top = std::move(this->top); this->top = std::move(old_top->next); old_top->next.reset(); @@ -194,7 +191,7 @@ void var_stack_t::pop() { break; } } - // TODO: move this to something general + // TODO: Move this to something general. if (locale_changed) handle_locale(locale_changed); } @@ -348,9 +345,7 @@ static bool var_is_curses(const wcstring &key) { static bool can_set_term_title = false; /// Returns true if we think the terminal supports setting its title. -bool term_supports_setting_title() { - return can_set_term_title; -} +bool term_supports_setting_title() { return can_set_term_title; } /// This is a pretty lame heuristic for detecting terminals that do not support setting the /// title. If we recognise the terminal name as that of a virtual terminal, we assume it supports @@ -381,9 +376,7 @@ static bool does_term_support_setting_title() { } /// Handle changes to the TERM env var that do not involves the curses subsystem. -static void handle_term() { - can_set_term_title = does_term_support_setting_title(); -} +static void handle_term() { can_set_term_title = does_term_support_setting_title(); } /// Push all curses/terminfo env vars into the global environment where they can be found by those /// libraries. @@ -1039,13 +1032,9 @@ static bool local_scope_exports(const env_node_t *n) { return local_scope_exports(n->next.get()); } -void env_push(bool new_scope) { - vars_stack().push(new_scope); -} +void env_push(bool new_scope) { vars_stack().push(new_scope); } -void env_pop() { - vars_stack().pop(); -} +void env_pop() { vars_stack().pop(); } /// Function used with to insert keys of one table into a set::set. static void add_key_to_string_set(const var_table_t &envs, std::set *str_set, @@ -1161,7 +1150,7 @@ static void export_func(const std::map &envs, std::vectorhas_changed_exported) { + if (!this->has_changed_exported) { return; } std::map vals; diff --git a/src/env.h b/src/env.h index 8cdbd4408..74590f1c2 100644 --- a/src/env.h +++ b/src/env.h @@ -153,7 +153,7 @@ class env_vars_snapshot_t { std::map vars; bool is_current() const; -public: + public: env_vars_snapshot_t(const env_vars_snapshot_t &) = default; env_vars_snapshot_t &operator=(const env_vars_snapshot_t &) = default; diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index a37f845a9..a8aeaaf66 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -46,7 +46,7 @@ #ifdef __HAIKU__ #define _BSD_SOURCE #include -#endif //Haiku +#endif // Haiku // NAME_MAX is not defined on Solaris and suggests the use of pathconf() // There is no obvious sensible pathconf() for shared memory and _XPG_NAME_MAX @@ -864,8 +864,8 @@ void env_universal_t::parse_message_internal(const wcstring &msgstr, var_table_t #ifdef SIOCGIFHWADDR // Linux -#include #include +#include static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN], const char *interface = "eth0") { bool result = false; @@ -886,9 +886,9 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN], #elif defined(HAVE_GETIFADDRS) // OS X and BSD -#include #include #include +#include static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN], const char *interface = "en0") { // BSD, Mac OS X diff --git a/src/env_universal_common.h b/src/env_universal_common.h index a410f92c3..dcd7b0756 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -136,8 +136,8 @@ class universal_notifier_t { virtual ~universal_notifier_t(); // Factory constructor. - static std::unique_ptr new_notifier_for_strategy(notifier_strategy_t strat, - const wchar_t *test_path = NULL); + static std::unique_ptr new_notifier_for_strategy( + notifier_strategy_t strat, const wchar_t *test_path = NULL); // Default instance. Other instances are possible for testing. static universal_notifier_t &default_notifier(); diff --git a/src/event.cpp b/src/event.cpp index 071177aee..daac533e8 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -263,7 +263,7 @@ void event_remove(const event_t &criterion) { event_list_t::iterator iter = s_event_handlers.begin(); while (iter != s_event_handlers.end()) { const event_t *n = iter->get(); - if (! event_match(criterion, *n)) { + if (!event_match(criterion, *n)) { ++iter; continue; } @@ -323,7 +323,7 @@ static void event_fire_internal(const event_t &event) { if (signal_is_blocked()) { // Fix for https://github.com/fish-shell/fish-shell/issues/608. Don't run event handlers // while signals are blocked. - input_common_add_callback([event](){ + input_common_add_callback([event]() { ASSERT_IS_MAIN_THREAD(); event_fire(&event); }); @@ -333,9 +333,8 @@ static void event_fire_internal(const event_t &event) { // Iterate over our list of matching events. for (shared_ptr &criterion : fire) { // Only fire if this event is still present - if (std::find(s_event_handlers.begin(), - s_event_handlers.end(), - criterion) == s_event_handlers.end()) { + if (std::find(s_event_handlers.begin(), s_event_handlers.end(), criterion) == + s_event_handlers.end()) { continue; } @@ -445,9 +444,7 @@ void event_fire(const event_t *event) { void event_init() {} -void event_destroy() { - s_event_handlers.clear(); -} +void event_destroy() { s_event_handlers.clear(); } void event_fire_generic(const wchar_t *name, wcstring_list_t *args) { CHECK(name, ); diff --git a/src/exec.cpp b/src/exec.cpp index 9a03af75e..f413e3936 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -455,7 +455,7 @@ void exec_job(parser_t &parser, job_t *j) { if (j->get_flag(JOB_CONTROL) && !exec_error) { for (const process_ptr_t &p : j->processes) { if (p->type != EXTERNAL) { - if (! p->is_last_in_job || ! p->is_first_in_job) { + if (!p->is_last_in_job || !p->is_first_in_job) { needs_keepalive = true; break; } @@ -498,7 +498,7 @@ void exec_job(parser_t &parser, job_t *j) { if (exec_error) { break; } - process_t * const p = unique_p.get(); + process_t *const p = unique_p.get(); // The IO chain for this process. It starts with the block IO, then pipes, and then gets any // from the process. io_chain_t process_net_io_chain = j->block_io_chain(); @@ -509,7 +509,7 @@ void exec_job(parser_t &parser, job_t *j) { pipe_next_read = -1; // See if we need a pipe. - const bool pipes_to_next_command = ! p->is_last_in_job; + const bool pipes_to_next_command = !p->is_last_in_job; // The pipes the current process write to and read from. Unfortunately these can't be just // allocated on the stack, since j->io wants shared_ptr. @@ -554,7 +554,7 @@ void exec_job(parser_t &parser, job_t *j) { process_net_io_chain.append(p->io_chain()); // Read pipe goes last. - if (! p->is_first_in_job) { + if (!p->is_first_in_job) { pipe_read.reset(new io_pipe_t(p->pipe_read_fd, true)); // Record the current read in pipe_read. pipe_read->pipe_fd[0] = pipe_current_read; @@ -568,7 +568,7 @@ void exec_job(parser_t &parser, job_t *j) { // uniprocessor systems. if (p->type == EXTERNAL) { // Apply universal barrier so we have the most recent uvar changes - if (! get_proc_had_barrier()) { + if (!get_proc_had_barrier()) { set_proc_had_barrier(true); env_universal_barrier(); } @@ -637,7 +637,8 @@ void exec_job(parser_t &parser, job_t *j) { break; } - function_block_t *fb = parser.push_block(p, func_name, shadow_scope); + function_block_t *fb = + parser.push_block(p, func_name, shadow_scope); // Setting variables might trigger an event handler, hence we need to unblock // signals. @@ -647,7 +648,7 @@ void exec_job(parser_t &parser, job_t *j) { parser.forbid_function(func_name); - if (! p->is_last_in_job) { + if (!p->is_last_in_job) { // Be careful to handle failure, e.g. too many open fds. block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); if (block_output_io_buffer.get() == NULL) { @@ -674,7 +675,7 @@ void exec_job(parser_t &parser, job_t *j) { } case INTERNAL_BLOCK_NODE: { - if (! p->is_last_in_job) { + if (!p->is_last_in_job) { block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); if (block_output_io_buffer.get() == NULL) { // We failed (e.g. no more fds could be created). @@ -764,7 +765,7 @@ void exec_job(parser_t &parser, job_t *j) { } else { // Determine if we have a "direct" redirection for stdin. bool stdin_is_directly_redirected; - if (! p->is_first_in_job) { + if (!p->is_first_in_job) { // We must have a pipe stdin_is_directly_redirected = true; } else { diff --git a/src/expand.cpp b/src/expand.cpp index 2196e4d79..c17f68882 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -430,9 +430,10 @@ bool process_iterator_t::next_process(wcstring *out_str, pid_t *out_pid) { #endif /// The following function is invoked on the main thread, because the job list is not thread safe. -/// It should search the job list for something matching the given proc, and then return true to stop -/// the search, false to continue it. -static bool find_job(const wchar_t *proc, expand_flags_t flags, std::vector *completions) { +/// It should search the job list for something matching the given proc, and then return true to +/// stop the search, false to continue it. +static bool find_job(const wchar_t *proc, expand_flags_t flags, + std::vector *completions) { ASSERT_IS_MAIN_THREAD(); bool found = false; @@ -540,9 +541,7 @@ static void find_process(const wchar_t *proc, expand_flags_t flags, std::vector *out) { if (!(flags & EXPAND_SKIP_JOBS)) { bool found = false; - iothread_perform_on_main([&](){ - found = find_job(proc, flags, out); - }); + iothread_perform_on_main([&]() { found = find_job(proc, flags, out); }); if (found) { return; } diff --git a/src/fallback.cpp b/src/fallback.cpp index 757327e31..5570f06f5 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -170,7 +170,7 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { return wcsncasecmp_fallback(a, b, n); } #endif // __DARWIN_C_LEVEL >= 200809L -#else // __APPLE__ +#else // __APPLE__ /// These functions are missing from Solaris 10 #ifndef HAVE_WCSDUP diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index a2407bba7..3f01c28a3 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -514,7 +514,7 @@ static void test_tokenizer() { // Little function that runs in a background thread, bouncing to the main. static int test_iothread_thread_call(int *addr) { int before = *addr; - iothread_perform_on_main([=](){ *addr += 1; }); + iothread_perform_on_main([=]() { *addr += 1; }); int after = *addr; // Must have incremented it at least once. @@ -531,7 +531,7 @@ static void test_iothread(void) { int max_achieved_thread_count = 0; double start = timef(); for (int i = 0; i < iterations; i++) { - int thread_count = iothread_perform([&](){ test_iothread_thread_call(int_ptr.get());}); + int thread_count = iothread_perform([&]() { test_iothread_thread_call(int_ptr.get()); }); max_achieved_thread_count = std::max(max_achieved_thread_count, thread_count); } @@ -718,7 +718,7 @@ static void test_1_cancellation(const wchar_t *src) { const io_chain_t io_chain(out_buff); pthread_t thread = pthread_self(); double delay = 0.25 /* seconds */; - iothread_perform([=](){ + iothread_perform([=]() { /// Wait a while and then SIGINT the main thread. usleep(delay * 1E6); pthread_kill(thread, SIGINT); @@ -2460,7 +2460,7 @@ static void test_universal() { const int threads = 16; for (int i = 0; i < threads; i++) { - iothread_perform([=](){test_universal_helper(i);}); + iothread_perform([=]() { test_universal_helper(i); }); } iothread_drain_all(); @@ -2898,7 +2898,8 @@ void history_tests_t::test_history_merge(void) { say(L"Testing history merge"); const size_t count = 3; const wcstring name = L"merge_test"; - std::unique_ptr hists[count] = {make_unique(name), make_unique(name), make_unique(name)}; + std::unique_ptr hists[count] = { + make_unique(name), make_unique(name), make_unique(name)}; const wcstring texts[count] = {L"History 1", L"History 2", L"History 3"}; const wcstring alt_texts[count] = {L"History Alt 1", L"History Alt 2", L"History Alt 3"}; @@ -4056,16 +4057,11 @@ static void test_illegal_command_exit_code(void) { }; const command_result_tuple_t tests[] = { - {L"echo -n", STATUS_BUILTIN_OK}, - {L"pwd", STATUS_BUILTIN_OK}, - {L")", STATUS_ILLEGAL_CMD}, - {L") ", STATUS_ILLEGAL_CMD}, - {L"*", STATUS_ILLEGAL_CMD}, - {L"**", STATUS_ILLEGAL_CMD}, - {L"%", STATUS_ILLEGAL_CMD}, - {L"%test", STATUS_ILLEGAL_CMD}, - {L"?", STATUS_ILLEGAL_CMD}, - {L"abc?def", STATUS_ILLEGAL_CMD}, + {L"echo -n", STATUS_BUILTIN_OK}, {L"pwd", STATUS_BUILTIN_OK}, + {L")", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}, + {L"*", STATUS_ILLEGAL_CMD}, {L"**", STATUS_ILLEGAL_CMD}, + {L"%", STATUS_ILLEGAL_CMD}, {L"%test", STATUS_ILLEGAL_CMD}, + {L"?", STATUS_ILLEGAL_CMD}, {L"abc?def", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}}; int res = 0; diff --git a/src/history.cpp b/src/history.cpp index 9579c8b27..d871c9982 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1675,7 +1675,7 @@ path_list_t valid_paths(const path_list_t &paths, const wcstring &working_direct bool all_paths_are_valid(const path_list_t &paths, const wcstring &working_directory) { ASSERT_IS_BACKGROUND_THREAD(); for (const wcstring &path : paths) { - if (! path_is_valid(path, working_directory)) { + if (!path_is_valid(path, working_directory)) { return false; } } @@ -1742,12 +1742,11 @@ void history_t::add_pending_with_file_detection(const wcstring &str) { // Check for which paths are valid on a background thread, // then on the main thread update our history item const wcstring wd = env_get_pwd_slash(); - iothread_perform([=](){ - return valid_paths(potential_paths, wd); - }, [=](path_list_t validated_paths){ - this->set_valid_file_paths(validated_paths, identifier); - this->enable_automatic_saving(); - }); + iothread_perform([=]() { return valid_paths(potential_paths, wd); }, + [=](path_list_t validated_paths) { + this->set_valid_file_paths(validated_paths, identifier); + this->enable_automatic_saving(); + }); } // Actually add the item to the history. diff --git a/src/input_common.h b/src/input_common.h index bc4f93225..3b8bb0535 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -2,8 +2,8 @@ #ifndef INPUT_COMMON_H #define INPUT_COMMON_H -#include #include +#include #include "common.h" diff --git a/src/iothread.cpp b/src/iothread.cpp index c366e2c79..ec032bcee 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -39,13 +39,10 @@ struct spawn_request_t { void_function_t handler; void_function_t completion; - spawn_request_t() - {} + spawn_request_t() {} - spawn_request_t(void_function_t f, void_function_t comp) : - handler(std::move(f)), - completion(std::move(comp)) - {} + spawn_request_t(void_function_t f, void_function_t comp) + : handler(std::move(f)), completion(std::move(comp)) {} // Move-only spawn_request_t &operator=(const spawn_request_t &) = delete; @@ -77,9 +74,11 @@ static pthread_mutex_t s_result_queue_lock = PTHREAD_MUTEX_INITIALIZER; static std::queue s_result_queue; // "Do on main thread" support. -static pthread_mutex_t s_main_thread_performer_lock = PTHREAD_MUTEX_INITIALIZER; // protects the main thread requests -static pthread_cond_t s_main_thread_performer_cond; // protects the main thread requests -static pthread_mutex_t s_main_thread_request_q_lock = PTHREAD_MUTEX_INITIALIZER; // protects the queue +static pthread_mutex_t s_main_thread_performer_lock = + PTHREAD_MUTEX_INITIALIZER; // protects the main thread requests +static pthread_cond_t s_main_thread_performer_cond; // protects the main thread requests +static pthread_mutex_t s_main_thread_request_q_lock = + PTHREAD_MUTEX_INITIALIZER; // protects the queue static std::queue s_main_thread_request_queue; // Notifying pipes. @@ -194,7 +193,7 @@ int iothread_perform_impl(void_function_t &&func, void_function_t &&completion) ASSERT_IS_MAIN_THREAD(); ASSERT_IS_NOT_FORKED_CHILD(); iothread_init(); - + struct spawn_request_t req(std::move(func), std::move(completion)); int local_thread_count = -1; bool spawn_new_thread = false; @@ -366,7 +365,7 @@ void iothread_perform_on_main(void_function_t &&func) { // It would be nice to support checking for cancellation here, but the clients need a // deterministic way to clean up to avoid leaks VOMIT_ON_FAILURE( - pthread_cond_wait(&s_main_thread_performer_cond, &s_main_thread_performer_lock)); + pthread_cond_wait(&s_main_thread_performer_cond, &s_main_thread_performer_lock)); } // Ok, the request must now be done. diff --git a/src/iothread.h b/src/iothread.h index 7e5500ed0..b890c4430 100644 --- a/src/iothread.h +++ b/src/iothread.h @@ -27,8 +27,7 @@ void iothread_service_completion(void); void iothread_drain_all(void); // Internal implementation -int iothread_perform_impl(std::function &&func, - std::function &&completion); +int iothread_perform_impl(std::function &&func, std::function &&completion); // Template helpers // This is the glue part of the handler-completion handoff @@ -36,21 +35,23 @@ int iothread_perform_impl(std::function &&func, // and then call the completion with that object. However if our type is void, // this won't work (new void() fails!). So we have to use this template. // The type T is the return type of HANDLER and the argument to COMPLETION -template +template struct _iothread_trampoline { - template + template static int perform(const HANDLER &handler, const COMPLETION &completion) { - T *result = new T(); // TODO: placement new? - return iothread_perform_impl([=](){ *result = handler(); }, - [=](){ completion(std::move(*result)); delete result; }); + T *result = new T(); // TODO: placement new? + return iothread_perform_impl([=]() { *result = handler(); }, + [=]() { + completion(std::move(*result)); + delete result; + }); } }; - // Void specialization -template<> +template <> struct _iothread_trampoline { - template + template static int perform(const HANDLER &handler, const COMPLETION &completion) { return iothread_perform_impl(handler, completion); } @@ -60,15 +61,14 @@ struct _iothread_trampoline { // on the main thread. The value returned from the handler is passed to the completion. // In other words, this is like COMPLETION(HANDLER()) except the handler part is invoked // on a background thread. -template +template int iothread_perform(const HANDLER &handler, const COMPLETION &completion) { return _iothread_trampoline::perform(handler, completion); } // variant of iothread_perform without a completion handler inline int iothread_perform(std::function &&func) { - return iothread_perform_impl(std::move(func), - std::function()); + return iothread_perform_impl(std::move(func), std::function()); } /// Performs a function on the main thread, blocking until it completes. diff --git a/src/output.cpp b/src/output.cpp index b4bb9f71e..061b8dff9 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -230,7 +230,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) { was_reverse = false; } - if (was_dim && !is_dim ) { + if (was_dim && !is_dim) { // Only way to exit dim mode is a reset of all attributes. writembs(exit_attribute_mode); last_color = normal; @@ -242,7 +242,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) { was_reverse = false; } - if (was_reverse && !is_reverse ) { + if (was_reverse && !is_reverse) { // Only way to exit reverse mode is a reset of all attributes. writembs(exit_attribute_mode); last_color = normal; diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 5f6c9a6ba..55110d885 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -75,9 +75,8 @@ static wcstring profiling_cmd_name_for_redirectable_block(const parse_node_t &no return result; } -parse_execution_context_t::parse_execution_context_t(parse_node_tree_t t, - const wcstring &s, parser_t *p, - int initial_eval_level) +parse_execution_context_t::parse_execution_context_t(parse_node_tree_t t, const wcstring &s, + parser_t *p, int initial_eval_level) : tree(std::move(t)), src(s), parser(p), @@ -1264,14 +1263,15 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t shared_ptr job = std::make_shared(acquire_job_id(), block_io); job->tmodes = tmodes; job->set_flag(JOB_CONTROL, - (job_control_mode == JOB_CONTROL_ALL) || - ((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive())); + (job_control_mode == JOB_CONTROL_ALL) || + ((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive())); job->set_flag(JOB_FOREGROUND, !tree.job_should_be_backgrounded(job_node)); job->set_flag(JOB_TERMINAL, job->get_flag(JOB_CONTROL) && !is_subshell && !is_event); - job->set_flag(JOB_SKIP_NOTIFICATION, is_subshell || is_block || is_event || !shell_is_interactive()); + job->set_flag(JOB_SKIP_NOTIFICATION, + is_subshell || is_block || is_event || !shell_is_interactive()); // Tell the current block what its job is. This has to happen before we populate it (#1394). parser->current_block()->job = job; diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 32da0cf10..eda099ac3 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -124,7 +124,6 @@ const wchar_t *token_type_description(parse_token_type_t type) { const wchar_t *description = enum_to_str(type, token_enum_map); if (description) return description; return L"unknown_token_type"; - } const wchar_t *keyword_description(parse_keyword_t type) { diff --git a/src/parse_tree.h b/src/parse_tree.h index dc932a782..c5652cff0 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -142,8 +142,8 @@ class parse_node_tree_t : public std::vector { parse_node_tree_t() {} parse_node_tree_t(parse_node_tree_t &&) = default; parse_node_tree_t &operator=(parse_node_tree_t &&) = default; - parse_node_tree_t(const parse_node_tree_t &) = delete; // no copying - parse_node_tree_t &operator=(const parse_node_tree_t &) = delete; // no copying + parse_node_tree_t(const parse_node_tree_t &) = delete; // no copying + parse_node_tree_t &operator=(const parse_node_tree_t &) = delete; // no copying // Get the node corresponding to a child of the given node, or NULL if there is no such child. // If expected_type is provided, assert that the node has that type. diff --git a/src/parser.cpp b/src/parser.cpp index 586bb8c5f..0a3194cc2 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -525,7 +525,7 @@ wcstring parser_t::current_line() { void parser_t::job_add(shared_ptr job) { assert(job != NULL); - assert(! job->processes.empty()); + assert(!job->processes.empty()); this->my_job_list.push_front(std::move(job)); } @@ -596,7 +596,8 @@ int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t return this->eval(cmd, io, block_type, std::move(tree)); } -int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, parse_node_tree_t tree) { +int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, + parse_node_tree_t tree) { CHECK_BLOCK(1); assert(block_type == TOP || block_type == SUBST); @@ -612,8 +613,8 @@ int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t (execution_contexts.empty() ? -1 : execution_contexts.back()->current_eval_level()); // Append to the execution context stack. - execution_contexts.push_back(make_unique(std::move(tree), cmd, - this, exec_eval_level)); + execution_contexts.push_back( + make_unique(std::move(tree), cmd, this, exec_eval_level)); const parse_execution_context_t *ctx = execution_contexts.back().get(); // Execute the first node. diff --git a/src/parser.h b/src/parser.h index f28d0c3f7..4baec50b6 100644 --- a/src/parser.h +++ b/src/parser.h @@ -244,7 +244,8 @@ class parser_t { int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type); /// Evaluate the expressions contained in cmd, which has been parsed into the given parse tree. - int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, parse_node_tree_t t); + int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, + parse_node_tree_t t); /// Evaluates a block node at the given node offset in the topmost execution context. int eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum block_type_t block_type); @@ -288,8 +289,8 @@ class parser_t { /// Pushes a new block created with the given arguments /// Returns a pointer to the block. The pointer is valid /// until the call to pop_block() - template - BLOCKTYPE *push_block(Args&&... args) { + template + BLOCKTYPE *push_block(Args &&... args) { BLOCKTYPE *ret = new BLOCKTYPE(std::forward(args)...); this->push_block_int(ret); return ret; diff --git a/src/proc.cpp b/src/proc.cpp index 1a9a61d68..38c4d62f6 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -220,7 +220,7 @@ int job_is_stopped(const job_t *j) { /// /// \param j the job to test bool job_is_completed(const job_t *j) { - assert(! j->processes.empty()); + assert(!j->processes.empty()); bool result = true; for (const process_ptr_t &p : j->processes) { if (!p->completed) { @@ -239,9 +239,7 @@ void job_t::set_flag(job_flag_t flag, bool set) { } } -bool job_t::get_flag(job_flag_t flag) const { - return !! (this->flags & flag); -} +bool job_t::get_flag(job_flag_t flag) const { return !!(this->flags & flag); } int job_signal(job_t *j, int signal) { pid_t my_pid = getpid(); @@ -368,9 +366,7 @@ process_t::process_t() job_t::job_t(job_id_t jobid, const io_chain_t &bio) : block_io(bio), pgid(0), tmodes(), job_id(jobid), flags(0) {} -job_t::~job_t() { - release_job_id(job_id); -} +job_t::~job_t() { release_job_id(job_id); } /// Return all the IO redirections. Start with the block IO, then walk over the processes. io_chain_t job_t::all_io_redirections() const { @@ -798,17 +794,18 @@ static bool terminal_give_to_job(job_t *j, int cont) { } if (cont) { - int result = -1; - errno = EINTR; - while (result == -1 && errno == EINTR) { - result = tcsetattr(STDIN_FILENO, TCSADRAIN, &j->tmodes); - } - if (result == -1) { - if (errno == ENOTTY) redirect_tty_output(); - debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') to foreground"), j->job_id, j->command_wcstr()); - wperror(L"tcsetattr"); - return false; - } + int result = -1; + errno = EINTR; + while (result == -1 && errno == EINTR) { + result = tcsetattr(STDIN_FILENO, TCSADRAIN, &j->tmodes); + } + if (result == -1) { + if (errno == ENOTTY) redirect_tty_output(); + debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') to foreground"), + j->job_id, j->command_wcstr()); + wperror(L"tcsetattr"); + return false; + } } return true; @@ -985,7 +982,6 @@ void proc_sanity_check() { while (const job_t *j = jobs.next()) { if (!j->get_flag(JOB_CONSTRUCTED)) continue; - // More than one foreground job? if (j->get_flag(JOB_FOREGROUND) && !(job_is_stopped(j) || job_is_completed(j))) { if (fg_job) { @@ -1013,7 +1009,6 @@ void proc_sanity_check() { j->command_wcstr(), p->argv0(), p->completed); sanity_lose(); } - } } } diff --git a/src/reader.cpp b/src/reader.cpp index 5e80108df..f7228843a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -37,8 +37,8 @@ #include #include -#include #include +#include #include "color.h" #include "common.h" @@ -1118,8 +1118,8 @@ struct autosuggestion_result_t { // Returns a function that can be invoked (potentially // on a background thread) to determine the autosuggestion -static std::function -get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, history_t *history) { +static std::function get_autosuggestion_performer( + const wcstring &search_string, size_t cursor_pos, history_t *history) { const unsigned int generation_count = s_generation_count; const wcstring working_directory(env_get_pwd_slash()); env_vars_snapshot_t vars(env_vars_snapshot_t::highlighting_keys); @@ -1135,8 +1135,8 @@ get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, h return nothing; } - VOMIT_ON_FAILURE(pthread_setspecific(generation_count_key, - (void *)(uintptr_t)generation_count)); + VOMIT_ON_FAILURE( + pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count)); // Let's make sure we aren't using the empty string. if (search_string.empty()) { @@ -1176,9 +1176,8 @@ get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, h if (!completions.empty()) { const completion_t &comp = completions.at(0); size_t cursor = cursor_pos; - wcstring suggestion = completion_apply_to_command_line(comp.completion, comp.flags, - search_string, &cursor, - true /* append only */); + wcstring suggestion = completion_apply_to_command_line( + comp.completion, comp.flags, search_string, &cursor, true /* append only */); return {std::move(suggestion), search_string}; } @@ -1197,8 +1196,7 @@ static bool can_autosuggest(void) { // Called after an autosuggestion has been computed on a background thread static void autosuggest_completed(autosuggestion_result_t result) { - if (! result.suggestion.empty() && - can_autosuggest() && + if (!result.suggestion.empty() && can_autosuggest() && result.search_string == data->command_line.text && string_prefixes_string_case_insensitive(result.search_string, result.suggestion)) { // Autosuggestion is active and the search term has not changed, so we're good to go. @@ -2104,7 +2102,8 @@ static void highlight_complete(highlight_result_t result) { // Given text, bracket matching position, and whether IO is allowed, // return a function that performs highlighting. The function may be invoked on a background thread. static std::function get_highlight_performer(const wcstring &text, - long match_highlight_pos, bool no_io) { + long match_highlight_pos, + bool no_io) { env_vars_snapshot_t vars(env_vars_snapshot_t::highlighting_keys); unsigned int generation_count = s_generation_count; highlight_function_t highlight_func = no_io ? highlight_shell_no_io : data->highlight_function; @@ -2116,7 +2115,8 @@ static std::function get_highlight_performer(const wcs if (text.empty()) { return {}; } - VOMIT_ON_FAILURE(pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count)); + VOMIT_ON_FAILURE( + pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count)); std::vector colors(text.size(), 0); highlight_func(text, colors, match_highlight_pos, NULL /* error */, vars); return {std::move(colors), text};