From 16459099afc4290fe6b2d2776ee003d7f1ff48f2 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 30 Oct 2014 18:19:47 -0700 Subject: [PATCH] Make C_ (gettext used in completions) return wcstring --- autoload.cpp | 1 + builtin.cpp | 2 +- common.cpp | 3 +-- complete.cpp | 21 +++++++++++++-------- env.cpp | 1 - 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/autoload.cpp b/autoload.cpp index ad18dab04..165afb39d 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -232,6 +232,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_ /* If we can use this function, return whether we were able to access it */ if (use_cached) { + assert(func != NULL); return func->is_internalized || func->access.accessible; } } diff --git a/builtin.cpp b/builtin.cpp index e4f276f9f..ac8def935 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -613,7 +613,7 @@ static int builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int u wcstring seq2; if (get_terminfo_sequence(*seq++, &seq2)) { - input_mapping_erase(seq2.c_str(), mode); + input_mapping_erase(seq2, mode); } else { diff --git a/common.cpp b/common.cpp index ae421de40..ceb323cb2 100644 --- a/common.cpp +++ b/common.cpp @@ -255,7 +255,6 @@ char *wcs2str(const wchar_t *in) { if (! in) return NULL; - char *out; size_t desired_size = MAX_UTF8_BYTES*wcslen(in)+1; char local_buff[512]; if (desired_size <= sizeof local_buff / sizeof *local_buff) @@ -277,7 +276,7 @@ char *wcs2str(const wchar_t *in) else { // here we fall into the bad case of allocating a buffer probably much larger than necessary - out = (char *)malloc(MAX_UTF8_BYTES*wcslen(in)+1); + char *out = (char *)malloc(MAX_UTF8_BYTES*wcslen(in)+1); if (!out) { DIE_MEM(); diff --git a/complete.cpp b/complete.cpp index 9f9a27b82..6397a2504 100644 --- a/complete.cpp +++ b/complete.cpp @@ -101,9 +101,15 @@ response) */ #ifdef USE_GETTEXT -#define C_(wstr) ((wcscmp(wstr, L"")==0)?L"":wgettext(wstr)) +static const wchar_t *C_(const wcstring &s) +{ + return s.empty() ? L"" : wgettext(s); +} #else -#define C_(string) (string) +static const wcstring &C_(const wcstring &s) +{ + return s; +} #endif /* Testing apparatus */ @@ -158,10 +164,9 @@ typedef struct complete_entry_opt /** Completion flags */ complete_flags_t flags; - const wchar_t *localized_desc() const + const wcstring localized_desc() const { - const wchar_t *tmp = desc.c_str(); - return C_(tmp); + return C_(desc); } } complete_entry_opt_t; @@ -1535,7 +1540,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop if (o->short_opt != L'\0' && short_ok(str, o->short_opt, iter->short_opt_str)) { - const wchar_t *desc = o->localized_desc(); + const wcstring desc = o->localized_desc(); wchar_t completion[2]; completion[0] = o->short_opt; completion[1] = 0; @@ -2110,7 +2115,7 @@ void complete_print(wcstring &out) for (std::vector::const_iterator iter = all_completions.begin(); iter != all_completions.end(); ++iter) { const completion_entry_t *e = *iter; - const option_list_t options = e->get_options(); + const option_list_t &options = e->get_options(); for (option_list_t::const_iterator oiter = options.begin(); oiter != options.end(); ++oiter) { const complete_entry_opt_t *o = &*oiter; @@ -2146,7 +2151,7 @@ void complete_print(wcstring &out) append_switch(out, L"description", - C_(o->desc.c_str())); + C_(o->desc)); append_switch(out, L"arguments", diff --git a/env.cpp b/env.cpp index fc10e820a..996784558 100644 --- a/env.cpp +++ b/env.cpp @@ -978,7 +978,6 @@ env_var_t env_get_string(const wcstring &key, env_mode_flags_t mode) scoped_lock lock(env_lock); env_node_t *env = search_local ? top : global_env; - wcstring result; while (env != NULL) {