aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/function.h
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-05-08 15:57:56 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-05-14 20:38:32 -0700
commit51468b764689e7d724a87e6c2b8cdb4e599a3604 (patch)
tree75fe13dbad791e0d143a3610bfe7ed7d0136ad38 /src/function.h
parentff1d651415a2752e82ec417294f9bdf8c234c10f (diff)
add `function --shadow-builtin` flag
It's currently too easy for someone to bork their shell by doing something like `function test; return 0; end`. That's obviously a silly, contrived, example but the point is that novice users who learn about functions are prone to do something like that without realizing it will bork the shell. Even expert users who know about the `test` builtin might forget that, say, `pwd` is a builtin. This change adds a `--shadow-builtin` flag that must be specified to indicate you know what you're doing. Fixes #3000
Diffstat (limited to 'src/function.h')
-rw-r--r--src/function.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/function.h b/src/function.h
index 04829cbe..59b37051 100644
--- a/src/function.h
+++ b/src/function.h
@@ -31,44 +31,41 @@ struct function_data_t {
/// List of all variables that are inherited from the function definition scope. The variable
/// values are snapshotted when function_add() is called.
wcstring_list_t inherit_vars;
- /// Set to non-zero if invoking this function shadows the variables of the underlying function.
- int shadows;
+ /// Set to true if invoking this function shadows the variables of the underlying function.
+ bool shadow_scope;
+ /// Set to true if this function shadows a builtin.
+ bool shadow_builtin;
};
class function_info_t {
public:
- /// Constructs relevant information from the function_data.
- function_info_t(const function_data_t &data, const wchar_t *filename, int def_offset,
- bool autoload);
-
- /// Used by function_copy.
- function_info_t(const function_info_t &data, const wchar_t *filename, int def_offset,
- bool autoload);
-
/// Function definition.
const wcstring definition;
-
/// Function description. Only the description may be changed after the function is created.
wcstring description;
-
/// File where this function was defined (intern'd string).
const wchar_t *const definition_file;
-
/// Line where definition started.
const int definition_offset;
-
/// List of all named arguments for this function.
const wcstring_list_t named_arguments;
-
/// Mapping of all variables that were inherited from the function definition scope to their
/// values.
const std::map<wcstring, env_var_t> inherit_vars;
-
/// Flag for specifying that this function was automatically loaded.
const bool is_autoload;
-
+ /// Set to true if this function shadows a builtin.
+ const bool shadow_builtin;
/// Set to true if invoking this function shadows the variables of the underlying function.
- const bool shadows;
+ const bool shadow_scope;
+
+ /// Constructs relevant information from the function_data.
+ function_info_t(const function_data_t &data, const wchar_t *filename, int def_offset,
+ bool autoload);
+
+ /// Used by function_copy.
+ function_info_t(const function_info_t &data, const wchar_t *filename, int def_offset,
+ bool autoload);
};
/// Initialize function data.
@@ -133,8 +130,11 @@ std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name);
/// is successful.
bool function_copy(const wcstring &name, const wcstring &new_name);
+/// Returns whether this function shadows a builtin of the same name.
+int function_get_shadow_builtin(const wcstring &name);
+
/// Returns whether this function shadows variables of the underlying function.
-int function_get_shadows(const wcstring &name);
+int function_get_shadow_scope(const wcstring &name);
/// Prepares the environment for executing a function.
void function_prepare_environment(const wcstring &name, const wchar_t *const *argv,