diff --git a/src/assert.hh b/src/assert.hh index 52bdcf48..a65b09fd 100644 --- a/src/assert.hh +++ b/src/assert.hh @@ -12,17 +12,13 @@ void on_assert_failed(const char* message); #define TOSTRING(X) STRINGIFY(X) #define COMMA , -#ifdef assert -#undef assert -#endif - #ifdef KAK_DEBUG - #define assert(condition) \ + #define kak_assert(condition) \ if (not (condition)) \ on_assert_failed("assert failed \"" #condition \ "\" at " __FILE__ ":" TOSTRING(__LINE__)) #else - #define assert(condition) + #define kak_assert(condition) #endif diff --git a/src/buffer.cc b/src/buffer.cc index cce72005..72031db3 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -32,7 +32,7 @@ Buffer::Buffer(String name, Flags flags, std::vector lines) m_lines.reserve(lines.size()); for (auto& line : lines) { - assert(not line.empty() and line.back() == '\n'); + kak_assert(not line.empty() and line.back() == '\n'); m_lines.emplace_back(Line{ pos, std::move(line) }); pos += m_lines.back().length(); } @@ -59,7 +59,7 @@ Buffer::~Buffer() } BufferManager::instance().unregister_buffer(*this); - assert(m_change_listeners.empty()); + kak_assert(m_change_listeners.empty()); } String Buffer::display_name() const @@ -77,7 +77,7 @@ BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column, ByteCount Buffer::line_length(LineCount line) const { - assert(line < line_count()); + kak_assert(line < line_count()); ByteCount end = (line < line_count() - 1) ? m_lines[line + 1].start : character_count(); return end - m_lines[line].start; @@ -99,7 +99,7 @@ BufferCoord Buffer::clamp(const BufferCoord& line_and_column, BufferIterator Buffer::iterator_at_line_begin(LineCount line) const { line = Kakoune::clamp(line, 0_line, line_count()-1); - assert(line_length(line) > 0); + kak_assert(line_length(line) > 0); return BufferIterator(*this, { line, 0 }); } @@ -111,7 +111,7 @@ BufferIterator Buffer::iterator_at_line_begin(const BufferIterator& iterator) co BufferIterator Buffer::iterator_at_line_end(LineCount line) const { line = Kakoune::clamp(line, 0_line, line_count()-1); - assert(line_length(line) > 0); + kak_assert(line_length(line) > 0); return ++BufferIterator(*this, { line, line_length(line) - 1 }); } @@ -197,7 +197,7 @@ struct Buffer::Modification { case Insert: inverse_type = Erase; break; case Erase: inverse_type = Insert; break; - default: assert(false); + default: kak_assert(false); } return {inverse_type, position, content}; } @@ -222,7 +222,7 @@ bool Buffer::redo() if (m_history_cursor == m_history.end()) return false; - assert(m_current_undo_group.empty()); + kak_assert(m_current_undo_group.empty()); for (const Modification& modification : *m_history_cursor) apply_modification(modification); @@ -235,12 +235,12 @@ void Buffer::check_invariant() const { #ifdef KAK_DEBUG ByteCount start = 0; - assert(not m_lines.empty()); + kak_assert(not m_lines.empty()); for (auto& line : m_lines) { - assert(line.start == start); - assert(line.length() > 0); - assert(line.content.back() == '\n'); + kak_assert(line.start == start); + kak_assert(line.length() > 0); + kak_assert(line.content.back() == '\n'); start += line.length(); } #endif @@ -248,7 +248,7 @@ void Buffer::check_invariant() const void Buffer::do_insert(const BufferIterator& pos, const String& content) { - assert(pos.is_valid()); + kak_assert(pos.is_valid()); if (content.empty()) return; @@ -327,8 +327,8 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content) void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end) { - assert(begin.is_valid()); - assert(end.is_valid()); + kak_assert(begin.is_valid()); + kak_assert(end.is_valid()); ++m_timestamp; const ByteCount length = end - begin; String prefix = m_lines[begin.line()].content.substr(0, begin.column()); @@ -360,7 +360,7 @@ void Buffer::apply_modification(const Modification& modification) if (not pos.is_end() and pos.column() == m_lines[pos.line()].length()) pos = { pos.buffer(), { pos.line() + 1, 0 }}; - assert(pos.is_valid()); + kak_assert(pos.is_valid()); switch (modification.type) { case Modification::Insert: @@ -372,12 +372,12 @@ void Buffer::apply_modification(const Modification& modification) { ByteCount count = content.length(); BufferIterator end = pos + count; - assert(string(pos, end) == content); + kak_assert(string(pos, end) == content); do_erase(pos, end); break; } default: - assert(false); + kak_assert(false); } } diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index 1a9b5a95..e5b7c95a 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -9,12 +9,12 @@ namespace Kakoune inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord) : m_buffer(&buffer), m_coord(coord) { - assert(is_valid()); + kak_assert(is_valid()); } inline const Buffer& BufferIterator::buffer() const { - assert(m_buffer); + kak_assert(m_buffer); return *m_buffer; } @@ -30,7 +30,7 @@ inline bool BufferIterator::is_valid() const inline void BufferIterator::clamp(bool avoid_eol) { - assert(m_buffer); + kak_assert(m_buffer); m_coord = m_buffer->clamp(m_coord, avoid_eol); } @@ -46,25 +46,25 @@ inline bool BufferIterator::operator!=(const BufferIterator& iterator) const inline bool BufferIterator::operator<(const BufferIterator& iterator) const { - assert(m_buffer == iterator.m_buffer); + kak_assert(m_buffer == iterator.m_buffer); return (m_coord < iterator.m_coord); } inline bool BufferIterator::operator<=(const BufferIterator& iterator) const { - assert(m_buffer == iterator.m_buffer); + kak_assert(m_buffer == iterator.m_buffer); return (m_coord <= iterator.m_coord); } inline bool BufferIterator::operator>(const BufferIterator& iterator) const { - assert(m_buffer == iterator.m_buffer); + kak_assert(m_buffer == iterator.m_buffer); return (m_coord > iterator.m_coord); } inline bool BufferIterator::operator>=(const BufferIterator& iterator) const { - assert(m_buffer == iterator.m_buffer); + kak_assert(m_buffer == iterator.m_buffer); return (m_coord >= iterator.m_coord); } @@ -75,20 +75,20 @@ inline char BufferIterator::operator*() const inline ByteCount BufferIterator::offset() const { - assert(m_buffer); + kak_assert(m_buffer); return line() >= m_buffer->line_count() ? m_buffer->character_count() : m_buffer->m_lines[line()].start + column(); } inline size_t BufferIterator::operator-(const BufferIterator& iterator) const { - assert(m_buffer == iterator.m_buffer); + kak_assert(m_buffer == iterator.m_buffer); return (size_t)(int)(offset() - iterator.offset()); } inline BufferIterator BufferIterator::operator+(ByteCount size) const { - assert(m_buffer); + kak_assert(m_buffer); if (size >= 0) { ByteCount o = std::min(m_buffer->character_count(), offset() + size); @@ -105,7 +105,7 @@ inline BufferIterator BufferIterator::operator+(ByteCount size) const inline BufferIterator BufferIterator::operator-(ByteCount size) const { - assert(m_buffer); + kak_assert(m_buffer); if (size >= 0) { ByteCount o = std::max(0_byte, offset() - size); @@ -114,7 +114,7 @@ inline BufferIterator BufferIterator::operator-(ByteCount size) const if (m_buffer->m_lines[i].start <= o) return BufferIterator(*m_buffer, { i, o - m_buffer->m_lines[i].start }); } - assert(false); + kak_assert(false); } return operator+(-size); } @@ -175,22 +175,22 @@ inline BufferIterator BufferIterator::operator--(int) inline BufferIterator& BufferIterator::operator=(const BufferCoord& coord) { m_coord = coord; - assert(is_valid()); + kak_assert(is_valid()); return *this; } inline bool BufferIterator::is_begin() const { - assert(m_buffer); + kak_assert(m_buffer); return m_coord.line == 0 and m_coord.column == 0; } inline bool BufferIterator::is_end() const { - assert(m_buffer); + kak_assert(m_buffer); if (m_coord.line == m_buffer->line_count()) { - assert(m_coord.column == 0); + kak_assert(m_coord.column == 0); return true; } return offset() == m_buffer->character_count(); diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 7e62acfb..00dcfad2 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -43,7 +43,7 @@ void BufferManager::unregister_buffer(Buffer& buffer) return; } } - assert(false); + kak_assert(false); } Buffer* BufferManager::get_buffer_ifp(const String& name) @@ -71,7 +71,7 @@ void BufferManager::set_last_used_buffer(Buffer& buffer) auto it = m_buffers.begin(); while (*it != &buffer and it != m_buffers.end()) ++it; - assert(it != m_buffers.end()); + kak_assert(it != m_buffers.end()); m_buffers.erase(it); m_buffers.emplace(m_buffers.begin(), &buffer); } diff --git a/src/client_manager.cc b/src/client_manager.cc index 0cf05967..6db8afd4 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -19,7 +19,7 @@ struct ClientManager::Client input_handler(*user_interface), name(std::move(name)) { - assert(not this->name.empty()); + kak_assert(not this->name.empty()); context().change_editor(window); } Client(Client&&) = delete; @@ -106,7 +106,7 @@ void ClientManager::remove_client_by_context(Context& context) return; } } - assert(false); + kak_assert(false); } Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer) diff --git a/src/color.cc b/src/color.cc index b5214eb2..f1b3ef8a 100644 --- a/src/color.cc +++ b/src/color.cc @@ -34,7 +34,7 @@ String color_to_str(const Color& color) case Color::Cyan: return "cyan"; case Color::White: return "white"; } - assert(false); + kak_assert(false); return "default"; } diff --git a/src/command_manager.cc b/src/command_manager.cc index 7817fe4a..a5c590e7 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -324,7 +324,7 @@ Completions CommandManager::complete(const Context& context, return result; } - assert(not tokens.empty()); + kak_assert(not tokens.empty()); if (tokens[0].type() != Token::Type::Raw) return Completions(); @@ -357,7 +357,7 @@ CandidateList PerArgumentCommandCompleter::operator()(const Context& context, return CandidateList(); // it is possible to try to complete a new argument - assert(token_to_complete <= params.size()); + kak_assert(token_to_complete <= params.size()); const String& argument = token_to_complete < params.size() ? params[token_to_complete] : String(); diff --git a/src/commands.cc b/src/commands.cc index 63ec8ddc..c46f1596 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -66,7 +66,7 @@ Buffer* open_fifo(const String& name , const String& filename, Context& context) ClientManager::instance().redraw_clients(); if (count <= 0) { - assert(buffer->flags() & Buffer::Flags::Fifo); + kak_assert(buffer->flags() & Buffer::Flags::Fifo); buffer->flags() &= ~Buffer::Flags::Fifo; close(watcher.fd()); delete &watcher; @@ -804,7 +804,7 @@ public: Key get_key() override { - assert(m_pos < m_keys.size()); + kak_assert(m_pos < m_keys.size()); return m_keys[m_pos++]; } bool is_key_available() override { return m_pos < m_keys.size(); } diff --git a/src/debug.cc b/src/debug.cc index 9cfa0cd8..b0d2c4a7 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -15,7 +15,7 @@ static Buffer& get_or_create_debug_buffer() if (not buffer) buffer = new Buffer(debug_buffer_name, Buffer::Flags::NoUndo); - assert(buffer); + kak_assert(buffer); return *buffer; } diff --git a/src/display_buffer.cc b/src/display_buffer.cc index f518ab50..929fb9b4 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -7,9 +7,9 @@ namespace Kakoune DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos) { - assert(it->content.type() == AtomContent::BufferRange); - assert(it->content.begin() < pos); - assert(it->content.end() > pos); + kak_assert(it->content.type() == AtomContent::BufferRange); + kak_assert(it->content.begin() < pos); + kak_assert(it->content.end() > pos); DisplayAtom atom = *it; atom.content.m_end = pos; @@ -68,8 +68,8 @@ void DisplayBuffer::compute_range() m_range.second = atom.content.end(); } } - assert(m_range.first.is_valid() and m_range.second.is_valid()); - assert(m_range.first <= m_range.second); + kak_assert(m_range.first.is_valid() and m_range.second.is_valid()); + kak_assert(m_range.first <= m_range.second); } void DisplayBuffer::optimize() diff --git a/src/display_buffer.hh b/src/display_buffer.hh index 49bf67cb..ee0c32d1 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -54,7 +54,7 @@ public: case ReplacedBufferRange: return m_text; } - assert(false); + kak_assert(false); return 0; } @@ -68,25 +68,25 @@ public: case ReplacedBufferRange: return m_text.char_length(); } - assert(false); + kak_assert(false); return 0; } const BufferIterator& begin() const { - assert(has_buffer_range()); + kak_assert(has_buffer_range()); return m_begin; } const BufferIterator& end() const { - assert(has_buffer_range()); + kak_assert(has_buffer_range()); return m_end; } void replace(String text) { - assert(m_type == BufferRange); + kak_assert(m_type == BufferRange); m_type = ReplacedBufferRange; m_text = std::move(text); } diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index a258ddd7..1490dd9c 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -24,7 +24,7 @@ void DynamicSelectionList::check_invariant() const const Buffer* buf = &buffer(); for (auto& sel : *this) { - assert(buf == &sel.buffer()); + kak_assert(buf == &sel.buffer()); sel.check_invariant(); } #endif @@ -70,7 +70,7 @@ struct UpdateInsert { BufferCoord coord = it.coord(); if (assume_different_line) - assert(begin.line < coord.line); + kak_assert(begin.line < coord.line); if (not assume_greater_than_begin and coord < begin) return; if (not assume_different_line and begin.line == coord.line) @@ -91,7 +91,7 @@ struct UpdateErase if (not assume_greater_than_begin and coord < begin) return; if (assume_different_line) - assert(end.line < coord.line); + kak_assert(end.line < coord.line); if (not assume_different_line and coord <= end) coord = it.buffer().clamp(begin); else diff --git a/src/editor.cc b/src/editor.cc index 6b058f3a..b0f5fa08 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -72,7 +72,7 @@ static BufferIterator prepare_insert(Buffer& buffer, const Selection& sel, return pos; } } - assert(false); + kak_assert(false); return BufferIterator{}; } @@ -162,7 +162,7 @@ static void sort_and_merge_overlapping(SelectionList& selections, size_t& main_s void Editor::move_selections(CharCount offset, SelectMode mode) { - assert(mode == SelectMode::Replace or mode == SelectMode::Extend); + kak_assert(mode == SelectMode::Replace or mode == SelectMode::Extend); for (auto& sel : m_selections) { auto last = sel.last(); @@ -178,7 +178,7 @@ void Editor::move_selections(CharCount offset, SelectMode mode) void Editor::move_selections(LineCount offset, SelectMode mode) { - assert(mode == SelectMode::Replace or mode == SelectMode::Extend); + kak_assert(mode == SelectMode::Replace or mode == SelectMode::Extend); for (auto& sel : m_selections) { BufferCoord pos = sel.last().coord(); @@ -257,7 +257,7 @@ void Editor::select(const Selection& selection, SelectMode mode) sort_and_merge_overlapping(m_selections, m_main_sel); } else - assert(false); + kak_assert(false); check_invariant(); } @@ -352,15 +352,15 @@ public: void on_insert(const BufferIterator& begin, const BufferIterator& end) { - assert(begin.is_valid()); - assert(end.is_valid()); + kak_assert(begin.is_valid()); + kak_assert(end.is_valid()); m_first = begin; m_last = utf8::previous(end); } void on_erase(const BufferIterator& begin, const BufferIterator& end) { - assert(begin.is_valid()); + kak_assert(begin.is_valid()); m_first = begin; if (m_first >= m_buffer.end()) m_first = utf8::previous(m_buffer.end()); @@ -405,11 +405,11 @@ bool Editor::redo() void Editor::check_invariant() const { #ifdef KAK_DEBUG - assert(not m_selections.empty()); - assert(m_main_sel < m_selections.size()); + kak_assert(not m_selections.empty()); + kak_assert(m_main_sel < m_selections.size()); m_selections.check_invariant(); buffer().check_invariant(); - assert(std::is_sorted(m_selections.begin(), m_selections.end(), compare_selections)); + kak_assert(std::is_sorted(m_selections.begin(), m_selections.end(), compare_selections)); #endif } @@ -420,7 +420,7 @@ void Editor::begin_edition() void Editor::end_edition() { - assert(m_edition_level > 0); + kak_assert(m_edition_level > 0); if (m_edition_level == 1) m_buffer->commit_undo_group(); @@ -479,7 +479,7 @@ IncrementalInserter::IncrementalInserter(Editor& editor, InsertMode mode) last = first; break; case InsertMode::InsertAtNextLineBegin: - assert(false); // not implemented + kak_assert(false); // not implemented break; } if (first.underlying_iterator().is_end()) diff --git a/src/event_manager.cc b/src/event_manager.cc index 280f4200..d23659f2 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -40,8 +40,8 @@ EventManager::EventManager() EventManager::~EventManager() { - assert(m_fd_watchers.empty()); - assert(m_timers.empty()); + kak_assert(m_fd_watchers.empty()); + kak_assert(m_timers.empty()); } void EventManager::handle_next_events() diff --git a/src/filters.cc b/src/filters.cc index 2458dc29..26ff5969 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -44,7 +44,7 @@ void expand_tabulations(Buffer& buffer, Selection& selection, String& content) for (auto line_it = buffer.iterator_at_line_begin(position); line_it != position; ++line_it) { - assert(*line_it != '\n'); + kak_assert(*line_it != '\n'); if (*line_it == '\t') column += tabstop - (column % tabstop); else diff --git a/src/function_registry.hh b/src/function_registry.hh index 058c4aa3..291ba0c4 100644 --- a/src/function_registry.hh +++ b/src/function_registry.hh @@ -20,7 +20,7 @@ class FunctionRegistry public: void register_func(const String& name, const FunctionType& function) { - assert(not m_functions.contains(name)); + kak_assert(not m_functions.contains(name)); m_functions.append(std::make_pair(name, function)); } diff --git a/src/highlighters.cc b/src/highlighters.cc index 0e56d1e2..b50ca98a 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -239,7 +239,7 @@ void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buf for (auto line_it = it.buffer().iterator_at_line_begin(it); line_it != it; ++line_it) { - assert(*line_it != '\n'); + kak_assert(*line_it != '\n'); if (*line_it == '\t') column += tabstop - (column % tabstop); else diff --git a/src/input_handler.cc b/src/input_handler.cc index c8a1466f..95071bd2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -127,7 +127,7 @@ public: void insert_from(CharCount start, const String& str) { - assert(start <= m_cursor_pos); + kak_assert(start <= m_cursor_pos); m_line = m_line.substr(0, start) + str + m_line.substr(m_cursor_pos); m_cursor_pos = start + str.char_length(); @@ -148,7 +148,7 @@ private: static DisplayLine line_with_cursor(const String& str, CharCount cursor_pos) { - assert(cursor_pos <= str.char_length()); + kak_assert(cursor_pos <= str.char_length()); if (cursor_pos == str.char_length()) return DisplayLine{-1, { {str, get_color("StatusLine")}, {" "_str, get_color("StatusCursor")} }}; @@ -654,7 +654,7 @@ private: if (not m_completions.is_valid()) return false; - assert(cursor >= m_completions.begin); + kak_assert(cursor >= m_completions.begin); m_matching_candidates = m_completions.candidates; m_current_candidate = m_matching_candidates.size(); @@ -799,7 +799,7 @@ void InputHandler::repeat_last_insert() m_mode.reset(new InputModes::Insert(*this, m_last_insert.first)); for (auto& key : keys) m_mode->on_key(key); - assert(dynamic_cast(m_mode.get()) != nullptr); + kak_assert(dynamic_cast(m_mode.get()) != nullptr); } void InputHandler::prompt(const String& prompt, ColorPair prompt_colors, @@ -857,7 +857,7 @@ void InputHandler::handle_available_inputs() void InputHandler::start_recording(char reg) { - assert(m_recording_reg == 0); + kak_assert(m_recording_reg == 0); m_recorded_keys = ""; m_recording_reg = reg; } @@ -869,7 +869,7 @@ bool InputHandler::is_recording() const void InputHandler::stop_recording() { - assert(m_recording_reg != 0); + kak_assert(m_recording_reg != 0); RegisterManager::instance()[m_recording_reg] = memoryview(m_recorded_keys); m_recording_reg = 0; } diff --git a/src/keys.cc b/src/keys.cc index 116fcdf6..91888cb9 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -8,7 +8,7 @@ Key canonicalize_ifn(Key key) { if (key.key > 0 and key.key < 27) { - assert(key.modifiers == Key::Modifiers::None); + kak_assert(key.modifiers == Key::Modifiers::None); key.modifiers = Key::Modifiers::Control; key.key = key.key - 1 + 'a'; } diff --git a/src/main.cc b/src/main.cc index 40f54c28..2b77fd91 100644 --- a/src/main.cc +++ b/src/main.cc @@ -324,7 +324,7 @@ static InsertMode adapt_for_linewise(InsertMode mode) if (mode == InsertMode::Replace) return InsertMode::Replace; - assert(false); + kak_assert(false); return InsertMode::Insert; } @@ -409,7 +409,7 @@ void do_join(Context& context) { SelectionList res = select_all_matches(sel, Regex{"\n\\h*"}); // remove last end of line if selected - assert(std::is_sorted(res.begin(), res.end(), + kak_assert(std::is_sorted(res.begin(), res.end(), [](const Selection& lhs, const Selection& rhs) { return lhs.begin() < rhs.begin(); })); if (not res.empty() and res.back().end() == sel.buffer().end()) @@ -614,7 +614,7 @@ String runtime_directory() char buffer[2048]; #if defined(__linux__) ssize_t res = readlink("/proc/self/exe", buffer, 2048); - assert(res != -1); + kak_assert(res != -1); buffer[res] = '\0'; #elif defined(__APPLE__) uint32_t bufsize = 2048; diff --git a/src/ncurses.cc b/src/ncurses.cc index 1425c47c..1dc22708 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -302,7 +302,7 @@ void NCursesUI::print_status(const DisplayLine& status) void NCursesUI::draw_menu() { - assert(m_menu_win); + kak_assert(m_menu_win); auto menu_fg = get_color_pair(m_menu_fg); auto menu_bg = get_color_pair(m_menu_bg); @@ -347,8 +347,8 @@ void NCursesUI::menu_show(const memoryview& choices, DisplayCoord anchor, ColorPair fg, ColorPair bg, MenuStyle style) { - assert(m_menu_win == nullptr); - assert(m_choices.empty()); + kak_assert(m_menu_win == nullptr); + kak_assert(m_choices.empty()); m_menu_fg = fg; m_menu_bg = bg; @@ -470,7 +470,7 @@ static DisplayCoord compute_pos(const DisplayCoord& anchor, void NCursesUI::info_show(const String& content, DisplayCoord anchor, ColorPair colors, MenuStyle style) { - assert(m_info_win == nullptr); + kak_assert(m_info_win == nullptr); DisplayCoord size = compute_needed_size(content); if (style == MenuStyle::Prompt) diff --git a/src/option_manager.cc b/src/option_manager.cc index 453f88db..1e84e67a 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -20,19 +20,19 @@ OptionManager::~OptionManager() if (m_parent) m_parent->unregister_watcher(*this); - assert(m_watchers.empty()); + kak_assert(m_watchers.empty()); } void OptionManager::register_watcher(OptionManagerWatcher& watcher) { - assert(not contains(m_watchers, &watcher)); + kak_assert(not contains(m_watchers, &watcher)); m_watchers.push_back(&watcher); } void OptionManager::unregister_watcher(OptionManagerWatcher& watcher) { auto it = find(m_watchers.begin(), m_watchers.end(), &watcher); - assert(it != m_watchers.end()); + kak_assert(it != m_watchers.end()); m_watchers.erase(it); } diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index c02e895c..959ec3ed 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -43,7 +43,7 @@ ParametersParser::ParametersParser(const ParameterList& params, bool ParametersParser::has_option(const String& name) const { - assert(m_options.find(name) != m_options.end()); + kak_assert(m_options.find(name) != m_options.end()); for (auto& param : m_params) { if (param[0] == '-' and param.substr(1_byte) == name) @@ -59,8 +59,8 @@ const String& ParametersParser::option_value(const String& name) const { #ifdef KAK_DEBUG auto it = m_options.find(name); - assert(it != m_options.end()); - assert(it->second == true); + kak_assert(it != m_options.end()); + kak_assert(it->second == true); #endif for (size_t i = 0; i < m_params.size(); ++i) @@ -82,7 +82,7 @@ size_t ParametersParser::positional_count() const const String& ParametersParser::operator[] (size_t index) const { - assert(index < positional_count()); + kak_assert(index < positional_count()); return m_params[m_positional_indices[index]]; } diff --git a/src/parameters_parser.hh b/src/parameters_parser.hh index ca159922..76f30ca7 100644 --- a/src/parameters_parser.hh +++ b/src/parameters_parser.hh @@ -97,19 +97,19 @@ struct ParametersParser bool operator==(const iterator& other) const { - assert(&m_parser == &other.m_parser); + kak_assert(&m_parser == &other.m_parser); return m_index == other.m_index; } bool operator!=(const iterator& other) const { - assert(&m_parser == &other.m_parser); + kak_assert(&m_parser == &other.m_parser); return m_index != other.m_index; } bool operator<(const iterator& other) const { - assert(&m_parser == &other.m_parser); + kak_assert(&m_parser == &other.m_parser); return m_index < other.m_index; } diff --git a/src/register_manager.cc b/src/register_manager.cc index 11bae66a..2407d5d0 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -66,7 +66,7 @@ Register& RegisterManager::operator[](char reg) void RegisterManager::register_dynamic_register(char reg, RegisterRetriever function) { auto& reg_ptr = m_registers[reg]; - assert(not reg_ptr); + kak_assert(not reg_ptr); reg_ptr.reset(new DynamicRegister(std::move(function))); } diff --git a/src/remote.cc b/src/remote.cc index 01b6760b..d8c07e9a 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -133,7 +133,7 @@ String read(int socket) if (length == 0) return String{}; char buffer[2048]; - assert(length < 2048); + kak_assert(length < 2048); read(socket, buffer, (int)length); return String(buffer, buffer+(int)length); } diff --git a/src/selection.cc b/src/selection.cc index 7868fb15..065aaefc 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -32,10 +32,10 @@ String Range::content() const void Range::check_invariant() const { #ifdef KAK_DEBUG - assert(m_first.is_valid()); - assert(m_last.is_valid()); - assert(utf8::is_character_start(m_first)); - assert(utf8::is_character_start(m_last)); + kak_assert(m_first.is_valid()); + kak_assert(m_last.is_valid()); + kak_assert(utf8::is_character_start(m_first)); + kak_assert(utf8::is_character_start(m_last)); #endif } diff --git a/src/shell_manager.cc b/src/shell_manager.cc index dce3a13a..265b97e8 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -92,8 +92,8 @@ String ShellManager::pipe(const String& input, else if (match[2].matched) name = String(match[2].first, match[2].second); else - assert(false); - assert(name.length() > 0); + kak_assert(false); + kak_assert(name.length() > 0); auto local_var = env_vars.find(name); if (local_var != env_vars.end()) diff --git a/src/unit_tests.cc b/src/unit_tests.cc index b4bbead8..7c45c3d0 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -11,43 +11,43 @@ void test_buffer() Buffer empty_buffer("empty", Buffer::Flags::None, {}); Buffer buffer("test", Buffer::Flags::None, { "allo ?\n", "mais que fais la police\n", " hein ?\n", " youpi\n" }); - assert(buffer.line_count() == 4); + kak_assert(buffer.line_count() == 4); BufferIterator i = buffer.begin(); - assert(*i == 'a'); + kak_assert(*i == 'a'); i += 6; - assert(i.coord() == BufferCoord{0 COMMA 6}); + kak_assert(i.coord() == BufferCoord{0 COMMA 6}); i += 1; - assert(i.coord() == BufferCoord{1 COMMA 0}); + kak_assert(i.coord() == BufferCoord{1 COMMA 0}); --i; - assert(i.coord() == BufferCoord{0 COMMA 6}); + kak_assert(i.coord() == BufferCoord{0 COMMA 6}); ++i; - assert(i.coord() == BufferCoord{1 COMMA 0}); + kak_assert(i.coord() == BufferCoord{1 COMMA 0}); buffer.insert(i, "tchou kanaky\n"); - assert(buffer.line_count() == 5); + kak_assert(buffer.line_count() == 5); BufferIterator begin = buffer.iterator_at({ 4, 1 }); BufferIterator end = buffer.iterator_at({ 4, 5 }) + 1; String str = buffer.string(begin, end); - assert(str == "youpi"); + kak_assert(str == "youpi"); // check insert at end behaviour: auto add end of line if necessary begin = buffer.end() - 1; buffer.insert(buffer.end(), "tchou"); - assert(buffer.string(begin+1, buffer.end()) == "tchou\n"); + kak_assert(buffer.string(begin+1, buffer.end()) == "tchou\n"); begin = buffer.end() - 1; buffer.insert(buffer.end(), "kanaky\n"); - assert(buffer.string(begin+1, buffer.end()) == "kanaky\n"); + kak_assert(buffer.string(begin+1, buffer.end()) == "kanaky\n"); buffer.commit_undo_group(); buffer.erase(begin+1, buffer.end()); buffer.insert(buffer.end(), "mutch\n"); buffer.commit_undo_group(); buffer.undo(); - assert(buffer.string(buffer.end() - 7, buffer.end()) == "kanaky\n"); + kak_assert(buffer.string(buffer.end() - 7, buffer.end()) == "kanaky\n"); buffer.redo(); - assert(buffer.string(buffer.end() - 6, buffer.end()) == "mutch\n"); + kak_assert(buffer.string(buffer.end() - 6, buffer.end()) == "mutch\n"); } void test_editor() @@ -61,7 +61,7 @@ void test_editor() editor.multi_select(std::bind(select_all_matches, std::placeholders::_1, Regex{"\\n\\h*"})); for (auto& sel : editor.selections()) { - assert(*sel.begin() == '\n'); + kak_assert(*sel.begin() == '\n'); editor.buffer().erase(sel.begin(), sel.end()); } } @@ -70,7 +70,7 @@ void test_editor() Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() }; editor.select(sel, SelectMode::Replace); editor.insert("",InsertMode::Replace); - assert(not editor.main_selection().first().is_end()); + kak_assert(not editor.main_selection().first().is_end()); } void test_incremental_inserter() @@ -81,35 +81,35 @@ void test_incremental_inserter() editor.select(buffer.begin()); { IncrementalInserter inserter(editor, InsertMode::OpenLineAbove); - assert(editor.is_editing()); - assert(editor.selections().size() == 1); - assert(editor.selections().front().first() == buffer.begin()); - assert(editor.selections().front().last() == buffer.begin()); - assert(*buffer.begin() == L'\n'); + kak_assert(editor.is_editing()); + kak_assert(editor.selections().size() == 1); + kak_assert(editor.selections().front().first() == buffer.begin()); + kak_assert(editor.selections().front().last() == buffer.begin()); + kak_assert(*buffer.begin() == L'\n'); } - assert(not editor.is_editing()); + kak_assert(not editor.is_editing()); } void test_utf8() { String str = "maïs mélange bientôt"; - assert(utf8::distance(str.begin(), str.end()) == 20); - assert(utf8::codepoint(str.begin() + 2) == 0x00EF); + kak_assert(utf8::distance(str.begin(), str.end()) == 20); + kak_assert(utf8::codepoint(str.begin() + 2) == 0x00EF); } void test_string() { - assert(int_to_str(124) == "124"); - assert(int_to_str(-129) == "-129"); - assert(int_to_str(0) == "0"); + kak_assert(int_to_str(124) == "124"); + kak_assert(int_to_str(-129) == "-129"); + kak_assert(int_to_str(0) == "0"); - assert(String("youpi ") + "matin" == "youpi matin"); + kak_assert(String("youpi ") + "matin" == "youpi matin"); std::vector splited = split("youpi:matin::tchou", ':'); - assert(splited[0] == "youpi"); - assert(splited[1] == "matin"); - assert(splited[2] == ""); - assert(splited[3] == "tchou"); + kak_assert(splited[0] == "youpi"); + kak_assert(splited[1] == "matin"); + kak_assert(splited[2] == ""); + kak_assert(splited[3] == "tchou"); } void test_keys() @@ -124,7 +124,7 @@ void test_keys() for (auto& key : keys) keys_as_str += key_to_str(key); auto parsed_keys = parse_keys(keys_as_str); - assert(keys == parsed_keys); + kak_assert(keys == parsed_keys); } void run_unit_tests() diff --git a/src/utf8.hh b/src/utf8.hh index ebbb430f..4113c9fe 100644 --- a/src/utf8.hh +++ b/src/utf8.hh @@ -95,7 +95,7 @@ namespace InvalidBytePolicy struct Assert { - Codepoint operator()(char byte) const { assert(false); return byte; } + Codepoint operator()(char byte) const { kak_assert(false); return byte; } }; struct Pass diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh index 71681dcc..7b735aa5 100644 --- a/src/utf8_iterator.hh +++ b/src/utf8_iterator.hh @@ -100,7 +100,7 @@ public: CharCount operator-(utf8_iterator other) const { - //assert(other < *this); + //kak_assert(other < *this); check_invariant(); other.check_invariant(); CharCount dist = 0; @@ -124,7 +124,7 @@ protected: void check_invariant() const { // always point to a character first byte; - // assert(is_character_start(it)); + // kak_assert(is_character_start(it)); } private: diff --git a/src/utils.hh b/src/utils.hh index bd52bf0c..117adf75 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -41,13 +41,13 @@ public: protected: Singleton() { - assert(not ms_instance); + kak_assert(not ms_instance); ms_instance = static_cast(this); } ~Singleton() { - assert(ms_instance == this); + kak_assert(ms_instance == this); ms_instance = nullptr; } @@ -134,10 +134,10 @@ class SafeCountable public: #ifdef KAK_DEBUG SafeCountable() : m_count(0) {} - ~SafeCountable() { assert(m_count == 0); } + ~SafeCountable() { kak_assert(m_count == 0); } void inc_safe_count() const { ++m_count; } - void dec_safe_count() const { --m_count; assert(m_count >= 0); } + void dec_safe_count() const { --m_count; kak_assert(m_count >= 0); } private: mutable int m_count; diff --git a/src/window.cc b/src/window.cc index 4abcab75..285cf0ff 100644 --- a/src/window.cc +++ b/src/window.cc @@ -149,7 +149,7 @@ void Window::scroll_to_keep_cursor_visible_ifn() if (last != buffer().end()) { // the cursor should always be visible. - assert(false); + kak_assert(false); } }