mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-01 07:38:46 +00:00
fb92ad946b
Several functions including wgetopt and execve operate on null-terminated arrays of nul-terminated pointers: a list of pointers to C strings where the last pointer is null. Prior to this change, each process_t stored its argv in such an array. This had two problems: 1. It was awkward to work with this type, instead of using std::vector, etc. 2. The process's arguments would be rearranged by builtins which is surprising Our null terminated arrays were built around a fancy type that would copy input strings and also generate an array of pointers to them, in one big allocation. Switch to a new model where we construct an array of pointers over existing strings. So you can supply a `vector<string>` and now `null_terminated_array_t` will just make a list of pointers to them. Now processes can just store their argv in a familiar wcstring_list_t.
10 lines
282 B
C++
10 lines
282 B
C++
#include "null_terminated_array.h"
|
|
|
|
std::vector<std::string> wide_string_list_to_narrow(const wcstring_list_t &strs) {
|
|
std::vector<std::string> res;
|
|
res.reserve(strs.size());
|
|
for (const wcstring &s : strs) {
|
|
res.push_back(wcs2string(s));
|
|
}
|
|
return res;
|
|
}
|