Skip to content

Commit

Permalink
[stdc++] Use modm_assert for handling standard library errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Oct 9, 2018
1 parent 2d36bf3 commit 4b442f1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
80 changes: 80 additions & 0 deletions ext/gcc/assert.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2018, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <cstdint>
#include <bits/functexcept.h>
#include <modm/utils/bit_constants.hpp>

%% if options["use_modm_assert"]
#include <modm/architecture/interface/assert.hpp>

#define __modm_stdcpp_failure(failure) modm_assert(false, "stdc++", "stdc++", failure);__builtin_abort();
%% else
#define __modm_stdcpp_failure(failure) __builtin_abort();
%% endif

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

void
__throw_logic_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("logic_error"); }

void
__throw_domain_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("domain_error"); }

void
__throw_invalid_argument(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("invalid_argument"); }

void
__throw_length_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("length_error"); }

void
__throw_out_of_range(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("out_of_range"); }

void
__throw_runtime_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("runtime_error"); }

void
__throw_range_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("range_error"); }

void
__throw_overflow_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("overflow_error"); }

void
__throw_underflow_error(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("underflow_error"); }

void
__throw_bad_optional_access()
{ __modm_stdcpp_failure("bad_optional"); }

void
__throw_bad_variant_access(const char* __s __attribute__((unused)))
{ __modm_stdcpp_failure("bad_variant"); }

void
__throw_bad_function_call()
{ __modm_stdcpp_failure("bad_function_call"); }

void
__throw_bad_any_cast()
{ __modm_stdcpp_failure("bad_any_cast"); }
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
9 changes: 8 additions & 1 deletion ext/gcc/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ def prepare(module, options):
if target["platform"] != "avr":
return False

module.add_option(
BooleanOption(
name="use_modm_assert",
description="Assert on error in stdlib. Set to False to save flash.",
default=True))

return True


def build(env):
env.append_metadata_unique("include_path", "ext/gcc/libstdc++/include")

env.outbasepath = "modm/ext/gcc"
env.copy(".", ignore=env.ignore_files("*.lb", "*.md", "examples"))
env.copy(".", ignore=env.ignore_files("*.lb", "*.md", "*.in", "examples"))
env.template("assert.cpp.in", "assert.cpp")

0 comments on commit 4b442f1

Please sign in to comment.