Eliminate / vet and whitelist some more globals

This commit is contained in:
ridiculousfish 2018-09-29 00:58:44 -04:00
parent 0170875ece
commit 36a149337b
5 changed files with 38 additions and 36 deletions

View File

@ -5,26 +5,39 @@
# This was written for macOS nm.
set total_globals 0
set boring_files fish_key_reader.cpp.o
set boring_files \
fish_key_reader.cpp.o \
fish_tests.cpp.o \
fish_indent.cpp.o \
set whitelist \
termsize_lock termsize \
initial_fg_process_group \
initial_pid initial_fg_process_group \
_debug_level \
sitm_esc ritm_esc dim_esc \
s_main_thread_performer_lock s_main_thread_performer_cond s_main_thread_request_q_lock
iothread_init()::inited \
s_result_queue s_main_thread_request_queue s_read_pipe s_write_pipe \
s_main_thread_performer_lock s_main_thread_performer_cond s_main_thread_request_q_lock \
locked_consumed_job_ids \
env_initialized \
for file in ./**.o
set filename (basename $file)
# Skip boring files.
contains $filename $boring_files ; and continue
for line in (nm -p -P -U $file)
# Look in data (dD) and bss (bB) segments.
set matches (string match --regex '^([^ ]+) ([dDbB])' -- $line) ; or continue
set symname (echo $matches[2] | c++filt)
contains $symname $whitelist ; and continue
echo $filename $symname $matches[3]
set total_globals (math $total_globals + 1)
end
set filename (basename $file)
# Skip boring files.
contains $filename $boring_files
and continue
for line in (nm -p -P -U $file)
# Look in data (dD) and bss (bB) segments.
set matches (string match --regex '^([^ ]+) ([dDbB])' -- $line)
or continue
set symname (echo $matches[2] | c++filt)
contains $symname $whitelist
and continue
echo $filename $symname $matches[3]
set total_globals (math $total_globals + 1)
end
end
echo "Total: $total_globals"
echo "Total: $total_globals"

View File

@ -285,10 +285,10 @@ inline bool is_whitespace(const wchar_t *input) { return is_whitespace(wcstring(
/// See https://developer.gnome.org/glib/stable/glib-I18N.html#N-:CAPS
#define N_(wstr) wstr
/// Test if a vector contains a value.
template <typename T1, typename T2>
bool contains(const std::vector<T1> &vec, const T2 &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
/// Test if a collection contains a value.
template <typename Col, typename T2>
bool contains(const Col &col, const T2 &val) {
return std::find(std::begin(col), std::end(col), val) != std::end(col);
}
/// Print a stack trace to stderr.

View File

@ -278,12 +278,6 @@ static env_universal_t *s_universal_variables = NULL;
/// Getter for universal variables.
static env_universal_t *uvars() { return s_universal_variables; }
// Helper class for storing constant strings, without needing to wrap them in a wcstring.
// Comparer for const string set.
// Note our sets are small so we don't bother to sort them.
typedef std::unordered_set<wcstring> const_string_set_t;
// A typedef for a set of constant strings. Note our sets are typically on the order of 6 elements,
// so we don't bother to sort them.
using string_set_t = const wchar_t *const[];
@ -321,11 +315,9 @@ static bool variable_is_colon_delimited_var(const wcstring &str) {
}
/// Table of variables whose value is dynamically calculated, such as umask, status, etc.
static const_string_set_t env_electric;
static const string_set_t env_electric = {L"history", L"status", L"umask"};
static bool is_electric(const wcstring &key) {
return env_electric.find(key) != env_electric.end();
}
static bool is_electric(const wcstring &key) { return contains(env_electric, key); }
maybe_t<env_var_t> env_node_t::find_entry(const wcstring &key) {
var_table_t::const_iterator entry = env.find(key);
@ -876,9 +868,6 @@ static void setup_var_dispatch_table() {
void env_init(const struct config_paths_t *paths /* or NULL */) {
setup_var_dispatch_table();
// Names of all dynamically calculated variables.
env_electric.insert({L"history", L"status", L"umask"});
// Now the environment variable handling is set up, the next step is to insert valid data.
// Import environment variables. Walk backwards so that the first one out of any duplicates wins
@ -1456,7 +1445,7 @@ wcstring_list_t env_get_names(int flags) {
if (show_global) {
add_key_to_string_set(vars_stack().global_env->env, &names, show_exported, show_unexported);
if (show_unexported) {
result.insert(result.end(), env_electric.begin(), env_electric.end());
result.insert(result.end(), std::begin(env_electric), std::end(env_electric));
}
}

View File

@ -762,8 +762,8 @@ static bool append_syntax_error(parse_error_list_t *errors, size_t source_locati
}
/// Returns 1 if the specified command is a builtin that may not be used in a pipeline.
static const wcstring_list_t forbidden_pipe_commands({L"exec", L"case", L"break", L"return",
L"continue"});
static const wchar_t *const forbidden_pipe_commands[] = {L"exec", L"case", L"break", L"return",
L"continue"};
static int parser_is_pipe_forbidden(const wcstring &word) {
return contains(forbidden_pipe_commands, word);
}

View File

@ -56,7 +56,7 @@
static int last_status = 0;
/// The signals that signify crashes to us.
static const std::vector<int> crashsignals = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGSYS };
static const int crashsignals[] = {SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGSYS};
bool job_list_is_empty() {
ASSERT_IS_MAIN_THREAD();