Add some noexcepts

This is to assert that callback functions should never throw (since
the context in which they're called may not be able to handle the
exception).
This commit is contained in:
Eelco Dolstra 2019-09-03 13:00:55 +02:00
parent 7348653ff4
commit f186000367
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
11 changed files with 19 additions and 18 deletions

View file

@ -55,7 +55,7 @@ void BinaryCacheStore::init()
} }
void BinaryCacheStore::getFile(const std::string & path, void BinaryCacheStore::getFile(const std::string & path,
Callback<std::shared_ptr<std::string>> callback) Callback<std::shared_ptr<std::string>> callback) noexcept
{ {
try { try {
callback(getFile(path)); callback(getFile(path));
@ -240,7 +240,7 @@ void BinaryCacheStore::narFromPath(const Path & storePath, Sink & sink)
} }
void BinaryCacheStore::queryPathInfoUncached(const Path & storePath, void BinaryCacheStore::queryPathInfoUncached(const Path & storePath,
Callback<std::shared_ptr<ValidPathInfo>> callback) Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept
{ {
auto uri = getUri(); auto uri = getUri();
auto act = std::make_shared<Activity>(*logger, lvlTalkative, actQueryPathInfo, auto act = std::make_shared<Activity>(*logger, lvlTalkative, actQueryPathInfo,

View file

@ -47,7 +47,7 @@ public:
/* Fetch the specified file and call the specified callback with /* Fetch the specified file and call the specified callback with
the result. A subclass may implement this asynchronously. */ the result. A subclass may implement this asynchronously. */
virtual void getFile(const std::string & path, virtual void getFile(const std::string & path,
Callback<std::shared_ptr<std::string>> callback); Callback<std::shared_ptr<std::string>> callback) noexcept;
std::shared_ptr<std::string> getFile(const std::string & path); std::shared_ptr<std::string> getFile(const std::string & path);
@ -73,7 +73,7 @@ public:
bool isValidPathUncached(const Path & path) override; bool isValidPathUncached(const Path & path) override;
void queryPathInfoUncached(const Path & path, void queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) override; Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept override;
Path queryPathFromHashPart(const string & hashPart) override Path queryPathFromHashPart(const string & hashPart) override
{ unsupported("queryPathFromHashPart"); } { unsupported("queryPathFromHashPart"); }

View file

@ -131,7 +131,7 @@ protected:
} }
void getFile(const std::string & path, void getFile(const std::string & path,
Callback<std::shared_ptr<std::string>> callback) override Callback<std::shared_ptr<std::string>> callback) noexcept override
{ {
checkEnabled(); checkEnabled();

View file

@ -88,7 +88,7 @@ struct LegacySSHStore : public Store
} }
void queryPathInfoUncached(const Path & path, void queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) override Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept override
{ {
try { try {
auto conn(connections->get()); auto conn(connections->get());

View file

@ -629,7 +629,7 @@ uint64_t LocalStore::addValidPath(State & state,
void LocalStore::queryPathInfoUncached(const Path & path, void LocalStore::queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept
{ {
try { try {
auto info = std::make_shared<ValidPathInfo>(); auto info = std::make_shared<ValidPathInfo>();

View file

@ -127,7 +127,7 @@ public:
PathSet queryAllValidPaths() override; PathSet queryAllValidPaths() override;
void queryPathInfoUncached(const Path & path, void queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) override; Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept override;
void queryReferrers(const Path & path, PathSet & referrers) override; void queryReferrers(const Path & path, PathSet & referrers) override;

View file

@ -349,7 +349,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
void RemoteStore::queryPathInfoUncached(const Path & path, void RemoteStore::queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept
{ {
try { try {
std::shared_ptr<ValidPathInfo> info; std::shared_ptr<ValidPathInfo> info;

View file

@ -41,7 +41,7 @@ public:
PathSet queryAllValidPaths() override; PathSet queryAllValidPaths() override;
void queryPathInfoUncached(const Path & path, void queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) override; Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept override;
void queryReferrers(const Path & path, PathSet & referrers) override; void queryReferrers(const Path & path, PathSet & referrers) override;

View file

@ -329,13 +329,14 @@ ref<const ValidPathInfo> Store::queryPathInfo(const Path & storePath)
void Store::queryPathInfo(const Path & storePath, void Store::queryPathInfo(const Path & storePath,
Callback<ref<ValidPathInfo>> callback) Callback<ref<ValidPathInfo>> callback) noexcept
{ {
assertStorePath(storePath); std::string hashPart;
auto hashPart = storePathToHash(storePath);
try { try {
assertStorePath(storePath);
hashPart = storePathToHash(storePath);
{ {
auto res = state.lock()->pathInfoCache.get(hashPart); auto res = state.lock()->pathInfoCache.get(hashPart);

View file

@ -360,12 +360,12 @@ public:
/* Asynchronous version of queryPathInfo(). */ /* Asynchronous version of queryPathInfo(). */
void queryPathInfo(const Path & path, void queryPathInfo(const Path & path,
Callback<ref<ValidPathInfo>> callback); Callback<ref<ValidPathInfo>> callback) noexcept;
protected: protected:
virtual void queryPathInfoUncached(const Path & path, virtual void queryPathInfoUncached(const Path & path,
Callback<std::shared_ptr<ValidPathInfo>> callback) = 0; Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept = 0;
public: public:

View file

@ -460,7 +460,7 @@ public:
if (prev) done.test_and_set(); if (prev) done.test_and_set();
} }
void operator()(T && t) void operator()(T && t) noexcept
{ {
auto prev = done.test_and_set(); auto prev = done.test_and_set();
assert(!prev); assert(!prev);
@ -469,7 +469,7 @@ public:
fun(promise.get_future()); fun(promise.get_future());
} }
void rethrow(const std::exception_ptr & exc = std::current_exception()) void rethrow(const std::exception_ptr & exc = std::current_exception()) noexcept
{ {
auto prev = done.test_and_set(); auto prev = done.test_and_set();
assert(!prev); assert(!prev);