assert: custom implementation

This commit is contained in:
Maxime Coste 2011-09-09 19:24:18 +00:00
parent 3caf962110
commit 030c5caf0a
7 changed files with 62 additions and 7 deletions

16
src/assert.cc Normal file
View File

@ -0,0 +1,16 @@
#include "assert.hh"
namespace Kakoune
{
assert_failed::assert_failed(const std::string& message)
{
m_message = message;
}
std::string assert_failed::description() const
{
return m_message;
}
}

31
src/assert.hh Normal file
View File

@ -0,0 +1,31 @@
#ifndef assert_hh_INCLUDED
#define assert_hh_INCLUDED
#include "exception.hh"
namespace Kakoune
{
struct assert_failed : logic_error
{
assert_failed(const std::string& message);
std::string description() const;
private:
std::string m_message;
};
}
#define STRINGIFY(X) #X
#define TOSTRING(X) STRINGIFY(X)
#ifdef assert
#undef assert
#endif
#define assert(condition) \
if (not (condition)) \
throw assert_failed("assert failed \"" #condition "\" at " __FILE__ ":" TOSTRING(__LINE__))
#endif // assert_hh_INCLUDED

View File

@ -2,8 +2,8 @@
#include "buffer_manager.hh" #include "buffer_manager.hh"
#include "window.hh" #include "window.hh"
#include "assert.hh"
#include <cassert>
#include <algorithm> #include <algorithm>
namespace Kakoune namespace Kakoune

View File

@ -1,7 +1,6 @@
#include "buffer_manager.hh" #include "buffer_manager.hh"
#include <cassert> #include "assert.hh"
#include "buffer.hh" #include "buffer.hh"
#include "window.hh" #include "window.hh"
#include "exception.hh" #include "exception.hh"

View File

@ -2,12 +2,13 @@
#include "buffer.hh" #include "buffer.hh"
#include "buffer_manager.hh" #include "buffer_manager.hh"
#include "assert.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <cstring> #include <cstring>
#include <cassert>
namespace Kakoune namespace Kakoune
{ {

View File

@ -1,13 +1,13 @@
#include <ncurses.h>
#include "window.hh" #include "window.hh"
#include "buffer.hh" #include "buffer.hh"
#include "file.hh" #include "file.hh"
#include "regex_selector.hh" #include "regex_selector.hh"
#include "command_manager.hh" #include "command_manager.hh"
#include "buffer_manager.hh" #include "buffer_manager.hh"
#include "assert.hh"
#include <unordered_map> #include <unordered_map>
#include <cassert> #include <ncurses.h>
using namespace Kakoune; using namespace Kakoune;
@ -331,6 +331,13 @@ int main()
} }
deinit_ncurses(); deinit_ncurses();
} }
catch (Kakoune::exception& error)
{
deinit_ncurses();
puts("uncaught exception:\n");
puts(error.description().c_str());
return -1;
}
catch (...) catch (...)
{ {
deinit_ncurses(); deinit_ncurses();

View File

@ -1,6 +1,8 @@
#ifndef utils_hh_INCLUDED #ifndef utils_hh_INCLUDED
#define utils_hh_INCLUDED #define utils_hh_INCLUDED
#include "exception.hh"
#include <memory> #include <memory>
namespace Kakoune namespace Kakoune
@ -37,7 +39,6 @@ bool operator== (const std::unique_ptr<T>& lhs, T* rhs)
return lhs.get() == rhs; return lhs.get() == rhs;
} }
} }
#endif // utils_hh_INCLUDED #endif // utils_hh_INCLUDED