diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 4f273840c..8d1bc992e 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -124,8 +124,8 @@ static wcstring functions_def(const wcstring &name) { CHECK(!name.empty(), L""); //!OCLINT(multiple unary operator) wcstring out; wcstring desc, def; - function_get_desc(name, &desc); - function_get_definition(name, &def); + function_get_desc(name, desc); + function_get_definition(name, def); event_t search(EVENT_ANY); search.function_name = name; std::vector> ev; @@ -243,7 +243,7 @@ static int report_function_metadata(const wchar_t *funcname, bool verbose, io_st path = L"stdin"; } shadows_scope = props->shadow_scope ? L"scope-shadowing" : L"no-scope-shadowing"; - function_get_desc(funcname, &description); + function_get_desc(funcname, description); description = escape_string(description, ESCAPE_NO_QUOTED); } diff --git a/src/complete.cpp b/src/complete.cpp index 25f67a2b0..e1d5cfe76 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -644,9 +644,9 @@ void completer_t::complete_cmd_desc(const wcstring &str) { /// Returns a description for the specified function, or an empty string if none. static wcstring complete_function_desc(const wcstring &fn) { wcstring result; - bool has_description = function_get_desc(fn, &result); + bool has_description = function_get_desc(fn, result); if (!has_description) { - function_get_definition(fn, &result); + function_get_definition(fn, result); } return result; } diff --git a/src/function.cpp b/src/function.cpp index bf32c2fe3..30593812a 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -228,6 +228,7 @@ void function_remove(const wcstring &name) { if (function_remove_ignore_autoload(name)) function_autoloader.unload(name); } +/// Returns a function by name if it has been loaded, returns false otherwise. Does not autoload. static const function_info_t *function_get(const wcstring &name) { // The caller must lock the functions_lock before calling this; however our mutex is currently // recursive, so trylock will never fail. We need a way to correctly check if a lock is locked @@ -240,11 +241,11 @@ static const function_info_t *function_get(const wcstring &name) { return &iter->second; } -bool function_get_definition(const wcstring &name, wcstring *out_definition) { +bool function_get_definition(const wcstring &name, wcstring &out_definition) { scoped_rlock locker(functions_lock); const function_info_t *func = function_get(name); - if (func && out_definition) { - out_definition->assign(func->props->body_node.get_source(func->props->parsed_source->src)); + if (func) { + out_definition = func->props->body_node.get_source(func->props->parsed_source->src); } return func != NULL; } @@ -255,12 +256,12 @@ std::map function_get_inherit_vars(const wcstring &name) { return func ? func->inherit_vars : std::map(); } -bool function_get_desc(const wcstring &name, wcstring *out_desc) { +bool function_get_desc(const wcstring &name, wcstring &out_desc) { // Empty length string goes to NULL. scoped_rlock locker(functions_lock); const function_info_t *func = function_get(name); - if (out_desc && func && !func->description.empty()) { - out_desc->assign(_(func->description.c_str())); + if (func && !func->description.empty()) { + out_desc = _(func->description.c_str()); return true; } diff --git a/src/function.h b/src/function.h index 5adfabb18..7520e19c7 100644 --- a/src/function.h +++ b/src/function.h @@ -59,12 +59,12 @@ std::shared_ptr function_get_properties(const wcstr /// Returns by reference the definition of the function with the name \c name. Returns true if /// successful, false if no function with the given name exists. /// This does not trigger autoloading. -bool function_get_definition(const wcstring &name, wcstring *out_definition); +bool function_get_definition(const wcstring &name, wcstring &out_definition); /// Returns by reference the description of the function with the name \c name. Returns true if the /// function exists and has a nonempty description, false if it does not. /// This does not trigger autoloading. -bool function_get_desc(const wcstring &name, wcstring *out_desc); +bool function_get_desc(const wcstring &name, wcstring &out_desc); /// Sets the description of the function with the name \c name. void function_set_desc(const wcstring &name, const wcstring &desc);