From 273afca3da0417fa0818194fb2850dfe17e48e68 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 15 Jan 2020 11:59:40 -0800 Subject: [PATCH] Remove some dead code --- src/cancellable.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/common.cpp | 32 ---------------------------- src/common.h | 14 ------------- 3 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 src/cancellable.h diff --git a/src/cancellable.h b/src/cancellable.h new file mode 100644 index 000000000..5cd03f510 --- /dev/null +++ b/src/cancellable.h @@ -0,0 +1,53 @@ +#ifndef FISH_CANCELLABLE_H +#define FISH_CANCELLABLE_H + +#include "maybe.h" + +/// A simple value type representing cancellation via a signal. +struct cancellation_t { + int signal; + + explicit cancellation_t(int sig) : signal(sig) {} +}; + +/// A cancellable_t is a wrapper around T which may be cancelled, for example by a signal. +template +class cancellable_t : private maybe_t { + using super = maybe_t; + + public: + /// Construct from a T. + /* implicit */ cancellable_t(T &&v) : super(v) {} + /* implicit */ cancellable_t(const T &v) : super(v) {} + + /// Construct from a cancellation. + /* implicit */ cancellable_t(cancellation_t c) : super(none()), signal_(c.signal) {} + + cancellable_t(const cancellable_t &) = default; + cancellable_t(cancellable_t &&) = default; + + /// Access the cancellation signal, if this was cancelled. + int signal() const { + assert(!has_value() && "Not cancelled"); + return signal_; + } + + /// \return whether this was cancelled. + bool is_cancelled() const { return !has_value(); } + + // Expose maybe_t::value and dereferencing. + using super::has_value; + using super::value; + using super::operator->; + using super::operator*; + + /// Notice we don't compare signals when checking for equality. + bool operator==(const cancellable_t &rhs) const { super::operator==(rhs); } + bool operator!=(const cancellable_t &rhs) const { super::operator!=(rhs); } + + private: + // The cancellation signal. + int signal_{0}; +}; + +#endif diff --git a/src/common.cpp b/src/common.cpp index 6f36c6dff..6e43badc4 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -250,38 +250,6 @@ bool is_windows_subsystem_for_linux() { } #endif // HAVE_BACKTRACE_SYMBOLS -int fgetws2(wcstring *s, FILE *f) { - int i = 0; - wint_t c; - - while (true) { - errno = 0; - - c = std::fgetwc(f); - if (errno == EILSEQ || errno == EINTR) { - continue; - } - - switch (c) { - // End of line. - case WEOF: - case L'\n': - case L'\0': { - return i; - } - // Ignore carriage returns. - case L'\r': { - break; - } - default: { - i++; - s->push_back(static_cast(c)); - break; - } - } - } -} - /// Converts the narrow character string \c in into its wide equivalent, and return it. /// /// The string may contain embedded nulls. diff --git a/src/common.h b/src/common.h index 67b788405..d3d1939d3 100644 --- a/src/common.h +++ b/src/common.h @@ -269,14 +269,6 @@ std::shared_ptr move_to_sharedptr(T &&v) { /// Print a stack trace to stderr. void show_stackframe(const wchar_t msg_level, int frame_count = 100, int skip_levels = 0); -/// Read a line from the stream f into the string. Returns the number of bytes read or -1 on -/// failure. -/// -/// If the carriage return character is encountered, it is ignored. fgetws() considers the line to -/// end if reading the file results in either a newline (L'\n') character, the null (L'\\0') -/// character or the end of file (WEOF) character. -int fgetws2(wcstring *s, FILE *f); - /// Returns a wide character string equivalent of the specified multibyte character string. /// /// This function encodes illegal character sequences in a reversible way using the private use @@ -768,12 +760,6 @@ std::unique_ptr make_unique(Args &&... args) { /// \param in the position of the opening quote. wchar_t *quote_end(const wchar_t *pos); -/// A call to this function will reset the error counter. Some functions print out non-critical -/// error messages. These should check the error_count before, and skip printing the message if -/// MAX_ERROR_COUNT messages have been printed. The error_reset() should be called after each -/// interactive command executes, to allow new messages to be printed. -void error_reset(); - /// This function should be called after calling `setlocale()` to perform fish specific locale /// initialization. void fish_setlocale();