diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ffdc43d..c74136b8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,6 @@ set(FISH_SRCS src/highlight.cpp src/input_common.cpp src/input.cpp - src/null_terminated_array.cpp src/output.cpp src/pager.cpp src/parse_util.cpp diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index afe4c82da..999b2213a 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -80,7 +80,6 @@ #include "kill.rs.h" #include "lru.h" #include "maybe.h" -#include "null_terminated_array.h" #include "operation_context.h" #include "pager.h" #include "parse_constants.h" diff --git a/src/null_terminated_array.cpp b/src/null_terminated_array.cpp deleted file mode 100644 index 2107a6aa8..000000000 --- a/src/null_terminated_array.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "null_terminated_array.h" - -std::vector wide_string_list_to_narrow(const std::vector &strs) { - std::vector res; - res.reserve(strs.size()); - for (const wcstring &s : strs) { - res.push_back(wcs2zstring(s)); - } - return res; -} - -const char **owning_null_terminated_array_t::get() { return impl_->get(); } - -owning_null_terminated_array_t::owning_null_terminated_array_t(std::vector &&strings) - : impl_(new_owning_null_terminated_array(strings)) {} - -owning_null_terminated_array_t::owning_null_terminated_array_t( - rust::Box impl) - : impl_(std::move(impl)) {} diff --git a/src/null_terminated_array.h b/src/null_terminated_array.h deleted file mode 100644 index 71a17af24..000000000 --- a/src/null_terminated_array.h +++ /dev/null @@ -1,83 +0,0 @@ -// Support for null-terminated arrays like char**. -#ifndef FISH_NULL_TERMINATED_ARRAY_H -#define FISH_NULL_TERMINATED_ARRAY_H - -#include "config.h" // IWYU pragma: keep - -#include -#include -#include -#include - -#include "common.h" -#include "cxx.h" - -struct OwningNullTerminatedArrayRefFFI; -#if INCLUDE_RUST_HEADERS -#include "null_terminated_array.rs.h" -#endif - -/// This supports the null-terminated array of NUL-terminated strings consumed by exec. -/// Given a list of strings, construct a vector of pointers to those strings contents. -/// This is used for building null-terminated arrays of null-terminated strings. -/// *Important*: the vector stores pointers into the interior of the input strings, which may be -/// subject to the small-string optimization. This means that pointers will be left dangling if any -/// input string is deallocated *or moved*. This class should only be used in transient calls. -template -class null_terminated_array_t : noncopyable_t, nonmovable_t { - public: - /// \return the list of pointers, appropriate for envp or argv. - /// Note this returns a mutable array of const strings. The caller may rearrange the strings but - /// not modify their contents. - const T **get() { - assert(!pointers_.empty() && pointers_.back() == nullptr && "Should have null terminator"); - return &pointers_[0]; - } - - // Construct from a list of strings (std::string or wcstring). - // This holds pointers into the strings. - explicit null_terminated_array_t(const std::vector> &strs) { - pointers_.reserve(strs.size() + 1); - for (const auto &s : strs) { - pointers_.push_back(s.c_str()); - } - pointers_.push_back(nullptr); - } - - private: - std::vector pointers_{}; -}; - -/// A container which exposes a null-terminated array of pointers to strings that it owns. -/// This is useful for persisted null-terminated arrays, e.g. the exported environment variable -/// list. This assumes char, since we don't need this for wchar_t. -/// Note this class is not movable or copyable as it embeds a null_terminated_array_t. -struct owning_null_terminated_array_t { - public: - // Access the null-terminated array of nul-terminated strings, appropriate for execv(). - const char **get(); - - // Construct, taking ownership of a list of strings. - explicit owning_null_terminated_array_t(std::vector &&strings); - - // Construct from the FFI side. - explicit owning_null_terminated_array_t(rust::Box impl); - - private: - const rust::Box impl_; -}; - -/// Helper to convert a list of wcstring to a list of std::string. -std::vector wide_string_list_to_narrow(const std::vector &strs); - -/// \return the length of a null-terminated array of pointers to something. -template -size_t null_terminated_array_length(const T *const *arr) { - size_t idx = 0; - while (arr[idx] != nullptr) { - idx++; - } - return idx; -} - -#endif // FISH_NULL_TERMINATED_ARRAY_H