Skip to content

Commit

Permalink
Lacking realization of std::terminate. Call terminate in case if exce…
Browse files Browse the repository at this point in the history
…ption can't be thrown.
  • Loading branch information
kibergus committed Aug 12, 2012
1 parent 5b8f133 commit 5ed5175
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
16 changes: 8 additions & 8 deletions func_exception.cpp
Expand Up @@ -61,23 +61,23 @@ _UCXXEXPORT void __throw_invalid_argument(const char * message){
#else

_UCXXEXPORT void __throw_bad_alloc(){
abort();
std::terminate();
}

_UCXXEXPORT void __throw_out_of_range( const char * ){
abort();
_UCXXEXPORT void __throw_out_of_range( const char *){
std::terminate();
}

_UCXXEXPORT void __throw_overflow_error( const char * ){
abort();
_UCXXEXPORT void __throw_overflow_error( const char *){
std::terminate();
}

_UCXXEXPORT void __throw_length_error(const char * ){
abort();
_UCXXEXPORT void __throw_length_error(const char *){
std::terminate();
}

_UCXXEXPORT void __throw_invalid_argument(const char *){
abort();
std::terminate();
}

#endif
Expand Down
42 changes: 42 additions & 0 deletions terminate.cpp
@@ -0,0 +1,42 @@
/* Copyright (C) 2012 Alexey Guseynov
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <exception>
#include <cstdlib>

namespace {
std::terminate_handler __terminate_handler = std::abort;
}

void std::terminate () throw() {
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
try {
__terminate_handler ();
} catch(...) {}
#else
__terminate_handler ();
#endif
std::abort ();
}

std::terminate_handler std::set_terminate (std::terminate_handler func) throw() {
std::terminate_handler old = __terminate_handler;
__terminate_handler = func;
return old;
}
37 changes: 37 additions & 0 deletions unexpected.cpp
@@ -0,0 +1,37 @@
/* Copyright (C) 2012 Alexey Guseynov
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <exception>

namespace {
std::unexpected_handler __unexpected_handler = std::terminate;
}

void
std::unexpected ()
{
__unexpected_handler();
std::terminate ();
}

std::unexpected_handler std::set_unexpected (std::unexpected_handler func) throw() {
std::unexpected_handler old = __unexpected_handler;
__unexpected_handler = func;
return old;
}

0 comments on commit 5ed5175

Please sign in to comment.