From e44bfd114156cb22c2539dbe41d6ae887b5124c1 Mon Sep 17 00:00:00 2001 From: yzy-1 <50034950+yzy-1@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:47:20 +0800 Subject: [PATCH] fix: Compatibility fixes --- include/generator.i.hpp | 8 ++++++-- include/interactor.hpp | 10 +--------- include/interactor.i.hpp | 12 +----------- include/io.i.hpp | 16 ++++++++++++---- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/include/generator.i.hpp b/include/generator.i.hpp index b954632..93c5e13 100644 --- a/include/generator.i.hpp +++ b/include/generator.i.hpp @@ -171,8 +171,12 @@ inline auto get_args_usage(const State& state) { } inline auto set_binary_mode() { -#ifdef ON_WINDOWS - _setmode(fileno(stdout), _O_BINARY); // Sets file mode to binary + /* + We recommend using binary mode on Windows. However, Codeforces Polygon doesn’t think so. + Since the only Online Judge that uses Windows seems to be Codeforces, make it happy. + */ +#if defined(ON_WINDOWS) && !defined(ONLINE_JUDGE) + _setmode(fileno(stdout), _O_BINARY); #endif } } // namespace detail diff --git a/include/interactor.hpp b/include/interactor.hpp index a32a45e..1ca3957 100644 --- a/include/interactor.hpp +++ b/include/interactor.hpp @@ -174,17 +174,12 @@ struct State { */ ~State(); - /** - * Disables the check for redundant content of `from_user` stream. - */ - auto disable_check_dirt() -> void; - /** * Quits the interactor with the given report. * * @param report The report to be reported. */ - [[noreturn]] auto quit(Report report) -> void; + [[noreturn]] auto quit(const Report& report) -> void; /** * Quits the interactor with the `report::Status::ACCEPTED` status. @@ -210,9 +205,6 @@ struct State { private: /// Whether the program has exited. bool exited_{false}; - - /// Whether to check for redundant content in the `from_user` stream. - bool check_dirt_{true}; }; /** diff --git a/include/interactor.i.hpp b/include/interactor.i.hpp index a585378..a70c3f4 100644 --- a/include/interactor.i.hpp +++ b/include/interactor.i.hpp @@ -29,7 +29,6 @@ /* cplib_embed_ignore start */ #include "cmd_args.hpp" -#include "io.hpp" #include "json.hpp" #include "macros.hpp" #include "utils.hpp" @@ -135,18 +134,9 @@ inline State::~State() { if (!exited_) panic("Interactor must exit by calling method `State::quit*`"); } -inline auto State::disable_check_dirt() -> void { check_dirt_ = true; } - -inline auto State::quit(Report report) -> void { +inline auto State::quit(const Report& report) -> void { exited_ = true; - if (check_dirt_ && - (report.status == Report::Status::ACCEPTED || - report.status == Report::Status::PARTIALLY_CORRECT) && - !from_user.inner().seek_eof()) { - report = Report(Report::Status::WRONG_ANSWER, 0.0, "Extra content in the user output"); - } - reporter->report(report); std::clog << "Unrecoverable error: Reporter didn't exit the program\n"; diff --git a/include/io.i.hpp b/include/io.i.hpp index 7fbe47a..e1a17e1 100644 --- a/include/io.i.hpp +++ b/include/io.i.hpp @@ -43,8 +43,12 @@ namespace detail { struct FdOutBuf : std::streambuf { public: explicit FdOutBuf(int fd) : fd_(fd) { -#ifdef ON_WINDOWS - _setmode(fd_, _O_BINARY); // Sets file mode to binary + /* + We recommend using binary mode on Windows. However, Codeforces Polygon doesn’t think so. + Since the only Online Judge that uses Windows seems to be Codeforces, make it happy. + */ +#if defined(ON_WINDOWS) && !defined(ONLINE_JUDGE) + _setmode(fd_, _O_BINARY); #endif } @@ -80,8 +84,12 @@ struct FdInBuf : std::streambuf { * => Force underflow() */ explicit FdInBuf(int fd) : fd_(fd) { -#ifdef ON_WINDOWS - _setmode(fd_, _O_BINARY); // Sets file mode to binary + /* + We recommend using binary mode on Windows. However, Codeforces Polygon doesn’t think so. + Since the only Online Judge that uses Windows seems to be Codeforces, make it happy. + */ +#if defined(ON_WINDOWS) && !defined(ONLINE_JUDGE) + _setmode(fd_, _O_BINARY); #endif setg(buf_.data() + PB_SIZE, // Beginning of putback area buf_.data() + PB_SIZE, // Read position