r5652 - trunk/varnish-cache/lib/libvcl
phk at varnish-cache.org
phk at varnish-cache.org
Fri Dec 17 18:15:35 CET 2010
Author: phk
Date: 2010-12-17 18:15:35 +0100 (Fri, 17 Dec 2010)
New Revision: 5652
Modified:
trunk/varnish-cache/lib/libvcl/vcc_compile.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_var.c
Log:
Add a couple of handy string allocation macros.
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-12-17 15:27:27 UTC (rev 5651)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-12-17 17:15:35 UTC (rev 5652)
@@ -107,6 +107,31 @@
return (p);
}
+char *
+TlDup(struct vcc *tl, const char *s)
+{
+ char *p;
+
+ p = TlAlloc(tl, strlen(s) + 1);
+ AN(p);
+ strcpy(p, s);
+ return (p);
+}
+
+char *
+TlDupTok(struct vcc *tl, const struct token *tok)
+{
+ char *p;
+ int i;
+
+ i = tok->e - tok->b;
+ p = TlAlloc(tl, i + 1);
+ AN(p);
+ memcpy(p, tok->b, i);
+ p[i] = '\0';
+ return (p);
+}
+
/*--------------------------------------------------------------------*/
int
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-12-17 15:27:27 UTC (rev 5651)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-12-17 17:15:35 UTC (rev 5652)
@@ -230,6 +230,9 @@
void EncToken(struct vsb *sb, const struct token *t);
int IsMethod(const struct token *t);
void *TlAlloc(struct vcc *tl, unsigned len);
+char *TlDup(struct vcc *tl, const char *s);
+char *TlDupTok(struct vcc *tl, const struct token *tok);
+
void EncString(struct vsb *sb, const char *b, const char *e, int mode);
/* vcc_dir_random.c */
Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c 2010-12-17 15:27:27 UTC (rev 5651)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2010-12-17 17:15:35 UTC (rev 5652)
@@ -46,24 +46,18 @@
struct symbol *
vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
{
- char *p;
struct symbol *sym;
struct var *v;
const struct var *vh;
- int i, l;
+ int l;
char buf[258];
vh = wc->var;
v = TlAlloc(tl, sizeof *v);
- assert(v != NULL);
+ AN(v);
- i = t->e - t->b;
- p = TlAlloc(tl, i + 1);
- assert(p != NULL);
- memcpy(p, t->b, i);
- p[i] = '\0';
- v->name = p;
+ v->name = TlDupTok(tl, t);
v->r_methods = vh->r_methods;
v->w_methods = vh->w_methods;
v->fmt = STRING;
@@ -72,17 +66,11 @@
bprintf(buf, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")",
v->hdr, (unsigned)l, v->name + vh->len);
- i = strlen(buf);
- p = TlAlloc(tl, i + 1);
- memcpy(p, buf, i + 1);
- v->rname = p;
+ v->rname = TlDup(tl, buf);
bprintf(buf, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ",
v->hdr, (unsigned)l, v->name + vh->len);
- i = strlen(buf);
- p = TlAlloc(tl, i + 1);
- memcpy(p, buf, i + 1);
- v->lname = p;
+ v->lname = TlDup(tl, buf);
sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
AN(sym);
More information about the varnish-commit
mailing list