r5657 - in trunk/varnish-cache: . bin/varnishd include lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Mon Dec 20 11:00:55 CET 2010


Author: phk
Date: 2010-12-20 11:00:55 +0100 (Mon, 20 Dec 2010)
New Revision: 5657

Removed:
   trunk/varnish-cache/include/vrt_stv_var.h
Modified:
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/configure.ac
   trunk/varnish-cache/lib/libvcl/generate.py
Log:
Move the table of stevedore VCL variables to the generate.py script,
this is much cleaner and does not demand a brand new python interpreter.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-19 22:48:08 UTC (rev 5656)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-20 10:00:55 UTC (rev 5657)
@@ -45,6 +45,7 @@
 #include "stevedore.h"
 #include "hash_slinger.h"
 #include "cli_priv.h"
+#include "vrt_obj.h"
 
 #define TRANSIENT_NAME	"Transient"
 
@@ -545,9 +546,6 @@
 	return (0);
 }
 
-#define VRTSTVVAR_PROTO
-#include "vrt_stv_var.h"
-
 #define VRTSTVVAR(nm, vtype, ctype, dval)	\
 ctype						\
 VRT_Stv_##nm(const char *nm)			\

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2010-12-19 22:48:08 UTC (rev 5656)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2010-12-20 10:00:55 UTC (rev 5657)
@@ -46,8 +46,9 @@
 typedef void storage_close_f(const struct stevedore *);
 
 /* Prototypes for VCL variable responders */
-typedef double storage_var_double(const struct stevedore *);
-typedef int storage_var_int(const struct stevedore *);
+#define VRTSTVTYPE(ct) typedef ct storage_var_##ct(const struct stevedore *);
+#include "vrt_stv_var.h"
+#undef VRTSTVTYPE
 
 struct stevedore {
 	unsigned		magic;

Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac	2010-12-19 22:48:08 UTC (rev 5656)
+++ trunk/varnish-cache/configure.ac	2010-12-20 10:00:55 UTC (rev 5657)
@@ -307,7 +307,7 @@
 fi
 
 AM_MISSING_HAS_RUN
-AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python python2], [AC_MSG_ERROR([Python is needed to build Varnish, please install python.])])
+AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build Varnish, please install python.])])
 
 # Solaris defines SO_{RCV,SND}TIMEO, but does not implement them.
 # Varnish will build and run without these, but connections will not

Deleted: trunk/varnish-cache/include/vrt_stv_var.h
===================================================================
--- trunk/varnish-cache/include/vrt_stv_var.h	2010-12-19 22:48:08 UTC (rev 5656)
+++ trunk/varnish-cache/include/vrt_stv_var.h	2010-12-20 10:00:55 UTC (rev 5657)
@@ -1,42 +0,0 @@
-/*-
- * Copyright (c) 2010 Varnish-Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $Id$
- */
-
-#ifdef VRTSTVVAR_PROTO
-#define VRTSTVVAR(nm, vtype, ctype, dval) ctype VRT_Stv_ ## nm(const char *nm);
-#endif
-
-VRTSTVVAR(free_space,	BYTES,	double,	0.)
-VRTSTVVAR(used_space,	BYTES,	double,	0.)
-VRTSTVVAR(happy,	BOOL,	int,	0)
-
-#ifdef VRTSTVVAR_PROTO
-#undef VRTSTVVAR_PROTO
-#undef VRTSTVVAR
-#endif

Modified: trunk/varnish-cache/lib/libvcl/generate.py
===================================================================
--- trunk/varnish-cache/lib/libvcl/generate.py	2010-12-19 22:48:08 UTC (rev 5656)
+++ trunk/varnish-cache/lib/libvcl/generate.py	2010-12-20 10:00:55 UTC (rev 5657)
@@ -41,9 +41,7 @@
 # XXX: does it actually do that ?
 
 import sys
-import subprocess
 
-
 srcroot = "../.."
 buildroot = "../.."
 if len(sys.argv) == 3:
@@ -404,6 +402,12 @@
 	),
 )
 
+stv_variables = (
+	('free_space',	'BYTES',	"0."),
+	('used_space',	'BYTES',	"0."),
+	('happy',	'BOOL',		"0"),
+)
+
 #######################################################################
 # VCL to C type conversion
 
@@ -414,6 +418,7 @@
 	'BACKEND':	"struct director *",
 	'TIME':		"double",
 	'DURATION':	"double",
+	'BYTES':	"double",
 	'INT':		"int",
 	'HEADER':	"const char *",
 }
@@ -507,14 +512,10 @@
 #######################################################################
 # Read a C-source file and spit out code that outputs it with vsb_cat()
 
-def emit_file(fo, fn, cpp = False):
-	if cpp:
-		fc = subprocess.check_output(["cpp", "-DVRTSTVVAR_PROTO", fn])
-		fc = fc.decode("ascii")
-	else:
-		fi = open(fn)
-		fc = fi.read()
-		fi.close()
+def emit_file(fo, fn):
+	fi = open(fn)
+	fc = fi.read()
+	fi.close()
 
 	w = 66		# Width of lines, after white space prefix
 	maxlen = 10240	# Max length of string literal
@@ -786,6 +787,9 @@
 
 fo.write("\t{ NULL }\n};\n")
 
+for i in stv_variables:
+	fh.write(vcltypes[i[1]] + " VRT_Stv_" + i[0] + "(const char *);\n")
+
 fo.close()
 fh.close()
 
@@ -816,7 +820,6 @@
 emit_file(fo, buildroot + "/include/vcl.h")
 emit_file(fo, srcroot + "/include/vrt.h")
 emit_file(fo, buildroot + "/include/vrt_obj.h")
-emit_file(fo, buildroot + "/include/vrt_stv_var.h", True)
 
 fo.write("""
 }
@@ -824,3 +827,42 @@
 
 fo.close()
 
+#######################################################################
+
+fo = open(buildroot + "/include/vrt_stv_var.h", "w")
+
+file_header(fo)
+
+fo.write("""
+#ifndef VRTSTVTYPE
+#define VRTSTVTYPE(ct)
+#define VRTSTVTYPEX
+#endif
+#ifndef VRTSTVVAR
+#define VRTSTVVAR(nm, vtype, ctype, dval)
+#define VRTSTVVARX
+#endif
+""")
+
+x=dict()
+for i in stv_variables:
+	ct = vcltypes[i[1]]
+	if not ct in x:
+		fo.write("VRTSTVTYPE(" + ct + ")\n")
+		x[ct] = 1
+	fo.write("VRTSTVVAR(" + i[0] + ",\t" + i[1] + ",\t")
+	fo.write(ct + ",\t" + i[2] + ")")
+	fo.write("\n")
+
+fo.write("""
+#ifdef VRTSTVTYPEX
+#undef VRTSTVTYPEX
+#undef VRTSTVTYPE
+#endif
+#ifdef VRTSTVVARX
+#undef VRTSTVVARX
+#undef VRTSTVVAR
+#endif
+""")
+
+fo.close




More information about the varnish-commit mailing list