Commit d9c78b70 authored by Geoff Simmons's avatar Geoff Simmons

get rid of some of the repetitive code for retrieving pcre2 error messages

(could probably get rid of more)
parent 9efdb805
......@@ -104,6 +104,16 @@ WS_Front(struct ws * const ws)
return ws->f;
}
static inline int
get_pcre2_errmsg(struct ws * const restrict ws, int errcode,
char * restrict * const restrict buf)
{
unsigned bytes = WS_Reserve(ws, 0);
*buf = WS_Front(ws);
return pcre2_get_error_message(errcode, (PCRE2_UCHAR *)*buf,
(PCRE2_SIZE)bytes);
}
/* Event function */
int __match_proto__(vmod_event_f)
......@@ -291,11 +301,9 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
code = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
options, &err_code, &err_offset, ccontext);
if (code == NULL) {
char *buf = WS_Front(ctx->ws);
char *buf;
uintptr_t snap = WS_Snapshot(ctx->ws);
unsigned bytes = WS_Reserve(ctx->ws, 0);
ret = pcre2_get_error_message(err_code, (PCRE2_UCHAR *)buf,
(PCRE2_SIZE)bytes);
ret = get_pcre2_errmsg(ctx->ws, err_code, &buf);
if (ret == PCRE2_ERROR_BADDATA) {
WS_ReleaseP(ctx->ws, buf);
VERR(ctx, "Cannot compile '%s' in %s constructor "
......@@ -323,12 +331,9 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
options |= PCRE2_JIT_COMPLETE;
ret = pcre2_jit_compile(code, options);
if (ret != 0) {
/* XXX DRY */
char *buf = WS_Front(ctx->ws);
char *buf;
uintptr_t snap = WS_Snapshot(ctx->ws);
unsigned bytes = WS_Reserve(ctx->ws, 0);
ret = pcre2_get_error_message(ret, (PCRE2_UCHAR *)buf,
(PCRE2_SIZE)bytes);
ret = get_pcre2_errmsg(ctx->ws, ret, &buf);
if (ret == PCRE2_ERROR_BADDATA) {
WS_ReleaseP(ctx->ws, buf);
VERR(ctx, "Cannot jit-compile '%s' in %s "
......@@ -515,12 +520,9 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
if (ret >= 0)
return 1;
/* XXX DRY */
char *buf = WS_Front(ctx->ws);
char *buf;
uintptr_t snap = WS_Snapshot(ctx->ws);
unsigned bytes = WS_Reserve(ctx->ws, 0);
ret = pcre2_get_error_message(ret, (PCRE2_UCHAR *)buf,
(PCRE2_SIZE)bytes);
ret = get_pcre2_errmsg(ctx->ws, ret, &buf);
if (ret == PCRE2_ERROR_BADDATA) {
WS_ReleaseP(ctx->ws, buf);
VERR(ctx, "in %s.match() (unknown error code)",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment