[master] d488c05 Allow direct calls to global symbol registration

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 14 11:02:06 CEST 2017


commit d488c050a8746f3952720ab52169c1bd6d7e0064
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Jun 28 10:15:28 2017 +0200

    Allow direct calls to global symbol registration
    
    Refs #2325

diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index bf57ee9..f6660fd 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -568,9 +568,9 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 		sym->fmt = v->fmt;
 		sym->eval = vcc_Eval_Var;
 		sym->r_methods = v->r_methods;
-		sym->rname = v->rname;
 		sym->w_methods = v->w_methods;
 		sym->lname = v->lname;
+		REPLACE(sym->rname, v->rname);
 	}
 
 	Fh(tl, 0, "/* ---===### VCC generated .h code ###===---*/\n");
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index bc43b78..17ceba0 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -137,7 +137,7 @@ struct symbol {
 	const char			*extra;
 
 	/* SYM_VAR */
-	const char			*rname;
+	char				*rname;
 	unsigned			r_methods;
 	const char			*lname;
 	unsigned			w_methods;
@@ -279,6 +279,7 @@ sym_expr_t vcc_Eval_SymFunc;
 void vcc_Eval_Func(struct vcc *tl, const char *spec,
     const char *extra, const struct symbol *sym);
 enum symkind VCC_HandleKind(vcc_type_t fmt);
+void VCC_GlobalSymbol(struct symbol *, vcc_type_t fmt, const char *pfx);
 struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *,
     vcc_type_t fmt, const char *pfx);
 
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 0d41901..3ab20b6 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1150,6 +1150,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	const char *re;
 	const char *not;
 	struct token *tk;
+	struct symbol *sym;
 	enum symkind kind;
 
 	*e = NULL;
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 1d33597..045a239 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -178,8 +178,8 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, enum symkind kind)
 	vcc_walksymbols(tl, tl->symbols, func, kind);
 }
 
-static void
-vcc_global(struct vcc *tl, struct symbol *sym, vcc_type_t fmt, const char *pfx)
+void
+VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx)
 {
 	struct vsb *vsb;
 
@@ -190,10 +190,7 @@ vcc_global(struct vcc *tl, struct symbol *sym, vcc_type_t fmt, const char *pfx)
 	AN(vsb);
 	VSB_printf(vsb, "%s_%s", pfx, sym->name);
 	AZ(VSB_finish(vsb));
-	if (tl != NULL)
-		sym->rname = TlDup(tl, VSB_data(vsb));
-	else
-		sym->rname = strdup(VSB_data(vsb));
+	REPLACE(sym->rname, VSB_data(vsb));
 	AN(sym->rname);
 	VSB_destroy(&vsb);
 
@@ -247,7 +244,7 @@ VCC_HandleSymbol(struct vcc *tl, const struct token *tk, vcc_type_t fmt,
 		sym = VCC_SymbolTok(tl, NULL, tk, kind, 1);
 	AN(sym);
 	AZ(sym->ndef);
-	vcc_global(tl, sym, fmt, pfx);
+	VCC_GlobalSymbol(sym, fmt, pfx);
 	sym->ndef = 1;
 	if (sym->def_b == NULL)
 		sym->def_b = tk;
diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c
index 6428b86..50fa9e9 100644
--- a/lib/libvcc/vcc_var.c
+++ b/lib/libvcc/vcc_var.c
@@ -29,6 +29,9 @@
 
 #include "config.h"
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "vcc_compile.h"
 #include "vct.h"
 
@@ -90,9 +93,9 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent,
 	sym->fmt = v->fmt;
 	sym->eval = vcc_Eval_Var;
 	sym->r_methods = v->r_methods;
-	sym->rname = v->rname;
 	sym->w_methods = v->w_methods;
 	sym->lname = v->lname;
+	REPLACE(sym->rname, v->rname);
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list