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