Introduction
Introduction Statistics Contact Development Disclaimer Help
Make error messages for buffer_get_line more useful - ledit - Text editor (WIP)
git clone git://lumidify.org/ledit.git (fast, but not encrypted)
git clone https://lumidify.org/ledit.git (encrypted, but very slow)
git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/…
Log
Files
Refs
README
LICENSE
---
commit 625a8fad5969b39a1ba8484a68935c27ba4a05a7
parent 79d3040398e884808312473b32e65a02a04feeef
Author: lumidify <[email protected]>
Date: Fri, 6 Sep 2024 08:30:59 +0200
Make error messages for buffer_get_line more useful
Diffstat:
M assert.h | 2 ++
M buffer.c | 4 ++--
M buffer.h | 6 +++++-
M view.c | 6 ++----
M view.h | 13 +++++--------
5 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/assert.h b/assert.h
@@ -4,5 +4,7 @@
/* based on the assert found in OpenBSD */
void ledit_assert_impl(const char *file, int line, const char *func, const cha…
#define ledit_assert(e) ((e) ? (void)0 : ledit_assert_impl(__FILE__, __LINE__,…
+/* used by some functions like buffer_get_line */
+#define ledit_assert_manual(e, file, line, func) ((e) ? (void)0 : ledit_assert…
#endif
diff --git a/buffer.c b/buffer.c
@@ -688,8 +688,8 @@ buffer_delete_line_entries_base(ledit_buffer *buffer, size_…
}
ledit_line *
-buffer_get_line(ledit_buffer *buffer, size_t index) {
- ledit_assert(index < buffer->lines_num);
+buffer_get_line_impl(ledit_buffer *buffer, size_t index, const char *file, int…
+ ledit_assert_manual(index < buffer->lines_num, file, line, func);
return index < buffer->lines_gap ?
&buffer->lines[index] :
&buffer->lines[index + buffer->lines_cap - buffer->lines_num];
diff --git a/buffer.h b/buffer.h
@@ -142,8 +142,12 @@ void buffer_normalize_line(ledit_line *line);
* Get the line at logical index 'index'.
* The returned line is only valid until the next
* action that appends or deletes line entries.
+ * The macro is used in order to give better debug
+ * information when there is an error since so many
+ * functions call this one.
*/
-ledit_line *buffer_get_line(ledit_buffer *buffer, size_t index);
+ledit_line *buffer_get_line_impl(ledit_buffer *buffer, size_t index, const cha…
+#define buffer_get_line(buffer, index) (buffer_get_line_impl((buffer), (index)…
/*
* Tell views to recalculate the height of line 'line' and
diff --git a/view.c b/view.c
@@ -162,15 +162,13 @@ view_unlock(ledit_view *view) {
view->lock_text = NULL;
}
-#if 0
ledit_view_line *
-view_get_line(ledit_view *view, size_t index) {
- ledit_assert(index < view->lines_num);
+view_get_line_impl(ledit_view *view, size_t index, const char *file, int line,…
+ ledit_assert_manual(index < view->lines_num, file, line, func);
return index < view->lines_gap ?
&view->lines[index] :
&view->lines[index + view->lines_cap - view->lines_num];
}
-#endif
static void
move_line_gap(ledit_view *view, size_t index) {
diff --git a/view.h b/view.h
@@ -112,15 +112,12 @@ void view_unlock(ledit_view *view);
* Get the view line at the given index.
* The returned line is only valid until the next
* action that appends or deletes line entries.
+ * The macro is used in order to give better debug
+ * information when there is an error since so many
+ * functions call this one.
*/
-/* ledit_view_line *view_get_line(ledit_view *view, size_t index); */
-
-/* This is very hacky - it's so the actual function calling view_get_line is r…
- * There probably is a better way to do this.
- * FIXME: couldn't this just use the same trick that assert does?
- * WARNING: Since this is now a macro, the arguments are not allowed to have s…
- */
-#define view_get_line(view, index) (ledit_assert((index) < (view)->lines_num),…
+ledit_view_line *view_get_line_impl(ledit_view *view, size_t index, const char…
+#define view_get_line(view, index) (view_get_line_impl((view), (index), __FILE…
/*
* These notification functions are called by the buffer when text
You are viewing proxied material from lumidify.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.