Skip to content

Commit

Permalink
Merge pull request arximboldi#155 from cyrilRomain/master
Browse files Browse the repository at this point in the history
Add config.hpp to enable -fno-exceptions builds
  • Loading branch information
arximboldi authored Jul 11, 2022
2 parents b6f4070 + fca02c7 commit 63e148d
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 58 deletions.
40 changes: 40 additions & 0 deletions lager/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// lager - library for functional interactive c++ programs
// Copyright (C) 2017 Juan Pedro Bolivar Puente
//
// This file is part of lager.
//
// lager is free software: you can redistribute it and/or modify
// it under the terms of the MIT License, as detailed in the LICENSE
// file located at the root of this source code distribution,
// or here: <https://github.com/arximboldi/lager/blob/master/LICENSE>
//

#pragma once

#if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
#define LAGER_HAS_CPP17 1
#endif

#ifdef __has_feature
#if !__has_feature(cxx_exceptions)
#define LAGER_NO_EXCEPTIONS
#endif
#endif

#ifdef LAGER_NO_EXCEPTIONS
#define LAGER_TRY if (true)
#define LAGER_CATCH(expr) else
#define LAGER_THROW(expr) \
do { \
assert(!#expr); \
std::terminate(); \
} while (false)
#define LAGER_RETHROW
#else
#define LAGER_TRY try
#define LAGER_CATCH(expr) catch (expr)
#define LAGER_THROW(expr) throw expr
#define LAGER_RETHROW throw
#endif

3 changes: 2 additions & 1 deletion lager/debug/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <lager/config.hpp>
#include <lager/detail/access.hpp>
#include <lager/effect.hpp>
#include <lager/util.hpp>
Expand Down Expand Up @@ -95,7 +96,7 @@ struct debugger
lookup_result lookup(cursor_t cursor) const
{
if (cursor > history.size())
throw std::runtime_error{"bad cursor"};
LAGER_THROW(std::runtime_error{"bad cursor"});
return cursor == 0 ? lookup_result{{}, init} : [&] {
auto& step = history[cursor - 1];
return lookup_result{step.action, step.model};
Expand Down
5 changes: 3 additions & 2 deletions lager/debug/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <lager/config.hpp>
#include <lager/context.hpp>
#include <lager/reader.hpp>

Expand Down Expand Up @@ -80,9 +81,9 @@ class router
});

if (it != resources_.end()) {
try {
LAGER_TRY {
return it->handler(std::move(req));
} catch (const std::exception& err) {
} LAGER_CATCH(const std::exception& err) {
return create_response_(500, "text/html", err.what());
}
}
Expand Down
11 changes: 6 additions & 5 deletions lager/debug/tree_debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <lager/config.hpp>
#include <lager/context.hpp>
#include <lager/util.hpp>

Expand Down Expand Up @@ -121,10 +122,10 @@ struct tree_debugger
{
auto pos = cursor[cursor_index];
if (pos.branch >= branches.size())
throw std::runtime_error{"bad cursor"};
LAGER_THROW(std::runtime_error{"bad cursor"});
auto& history = branches[pos.branch];
if (pos.step >= history.size())
throw std::runtime_error{"bad cursor"};
LAGER_THROW(std::runtime_error{"bad cursor"});
auto& node = history[pos.step];
auto next_index = cursor_index + 1;
return next_index == cursor.size()
Expand Down Expand Up @@ -190,10 +191,10 @@ struct tree_debugger

bool check(const cursor_t& cursor) const
{
try {
LAGER_TRY {
lookup(cursor);
return true;
} catch (const std::runtime_error&) {
} LAGER_CATCH(const std::runtime_error&) {
return false;
}
}
Expand Down Expand Up @@ -268,7 +269,7 @@ struct tree_debugger
return m;
},
[&](redo_action) -> result_t {
throw std::runtime_error{"todo"};
LAGER_THROW(std::runtime_error{"todo"});
return m;
},
[&](pause_action) -> result_t {
Expand Down
4 changes: 3 additions & 1 deletion lager/deps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <boost/hana/at_key.hpp>
#include <boost/hana/filter.hpp>
#include <boost/hana/find.hpp>
Expand Down Expand Up @@ -164,7 +166,7 @@ struct opt : to_spec<T>
if (x)
return to_spec<T>::get(*std::forward<Storage>(x));
else
throw missing_dependency_error{"missing dependency in lager::deps"};
LAGER_THROW(missing_dependency_error{"missing dependency in lager::deps"});
}

template <typename Storage>
Expand Down
4 changes: 3 additions & 1 deletion lager/detail/no_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <zug/meta/util.hpp>

#include <exception>
Expand All @@ -34,7 +36,7 @@ struct no_value
template <typename T>
operator T() const
{
throw no_value_error{};
LAGER_THROW(no_value_error{});
}
};

Expand Down
7 changes: 4 additions & 3 deletions lager/detail/xform_nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <lager/config.hpp>
#include <lager/detail/no_value.hpp>
#include <lager/detail/nodes.hpp>
#include <lager/util.hpp>
Expand Down Expand Up @@ -46,17 +47,17 @@ ZUG_INLINE_CONSTEXPR struct send_down_rf_t
template <typename ValueT, typename Xform, typename... ParentPtrs>
ValueT initial_value(Xform&& xform, const std::tuple<ParentPtrs...>& parents)
{
try {
LAGER_TRY {
return std::apply(
[&](auto&&... ps) {
return xform(zug::last)(detail::no_value{}, ps->current()...);
},
parents);
} catch (const no_value_error&) {
} LAGER_CATCH(const no_value_error&) {
if constexpr (std::is_default_constructible<ValueT>::value) {
return ValueT{};
} else {
throw;
LAGER_THROW();
}
}
};
Expand Down
4 changes: 3 additions & 1 deletion lager/event_loop/manual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <functional>
#include <stdexcept>
#include <utility>
Expand All @@ -24,7 +26,7 @@ struct with_manual_event_loop
template <typename Fn>
void async(Fn&& fn)
{
throw std::logic_error{"manual_event_loop does not support async()"};
LAGER_THROW(std::logic_error{"manual_event_loop does not support async()"});
}

template <typename Fn>
Expand Down
9 changes: 5 additions & 4 deletions lager/event_loop/qml.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <lager/config.hpp>
#include <lager/event_loop/queue.hpp>

#include <QQuickItem>
Expand Down Expand Up @@ -79,13 +80,13 @@ class event_loop_quick_item : public QQuickItem
}
}

void finish() { throw std::logic_error{"not implemented!"}; }
void pause() { throw std::logic_error{"not implemented!"}; }
void resume() { throw std::logic_error{"not implemented!"}; }
void finish() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void pause() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void resume() { LAGER_THROW(std::logic_error{"not implemented!"}); }
template <typename Fn>
void async(Fn&& fn)
{
throw std::logic_error{"not implemented!"};
LAGER_THROW(std::logic_error{"not implemented!"});
}
};

Expand Down
6 changes: 4 additions & 2 deletions lager/event_loop/qt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <QObject>
#include <QThreadPool>
#include <QtConcurrent>
Expand Down Expand Up @@ -45,8 +47,8 @@ struct with_qt_event_loop

void finish() { QCoreApplication::instance()->quit(); }

void pause() { throw std::runtime_error{"not implemented!"}; }
void resume() { throw std::runtime_error{"not implemented!"}; }
void pause() { LAGER_THROW(std::runtime_error{"not implemented!"}); }
void resume() { LAGER_THROW(std::runtime_error{"not implemented!"}); }
};

} // namespace lager
10 changes: 6 additions & 4 deletions lager/event_loop/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <functional>
#include <stdexcept>
#include <utility>
Expand All @@ -24,13 +26,13 @@ struct queue_event_loop
using event_fn = std::function<void()>;

void post(event_fn ev) { queue_.push_back(std::move(ev)); }
void finish() { throw std::logic_error{"not implemented!"}; }
void pause() { throw std::logic_error{"not implemented!"}; }
void resume() { throw std::logic_error{"not implemented!"}; }
void finish() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void pause() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void resume() { LAGER_THROW(std::logic_error{"not implemented!"}); }
template <typename Fn>
void async(Fn&& fn)
{
throw std::logic_error{"not implemented!"};
LAGER_THROW(std::logic_error{"not implemented!"});
}

void step()
Expand Down
10 changes: 6 additions & 4 deletions lager/event_loop/safe_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <functional>
#include <mutex>
#include <stdexcept>
Expand All @@ -36,13 +38,13 @@ struct safe_queue_event_loop
}
}

void finish() { throw std::logic_error{"not implemented!"}; }
void pause() { throw std::logic_error{"not implemented!"}; }
void resume() { throw std::logic_error{"not implemented!"}; }
void finish() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void pause() { LAGER_THROW(std::logic_error{"not implemented!"}); }
void resume() { LAGER_THROW(std::logic_error{"not implemented!"}); }
template <typename Fn>
void async(Fn&& fn)
{
throw std::logic_error{"not implemented!"};
LAGER_THROW(std::logic_error{"not implemented!"});
}

void step()
Expand Down
4 changes: 3 additions & 1 deletion lager/event_loop/sdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <SDL2/SDL.h>

#include <algorithm>
Expand Down Expand Up @@ -196,7 +198,7 @@ struct with_sdl_event_loop
template <typename Fn>
void async(Fn&& fn)
{
throw std::logic_error{"not implemented!"};
LAGER_THROW(std::logic_error{"not implemented!"});
}

template <typename Fn>
Expand Down
6 changes: 4 additions & 2 deletions lager/extra/cereal/immer_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <cereal/cereal.hpp>

#include <immer/map.hpp>
Expand Down Expand Up @@ -53,7 +55,7 @@ CEREAL_LOAD_FUNCTION_NAME(Archive& ar, immer::map<K, T, H, E, MP, B>& m)
m = std::move(m).set(std::move(id), std::move(x));
}
if (size != m.size())
throw std::runtime_error{"duplicate ids?"};
LAGER_THROW(std::runtime_error{"duplicate ids?"});
}

template <typename Archive,
Expand Down Expand Up @@ -91,7 +93,7 @@ CEREAL_LOAD_FUNCTION_NAME(Archive& ar, immer::map<K, T, H, E, MP, B>& m)
m = std::move(m).set(std::move(k), std::move(x));
}
if (size != m.size())
throw std::runtime_error{"duplicate ids?"};
LAGER_THROW(std::runtime_error{"duplicate ids?"});
}

template <typename Archive,
Expand Down
4 changes: 3 additions & 1 deletion lager/extra/cereal/immer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <cereal/cereal.hpp>

#include <immer/set.hpp>
Expand All @@ -35,7 +37,7 @@ void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, immer::set<T, H, E, MP, B>& m)
m = std::move(m).insert(std::move(x));
}
if (size != m.size())
throw std::runtime_error{"duplicate items?"};
LAGER_THROW(std::runtime_error{"duplicate items?"});
}

template <typename Archive,
Expand Down
4 changes: 3 additions & 1 deletion lager/extra/cereal/variant_with_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#pragma once

#include <lager/config.hpp>

#include <boost/core/demangle.hpp>
#include <cereal/cereal.hpp>
#include <variant>
Expand Down Expand Up @@ -43,7 +45,7 @@ template <int N, class Variant, class... Args, class Archive>
typename std::enable_if<N == std::variant_size_v<Variant>, void>::type
load_variant(Archive& /*ar*/, const std::string&, Variant&)
{
throw ::cereal::Exception("Invalid variant type name");
LAGER_THROW(::cereal::Exception("Invalid variant type name"));
}

template <int N, class Variant, class H, class... T, class Archive>
Expand Down
Loading

0 comments on commit 63e148d

Please sign in to comment.