aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-10-26 20:26:58 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-10-26 20:26:58 -0400
commit645081f64e9bc1f996326b74aed2f5cda2c62437 (patch)
treeeecca372f6dcbac0f7041ada0bc352fedc9f201c /match.c
parent9380a54d7cf1795b26be79cd7abbb74a415d0788 (diff)
Fixed lua to work with new API
Diffstat (limited to 'match.c')
-rw-r--r--match.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/match.c b/match.c
index c07086f..1e895a5 100644
--- a/match.c
+++ b/match.c
@@ -74,6 +74,7 @@ static size_t recycle_all_matches(void);
__attribute__((format(printf,1,2)))
static inline void match_error(const char *fmt, ...)
{
+ if (error_message) free(error_message);
va_list args;
va_start(args, fmt);
vasprintf(&error_message, fmt, args);
@@ -875,7 +876,8 @@ int each_match(bp_match_callback callback, void *userdata, const char *start, co
return num_matches;
}
- if (setjmp(error_jump) == 0) {
+ bool hit_error = setjmp(error_jump) != 0;
+ if (!hit_error) {
for (const char *str = start; str <= end; ) {
match_t *m = _next_match(&ctx, str, pat, skip);
if (!m) break;
@@ -888,17 +890,18 @@ int each_match(bp_match_callback callback, void *userdata, const char *start, co
str = m->end > str ? m->end : next_char(str, end);
recycle_all_matches();
}
- } else {
- if (error_handler)
- error_handler(error_message ? error_message : "An unknown error occurred");
+ }
+ cache_destroy(&ctx);
+ free_all_matches();
+
+ if (hit_error && error_handler) {
+ error_handler(error_message ? error_message : "An unknown error occurred");
}
if (error_message) {
free(error_message);
error_message = NULL;
}
- cache_destroy(&ctx);
- free_all_matches();
return num_matches;
}