Make arguments to builtins const

Prior to this change, builtins would take their arguments as `wchar_t **`.
This implies that the order of the arguments may be changed (which is
true, `wgetopter` does so) but also that the strings themselves may be
changed, which no builtin should do.

Switch them all to take `const wchar_t **` instead: now the arguments may
be rearranged but their contents may no longer be modified.
This commit is contained in:
ridiculousfish
2021-02-13 18:41:09 -08:00
parent 0b06a0ee07
commit e0e4b11dbd
79 changed files with 294 additions and 284 deletions

View File

@@ -1,7 +1,7 @@
#include "null_terminated_array.h"
template <typename CharT>
static CharT **make_null_terminated_array_helper(
static const CharT **make_null_terminated_array_helper(
const std::vector<std::basic_string<CharT> > &argv) {
size_t count = argv.size();
@@ -48,14 +48,14 @@ static CharT **make_null_terminated_array_helper(
assert(reinterpret_cast<unsigned char *>(strings) - base ==
static_cast<std::ptrdiff_t>(pointers_allocation_len + strings_allocation_len));
return reinterpret_cast<CharT **>(base);
return reinterpret_cast<const CharT **>(base);
}
wchar_t **make_null_terminated_array(const wcstring_list_t &lst) {
const wchar_t **make_null_terminated_array(const wcstring_list_t &lst) {
return make_null_terminated_array_helper(lst);
}
char **make_null_terminated_array(const std::vector<std::string> &lst) {
const char **make_null_terminated_array(const std::vector<std::string> &lst) {
return make_null_terminated_array_helper(lst);
}