Permalink
Browse files

Make sure object destructors are called as the first thing in the

VCL::fini cleanup
  • Loading branch information...
1 parent a1ed465 commit 0a712d95c1935d2c52cbaf091457e38736515c5b @bsdphk bsdphk committed Mar 12, 2013
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/libvcl/vcc_action.c
  2. +20 −0 lib/libvcl/vcc_compile.c
  3. +3 −0 lib/libvcl/vcc_compile.h
View
@@ -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);
View
@@ -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);
View
@@ -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);

0 comments on commit 0a712d9

Please sign in to comment.