Commit ddd9f277 authored by Geoff Simmons's avatar Geoff Simmons

Use VSBs to generate code for VMOD objects.

Fixes #2880
parent 7119d790
varnishtest "Long VMOD object names"
varnish v1 -vcl {
import debug;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new l234567890123456789012345678901234567890123456789012345678
= debug.obj();
new l2345678901234567890123456789012345678901234567890123456789
= debug.obj();
}
}
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "vfil.h" #include "vfil.h"
#include "vjsn.h" #include "vjsn.h"
#include "vmod_abi.h" #include "vmod_abi.h"
#include "vsb.h"
static int static int
vcc_path_dlopen(void *priv, const char *fn) vcc_path_dlopen(void *priv, const char *fn)
...@@ -349,8 +350,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym) ...@@ -349,8 +350,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
{ {
struct symbol *sy1, *sy2, *sy3; struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp; struct inifin *ifp;
char buf1[128]; struct vsb *buf;
char buf2[128];
const struct vjsn_val *vv, *vf; const struct vjsn_val *vv, *vf;
const char *p; const char *p;
...@@ -393,8 +393,10 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym) ...@@ -393,8 +393,10 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
vf = VTAILQ_NEXT(vf, list); vf = VTAILQ_NEXT(vf, list);
bprintf(buf1, ", &%s, \"%s\"", sy1->rname, sy1->name); buf = VSB_new_auto();
vcc_Eval_Func(tl, vf, buf1, sy2); VSB_printf(buf, ", &%s, \"%s\"", sy1->rname, sy1->name);
VSB_finish(buf);
vcc_Eval_Func(tl, vf, VSB_data(buf), sy2);
ERRCHK(tl); ERRCHK(tl);
SkipToken(tl, ';'); SkipToken(tl, ';');
sy1->def_e = tl->t; sy1->def_e = tl->t;
...@@ -411,8 +413,10 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym) ...@@ -411,8 +413,10 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
VSB_printf(ifp->fin, "\t\t%s(&%s);", vf->value, sy1->rname); VSB_printf(ifp->fin, "\t\t%s(&%s);", vf->value, sy1->rname);
/* Instantiate symbols for the methods */ /* Instantiate symbols for the methods */
bprintf(buf1, ", %s", sy1->rname); VSB_clear(buf);
p = TlDup(tl, buf1); VSB_printf(buf, ", %s", sy1->rname);
VSB_finish(buf);
p = TlDup(tl, VSB_data(buf));
while (vv != NULL) { while (vv != NULL) {
vf = VTAILQ_FIRST(&vv->children); vf = VTAILQ_FIRST(&vv->children);
assert(vf->type == VJSN_STRING); assert(vf->type == VJSN_STRING);
...@@ -420,11 +424,14 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym) ...@@ -420,11 +424,14 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
vf = VTAILQ_NEXT(vf, list); vf = VTAILQ_NEXT(vf, list);
assert(vf->type == VJSN_STRING); assert(vf->type == VJSN_STRING);
bprintf(buf2, "%s.%s", sy1->name, vf->value); VSB_clear(buf);
sy3 = VCC_MkSym(tl, buf2, SYM_FUNC, VCL_LOW, VCL_HIGH); VSB_printf(buf, "%s.%s", sy1->name, vf->value);
VSB_finish(buf);
sy3 = VCC_MkSym(tl, VSB_data(buf), SYM_FUNC, VCL_LOW, VCL_HIGH);
AN(sy3); AN(sy3);
func_sym(sy3, sy2->vmod, VTAILQ_NEXT(vf, list)); func_sym(sy3, sy2->vmod, VTAILQ_NEXT(vf, list));
sy3->extra = p; sy3->extra = p;
vv = VTAILQ_NEXT(vv, list); vv = VTAILQ_NEXT(vv, list);
} }
VSB_destroy(&buf);
} }
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