diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 12:43:08 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 12:43:08 -0400 |
| commit | 0a7062e2d711b5ac7fb71e873f293a8f0d0e8bc6 (patch) | |
| tree | 912ae69dd9906dee11424433ff5367237296b0f6 /src/stdlib/lists.h | |
| parent | 5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 (diff) | |
Improved error messages
Diffstat (limited to 'src/stdlib/lists.h')
| -rw-r--r-- | src/stdlib/lists.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/stdlib/lists.h b/src/stdlib/lists.h index 74314aa6..1386b2fa 100644 --- a/src/stdlib/lists.h +++ b/src/stdlib/lists.h @@ -10,6 +10,16 @@ #include "util.h" // Convert negative indices to back-indexed without branching: index0 = index + (index < 0)*(len+1)) - 1 +#define List_get_checked(list_expr, index_expr, item_type, start, end) \ + ({ \ + const List_t list = list_expr; \ + int64_t index = index_expr; \ + int64_t off = index + (index < 0) * (list.length + 1) - 1; \ + if (unlikely(off < 0 || off >= list.length)) \ + fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", \ + (int64_t)list.length, ")\n"); \ + *(item_type *)(list.data + list.stride * off); \ + }) #define List_get(list_expr, index_expr, item_type, var, optional_expr, none_expr) \ ({ \ const List_t list = list_expr; \ |
