Commit 1fa6b742 authored by Nils Goroll's avatar Nils Goroll

use a vsb to return vcc_regexp's result

to avoid micro-managing memory

Follow up cf20e04e
parent e66c5eb5
......@@ -322,7 +322,7 @@ void vcc_Parse_Init(struct vcc *);
sym_act_f vcc_Act_If;
/* vcc_utils.c */
const char *vcc_regexp(struct vcc *tl);
void vcc_regexp(struct vcc *tl, struct vsb *vgc_name);
void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport,
const char **ipv4, const char **ipv4_ascii, const char **ipv6,
const char **ipv6_ascii, const char **p_ascii, int maxips,
......
......@@ -288,8 +288,8 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, struct token *t,
{
struct expr *e2;
int all = sym->eval_priv == NULL ? 0 : 1;
const char *p;
char buf[128];
struct vsb vsb;
(void)t;
(void)fmt;
......@@ -298,10 +298,13 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, struct token *t,
ERRCHK(tl);
SkipToken(tl, ',');
ExpectErr(tl, CSTR);
p = vcc_regexp(tl);
bprintf(buf, "VRT_regsub(ctx, %d,\v+\n\v1,\n%s", all, p);
free(TRUST_ME(p));
*e = vcc_expr_edit(tl, STRING, buf, e2, NULL);
AN(VSB_new(&vsb, buf, sizeof buf, VSB_FIXEDLEN));
VSB_printf(&vsb, "VRT_regsub(ctx, %d,\v+\n\v1,\n", all);
vcc_regexp(tl, &vsb);
ERRCHK(tl);
AZ(VSB_finish(&vsb));
*e = vcc_expr_edit(tl, STRING, VSB_data(&vsb), e2, NULL);
SkipToken(tl, ',');
vcc_expr0(tl, &e2, STRING);
ERRCHK(tl);
......@@ -983,16 +986,18 @@ static void v_matchproto_(cmp_f)
cmp_regexp(struct vcc *tl, struct expr **e, const struct cmps *cp)
{
char buf[128];
const char *re;
struct vsb vsb;
*e = vcc_expr_edit(tl, STRING, "\vS", *e, NULL);
vcc_NextToken(tl);
ExpectErr(tl, CSTR);
re = vcc_regexp(tl);
AN(VSB_new(&vsb, buf, sizeof buf, VSB_FIXEDLEN));
VSB_printf(&vsb, "%sVRT_re_match(ctx, \v1, ", cp->emit);
vcc_regexp(tl, &vsb);
ERRCHK(tl);
bprintf(buf, "%sVRT_re_match(ctx, \v1, %s)", cp->emit, re);
free(TRUST_ME(re));
*e = vcc_expr_edit(tl, BOOL, buf, *e, NULL);
VSB_cat(&vsb, ")");
AZ(VSB_finish(&vsb));
*e = vcc_expr_edit(tl, BOOL, VSB_data(&vsb), *e, NULL);
}
static void v_matchproto_(cmp_f)
......
......@@ -47,10 +47,10 @@
/*--------------------------------------------------------------------*/
const char *
vcc_regexp(struct vcc *tl)
void
vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
{
char buf[BUFSIZ], *p;
char buf[BUFSIZ];
vre_t *t;
const char *error;
int erroroffset;
......@@ -58,18 +58,18 @@ vcc_regexp(struct vcc *tl)
Expect(tl, CSTR);
if (tl->err)
return (NULL);
return;
t = VRE_compile(tl->t->dec, 0, &error, &erroroffset);
if (t == NULL) {
VSB_printf(tl->sb,
"Regexp compilation error:\n\n%s\n\n", error);
vcc_ErrWhere(tl, tl->t);
return (NULL);
return;
}
VRE_free(&t);
bprintf(buf, "VGC_re_%u", tl->unique++);
p = TlAlloc(tl, strlen(buf) + 1);
strcpy(p, buf);
if (vgc_name)
VSB_cat(vgc_name, buf);
Fh(tl, 0, "static void *%s;\n", buf);
ifp = New_IniFin(tl);
......@@ -78,7 +78,6 @@ vcc_regexp(struct vcc *tl)
VSB_printf(ifp->ini, ");");
VSB_printf(ifp->fin, "\t\tVRT_re_fini(%s);", buf);
vcc_NextToken(tl);
return (p);
}
/*
......
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