[master] 0a712d9 Make sure object destructors are called as the first thing in the VCL::fini cleanup

Poul-Henning Kamp phk at varnish-cache.org
Tue Mar 12 15:10:31 CET 2013


commit 0a712d95c1935d2c52cbaf091457e38736515c5b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Mar 12 14:10:13 2013 +0000

    Make sure object destructors are called as the first thing in the
    VCL::fini cleanup

diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index 5fdae74..7d5ea2e 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -222,7 +222,7 @@ parse_new(struct vcc *tl)
 
 	bprintf(buf1, ", &%s, \"%s\"", sy1->name, sy1->name);
 	vcc_Eval_Func(tl, s_init, buf1, "ASDF", s_init + strlen(s_init) + 1);
-	Ff(tl, 0, "\t%s((struct req*)0, &%s);\n", s_fini, sy1->name);
+	Fd(tl, 0, "\t%s((struct req*)0, &%s);\n", s_fini, sy1->name);
 	ExpectErr(tl, ';');
 
 	bprintf(buf1, ", %s", sy1->name);
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index e585e67..6eca56c 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -190,6 +190,19 @@ Fi(const struct vcc *tl, int indent, const char *fmt, ...)
 }
 
 void
+Fd(const struct vcc *tl, int indent, const char *fmt, ...)
+{
+	va_list ap;
+
+	if (indent)
+		VSB_printf(tl->fd, "%*.*s", tl->findent, tl->findent, "");
+	va_start(ap, fmt);
+	VSB_vprintf(tl->fd, fmt, ap);
+	va_end(ap);
+}
+
+
+void
 Ff(const struct vcc *tl, int indent, const char *fmt, ...)
 {
 	va_list ap;
@@ -316,6 +329,9 @@ EmitFiniFunc(const struct vcc *tl)
 
 	Fc(tl, 0, "\nstatic void\nVGC_Fini(struct cli *cli)\n{\n\n");
 
+	AZ(VSB_finish(tl->fd));
+	VSB_cat(tl->fc, VSB_data(tl->fd));
+
 	/*
 	 * We do this here, so we are sure they happen before any
 	 * per-vcl vmod_privs get cleaned.
@@ -517,6 +533,10 @@ vcc_NewVcc(const struct vcc *tl0)
 	tl->fi = VSB_new_auto();
 	assert(tl->fi != NULL);
 
+	/* Destroy Objects */
+	tl->fd = VSB_new_auto();
+	assert(tl->fd != NULL);
+
 	/* Finish C code */
 	tl->ff = VSB_new_auto();
 	assert(tl->ff != NULL);
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index 1e51f5f..65e5dff 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -170,6 +170,7 @@ struct vcc {
 	struct vsb		*fc;		/* C-code */
 	struct vsb		*fh;		/* H-code (before C-code) */
 	struct vsb		*fi;		/* Init func code */
+	struct vsb		*fd;		/* Object destructors */
 	struct vsb		*ff;		/* Finish func code */
 	struct vsb		*fb;		/* Body of current sub
 						 * NULL otherwise
@@ -258,6 +259,8 @@ void Fi(const struct vcc *tl, int indent, const char *fmt, ...)
     __printflike(3, 4);
 void Ff(const struct vcc *tl, int indent, const char *fmt, ...)
     __printflike(3, 4);
+void Fd(const struct vcc *tl, int indent, const char *fmt, ...)
+    __printflike(3, 4);
 void EncToken(struct vsb *sb, const struct token *t);
 int IsMethod(const struct token *t);
 void *TlAlloc(struct vcc *tl, unsigned len);



More information about the varnish-commit mailing list