Skip to content

Commit

Permalink
fix: Compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yzy-1 committed Jul 28, 2024
1 parent a708b24 commit e44bfd1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
8 changes: 6 additions & 2 deletions include/generator.i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions include/interactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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};
};

/**
Expand Down
12 changes: 1 addition & 11 deletions include/interactor.i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

/* cplib_embed_ignore start */
#include "cmd_args.hpp"
#include "io.hpp"
#include "json.hpp"
#include "macros.hpp"
#include "utils.hpp"
Expand Down Expand Up @@ -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";
Expand Down
16 changes: 12 additions & 4 deletions include/io.i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e44bfd1

Please sign in to comment.