Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit d126358

Browse files
committed
Fixed linter
1 parent 4fafb3e commit d126358

4 files changed

Lines changed: 86 additions & 69 deletions

File tree

cpp/frontend/frontend.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ namespace frontend {
55
namespace {
66
class FileProvider : public capnproto::FileSender::Server {
77
public:
8-
FileProvider(std::unordered_map<util::SHA256_t, std::string,
9-
util::SHA256_t::Hasher>& known_files)
10-
: known_files_(known_files) {}
8+
explicit FileProvider(
9+
std::unordered_map<util::SHA256_t, std::string, util::SHA256_t::Hasher>
10+
known_files)
11+
: known_files_(std::move(known_files)) {}
1112

12-
kj::Promise<void> requestFile(RequestFileContext context) {
13+
kj::Promise<void> requestFile(RequestFileContext context) override {
1314
std::string path = known_files_.at(context.getParams().getHash());
1415
return util::File::HandleRequestFile(path,
1516
context.getParams().getReceiver());
@@ -23,7 +24,7 @@ class FileProvider : public capnproto::FileSender::Server {
2324
} // namespace
2425

2526
void File::getContentsAsString(
26-
std::function<void(const std::string&)> callback) {
27+
const std::function<void(const std::string&)>& callback) {
2728
auto pf = kj::newPromiseAndFulfiller<void>();
2829
frontend_.builder_.AddPromise(std::move(pf.promise));
2930
frontend_.finish_builder_.AddPromise(
@@ -71,7 +72,7 @@ void File::getContentsToFile(const std::string& path, bool overwrite,
7172
"Get file");
7273
}
7374

74-
Frontend::Frontend(std::string server, int port)
75+
Frontend::Frontend(const std::string& server, int port)
7576
: client_(server, port),
7677
frontend_context_(
7778
client_.getMain<capnproto::MainServer>()
@@ -96,7 +97,7 @@ File* Frontend::provideFile(const std::string& path,
9697
hash.ToCapnp(req.initHash());
9798
req.setDescription(description);
9899
req.setIsExecutable(is_executable);
99-
files_.push_back(File::New(req.send(), *this, is_executable));
100+
files_.push_back(File::New(req.send(), this, is_executable));
100101
return files_.back().get();
101102
}
102103

@@ -105,16 +106,16 @@ Execution* Frontend::addExecution(const std::string& description) {
105106
req.setDescription(description);
106107
executions_.push_back(std::make_unique<Execution>(
107108
description, req.send().then([](auto r) { return r.getExecution(); }),
108-
files_, builder_, finish_builder_, *this));
109+
&files_, &builder_, &finish_builder_, this));
109110
return executions_.back().get();
110111
}
111112

112113
ExecutionGroup* Frontend::addExecutionGroup(const std::string& description) {
113114
auto req = frontend_context_.addExecutionGroupRequest();
114115
req.setDescription(description);
115116
groups_.push_back(std::make_unique<ExecutionGroup>(
116-
description, req.send().then([](auto r) { return r.getGroup(); }), files_,
117-
builder_, finish_builder_, *this));
117+
description, req.send().then([](auto r) { return r.getGroup(); }),
118+
&files_, &builder_, &finish_builder_, this));
118119
return groups_.back().get();
119120
}
120121

@@ -139,8 +140,8 @@ Execution* ExecutionGroup::addExecution(const std::string& description) {
139140
req.setDescription(description);
140141
executions_.push_back(std::make_unique<Execution>(
141142
description_ + " of group " + description,
142-
req.send().then([](auto r) { return r.getExecution(); }), files_,
143-
builder_, finish_builder_, frontend_));
143+
req.send().then([](auto r) { return r.getExecution(); }), &files_,
144+
&builder_, &finish_builder_, &frontend_));
144145
return executions_.back().get();
145146
}
146147

@@ -260,25 +261,25 @@ void Execution::setExtraTime(float extra_time) {
260261
File* Execution::stdout(bool is_executable) {
261262
auto req = execution_.stdoutRequest();
262263
req.setIsExecutable(is_executable);
263-
files_.push_back(File::New(req.send(), frontend_, is_executable));
264+
files_.push_back(File::New(req.send(), &frontend_, is_executable));
264265
return files_.back().get();
265266
}
266267

267268
File* Execution::stderr(bool is_executable) {
268269
auto req = execution_.stderrRequest();
269270
req.setIsExecutable(is_executable);
270-
files_.push_back(File::New(req.send(), frontend_, is_executable));
271+
files_.push_back(File::New(req.send(), &frontend_, is_executable));
271272
return files_.back().get();
272273
}
273274
File* Execution::output(const std::string& name, bool is_executable) {
274275
auto req = execution_.outputRequest();
275276
req.setIsExecutable(is_executable);
276277
req.setName(name);
277-
files_.push_back(File::New(req.send(), frontend_, is_executable));
278+
files_.push_back(File::New(req.send(), &frontend_, is_executable));
278279
return files_.back().get();
279280
}
280281

281-
void Execution::notifyStart(std::function<void()> callback) {
282+
void Execution::notifyStart(const std::function<void()>& callback) {
282283
finish_builder_.AddPromise(
283284
execution_.notifyStartRequest()
284285
.send()
@@ -288,8 +289,8 @@ void Execution::notifyStart(std::function<void()> callback) {
288289
"Notify start " + description_);
289290
}
290291

291-
void Execution::getResult(std::function<void(Result)> callback,
292-
std::function<void()> errored) {
292+
void Execution::getResult(const std::function<void(Result)>& callback,
293+
const std::function<void()>& errored) {
293294
auto promise = kj::newPromiseAndFulfiller<void>();
294295
builder_.AddPromise(std::move(promise.promise));
295296
auto ff = promise.fulfiller.get();

cpp/frontend/frontend.hpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ class Fifo {
5353
public:
5454
Fifo() : promise(capnproto::Fifo::Reader()), forked_promise(promise.fork()) {}
5555
virtual ~Fifo() = default;
56+
Fifo(const Fifo&) = delete;
57+
Fifo(Fifo&&) = default;
58+
Fifo& operator=(const Fifo&) = delete;
59+
Fifo& operator=(Fifo&&) = default;
5660
template <typename T>
5761
static std::unique_ptr<Fifo> New(kj::Promise<T>&& p);
5862
};
5963

6064
template <typename T>
6165
class FifoInst : public Fifo {
6266
public:
63-
FifoInst(T&& p)
67+
explicit FifoInst(T&& p)
6468
: pf(kj::newPromiseAndFulfiller<capnproto::Fifo::Reader>()),
6569
promise(std::move(p)) {
6670
SetPromise(std::move(pf.promise));
@@ -102,27 +106,32 @@ class File {
102106
promise = std::move(prom);
103107
forked_promise = promise.fork();
104108
}
105-
File(Frontend& frontend, bool is_executable)
109+
File(Frontend* frontend, bool is_executable)
106110
: promise(capnproto::File::Reader()),
107111
forked_promise(promise.fork()),
108112
is_executable_(is_executable),
109-
frontend_(frontend) {}
113+
frontend_(*frontend) {}
110114

111115
public:
112116
template <typename T>
113-
static std::unique_ptr<File> New(kj::Promise<T>&& p, Frontend& frontend,
117+
static std::unique_ptr<File> New(kj::Promise<T>&& p, Frontend* frontend,
114118
bool is_executable);
115119
virtual ~File() = default;
120+
File(const File&) = delete;
121+
File(File&&) = delete;
122+
File& operator=(const File&) = delete;
123+
File& operator=(File&&) = delete;
116124

117-
void getContentsAsString(std::function<void(const std::string&)> callback);
125+
void getContentsAsString(
126+
const std::function<void(const std::string&)>& callback);
118127
void getContentsToFile(const std::string& path, bool overwrite,
119128
bool exist_ok);
120129
};
121130

122131
template <typename T>
123132
class FileInst : public File {
124133
public:
125-
FileInst(T&& p, Frontend& frontend, bool is_executable)
134+
FileInst(T&& p, Frontend* frontend, bool is_executable)
126135
: File(frontend, is_executable),
127136
pf(kj::newPromiseAndFulfiller<capnproto::File::Reader>()),
128137
promise(std::move(p)) {
@@ -147,7 +156,7 @@ class FileInst : public File {
147156
};
148157

149158
template <typename T>
150-
std::unique_ptr<File> File::New(kj::Promise<T>&& p, Frontend& frontend,
159+
std::unique_ptr<File> File::New(kj::Promise<T>&& p, Frontend* frontend,
151160
bool is_executable) {
152161
return std::make_unique<FileInst<kj::Promise<T>>>(std::move(p), frontend,
153162
is_executable);
@@ -156,15 +165,15 @@ std::unique_ptr<File> File::New(kj::Promise<T>&& p, Frontend& frontend,
156165
class Execution {
157166
public:
158167
Execution(std::string description, capnproto::Execution::Client execution,
159-
std::vector<std::unique_ptr<File>>& files,
160-
util::UnionPromiseBuilder& builder,
161-
util::UnionPromiseBuilder& finish_builder, Frontend& frontend)
168+
std::vector<std::unique_ptr<File>>* files,
169+
util::UnionPromiseBuilder* builder,
170+
util::UnionPromiseBuilder* finish_builder, Frontend* frontend)
162171
: description_(std::move(description)),
163-
execution_(execution),
164-
files_(files),
165-
builder_(builder),
166-
finish_builder_(finish_builder),
167-
frontend_(frontend) {}
172+
execution_(std::move(execution)),
173+
files_(*files),
174+
builder_(*builder),
175+
finish_builder_(*finish_builder),
176+
frontend_(*frontend) {}
168177

169178
void setExecutablePath(const std::string& path);
170179
void setExecutable(const std::string& name, File* file);
@@ -186,10 +195,10 @@ class Execution {
186195
File* stderr(bool is_executable);
187196
File* output(const std::string& name, bool is_executable);
188197

189-
void notifyStart(std::function<void()> callback);
198+
void notifyStart(const std::function<void()>& callback);
190199

191-
void getResult(std::function<void(Result)> callback,
192-
std::function<void()> errored = nullptr);
200+
void getResult(const std::function<void(Result)>& callback,
201+
const std::function<void()>& errored = nullptr);
193202

194203
private:
195204
std::string description_;
@@ -205,15 +214,15 @@ class ExecutionGroup {
205214
public:
206215
ExecutionGroup(std::string description,
207216
capnproto::ExecutionGroup::Client execution_group,
208-
std::vector<std::unique_ptr<File>>& files,
209-
util::UnionPromiseBuilder& builder,
210-
util::UnionPromiseBuilder& finish_builder, Frontend& frontend)
217+
std::vector<std::unique_ptr<File>>* files,
218+
util::UnionPromiseBuilder* builder,
219+
util::UnionPromiseBuilder* finish_builder, Frontend* frontend)
211220
: description_(std::move(description)),
212-
execution_group_(execution_group),
213-
files_(files),
214-
builder_(builder),
215-
finish_builder_(finish_builder),
216-
frontend_(frontend) {}
221+
execution_group_(std::move(execution_group)),
222+
files_(*files),
223+
builder_(*builder),
224+
finish_builder_(*finish_builder),
225+
frontend_(*frontend) {}
217226
Execution* addExecution(const std::string& description);
218227
Fifo* createFifo();
219228

@@ -233,7 +242,7 @@ class Frontend {
233242
friend class File;
234243

235244
public:
236-
Frontend(std::string server, int port);
245+
Frontend(const std::string& server, int port);
237246

238247
File* provideFile(const std::string& path, const std::string& description,
239248
bool is_executable);

cpp/frontend/python/frontend.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@
77

88
#include "frontend/frontend.hpp"
99

10-
using namespace pybind11::literals;
10+
using pybind11::literals::operator""_a;
1111

1212
template <typename T>
1313
class DestroyWithGIL {
1414
public:
15-
explicit DestroyWithGIL(T t) : t_(t) {}
16-
T& operator*() { return t_; }
15+
explicit DestroyWithGIL(T t) : t_(std::make_shared<T>(t)) {}
16+
T& operator*() { return *t_; }
1717
~DestroyWithGIL() {
1818
pybind11::gil_scoped_acquire acquire;
19-
t_ = T();
19+
t_ = nullptr;
2020
}
21+
DestroyWithGIL(const DestroyWithGIL& other) = default;
22+
DestroyWithGIL(DestroyWithGIL&& other) noexcept = default;
23+
DestroyWithGIL& operator=(const DestroyWithGIL& other) = default;
24+
DestroyWithGIL& operator=(DestroyWithGIL&& other) noexcept = default;
2125

2226
private:
23-
T t_;
27+
std::shared_ptr<T> t_;
2428
};
2529

2630
template <typename T>
2731
DestroyWithGIL<T> destroy_with_gil(T t) {
2832
return DestroyWithGIL<T>(t);
2933
}
3034

35+
// NOLINTNEXTLINE
3136
PYBIND11_MODULE(task_maker_frontend, m) {
3237
m.doc() = "Task-maker frontend module";
3338
pybind11::class_<frontend::Resources>(m, "Resources")
@@ -68,30 +73,32 @@ PYBIND11_MODULE(task_maker_frontend, m) {
6873
.def_readonly("was_killed", &frontend::Result::was_killed)
6974
.def("__repr__", [](const frontend::Result& res) {
7075
std::string message = "<Result ";
71-
if (res.status == capnproto::ProcessResult::Status::Which::SUCCESS)
76+
if (res.status == capnproto::ProcessResult::Status::Which::SUCCESS) {
7277
message += "SUCCESS";
73-
else if (res.status == capnproto::ProcessResult::Status::Which::SIGNAL)
78+
} else if (res.status ==
79+
capnproto::ProcessResult::Status::Which::SIGNAL) {
7480
message += "SIGNAL " + std::to_string(res.signal);
75-
else if (res.status ==
76-
capnproto::ProcessResult::Status::Which::RETURN_CODE)
81+
} else if (res.status ==
82+
capnproto::ProcessResult::Status::Which::RETURN_CODE) {
7783
message += "RETURN_CODE " + std::to_string(res.return_code);
78-
else if (res.status ==
79-
capnproto::ProcessResult::Status::Which::TIME_LIMIT)
84+
} else if (res.status ==
85+
capnproto::ProcessResult::Status::Which::TIME_LIMIT) {
8086
message += "TIME_LIMIT";
81-
else if (res.status ==
82-
capnproto::ProcessResult::Status::Which::WALL_LIMIT)
87+
} else if (res.status ==
88+
capnproto::ProcessResult::Status::Which::WALL_LIMIT) {
8389
message += "WALL_LIMIT";
84-
else if (res.status ==
85-
capnproto::ProcessResult::Status::Which::MEMORY_LIMIT)
90+
} else if (res.status ==
91+
capnproto::ProcessResult::Status::Which::MEMORY_LIMIT) {
8692
message += "MEMORY_LIMIT";
87-
else if (res.status ==
88-
capnproto::ProcessResult::Status::Which::MISSING_FILES)
93+
} else if (res.status ==
94+
capnproto::ProcessResult::Status::Which::MISSING_FILES) {
8995
message += "MISSING_FILES";
90-
else if (res.status ==
91-
capnproto::ProcessResult::Status::Which::INTERNAL_ERROR)
96+
} else if (res.status ==
97+
capnproto::ProcessResult::Status::Which::INTERNAL_ERROR) {
9298
message += "INTERNAL_ERROR";
93-
else
99+
} else {
94100
message += "UNKNOWN";
101+
}
95102
message += ">";
96103
return message;
97104
});
@@ -115,7 +122,7 @@ PYBIND11_MODULE(task_maker_frontend, m) {
115122
.def("getContentsToFile", &frontend::File::getContentsToFile, "path"_a,
116123
"overwrite"_a = true, "exist_ok"_a = true);
117124

118-
pybind11::class_<frontend::Fifo>(m, "Fifo");
125+
pybind11::class_<frontend::Fifo> _(m, "Fifo");
119126

120127
pybind11::class_<frontend::Execution>(m, "Execution")
121128
.def("setExecutablePath", &frontend::Execution::setExecutablePath,

hooks/lint-cpp-file

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/bin/bash -e
22

3-
INCLUDES=$(cat .syntastic_cpp_config)
4-
EXCLUDE_CHECKS="-llvm-header-guard,-cppcoreguidelines-pro-type-reinterpret-cast,-modernize-make-unique,-readability-braces-around-statements,-google-readability-braces-around-statements,-hicpp-braces-around-statements,-fuchsia-default-arguments,-fuchsia-overloaded-operator,-hicpp-signed-bitwise"
3+
INCLUDES="-Icpp -Ithird_party $(pkgconf --cflags python3) -Ibuild"
4+
EXCLUDE_CHECKS="-fuchsia-multiple-inheritance,-fuchsia-overloaded-operator,-fuchsia-default-arguments,-hicpp-braces-around-statements,-readability-braces-around-statements,-llvm-header-guard,-llvm-include-order,-bugprone-suspicious-semicolon"
55

66
check_file_clang() {
77
file="${1}"
88
echo "====> clang-tiding $file"
99
# TODO: add -quiet as soon as it is supported
1010
clang-tidy --checks=*,${EXCLUDE_CHECKS} \
1111
--warnings-as-errors=*,${EXCLUDE_CHECKS} ${1} \
12-
-- -std=c++11 ${INCLUDES}
12+
-- -std=c++14 ${INCLUDES}
1313
}
1414

1515
for file in $@; do

0 commit comments

Comments
 (0)