r103 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl

des at projects.linpro.no des at projects.linpro.no
Tue Apr 4 09:24:07 CEST 2006


Author: des
Date: 2006-04-04 09:24:07 +0200 (Tue, 04 Apr 2006)
New Revision: 103

Modified:
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/include/cli_priv.h
   trunk/varnish-cache/include/libvarnish.h
   trunk/varnish-cache/lib/libvarnish/argv.c
   trunk/varnish-cache/lib/libvarnish/cli.c
   trunk/varnish-cache/lib/libvcl/vcl_compile.c
Log:
Portability tweaks: use our own sbuf.h and queue.h; get rid of __DECONST; get
rid of digittoint() (which is pointless since ISO C guarantees that digits
are consecutive in the execution character set); get rid of __unused.

Also fix a buglet in argv.c's BackSlash() (parsing of octal numbers), and
constify the array passed around by ParseArgv() and FreeArgv().

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-04-04 07:24:07 UTC (rev 103)
@@ -69,7 +69,7 @@
 }
 
 static void
-accept_f(int fd, short event, void *arg __unused)
+accept_f(int fd, short event, void *arg)
 {
 	socklen_t l;
 	struct sessmem *sm;
@@ -77,6 +77,7 @@
 	struct sess *sp;
 	char port[10];
 
+	(void)arg;
 	sm = calloc(sizeof *sm, 1);
 	assert(sm != NULL);	/*
 				 * XXX: this is probably one we should handle

Modified: trunk/varnish-cache/include/cli_priv.h
===================================================================
--- trunk/varnish-cache/include/cli_priv.h	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/include/cli_priv.h	2006-04-04 07:24:07 UTC (rev 103)
@@ -11,7 +11,7 @@
 
 struct cli;	/* NB: struct cli is opaque at this level.  */
 
-typedef void cli_func_t(struct cli*, char **av, void *priv);
+typedef void cli_func_t(struct cli*, const char **av, void *priv);
 
 struct cli_proto {
 	/* These must match the CLI_* macros in cli.h */

Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/include/libvarnish.h	2006-04-04 07:24:07 UTC (rev 103)
@@ -3,10 +3,9 @@
  */
 
 /* from libvarnish/argv.c */
-void FreeArgv(char **argv);
-char **ParseArgv(const char *s, int comment);
+void FreeArgv(const char **argv);
+const char **ParseArgv(const char *s, int comment);
 
 
 /* Assert zero return value */
 #define AZ(foo)	do { assert((foo) == 0); } while (0)
-

Modified: trunk/varnish-cache/lib/libvarnish/argv.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/argv.c	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/lib/libvarnish/argv.c	2006-04-04 07:24:07 UTC (rev 103)
@@ -1,12 +1,12 @@
 /*
  * $Id$
  *
- * char **ParseArgv(const char *s, int comment)
+ * const char **ParseArgv(const char *s, int comment)
  *	Parse a command like line into an argv[]
  *	Index zero contains NULL or an error message
  *	"double quotes" and backslash substitution is handled.
  *
- * void FreeArgv(char **argv)
+ * void FreeArgv(const char **argv)
  *	Free the result of ParseArgv()
  *
  */
@@ -48,15 +48,15 @@
 		i = '\\';
 		r = 2;
 		break;
-	case '0': case '1': case '2': case 3:
-	case '4': case '5': case '6': case 7:
+	case '0': case '1': case '2': case '3':
+	case '4': case '5': case '6': case '7':
 		for (r = 1; r < 4; r++) {
 			if (!isdigit(s[r]))
 				break;
-			if (digittoint(s[r]) > 7)
+			if (s[r] - '0' > 7)
 				break;
 			i <<= 3;
-			i |= digittoint(s[r]);
+			i |= s[r] - '0';
 		}
 		break;
 	case 'x':
@@ -96,10 +96,10 @@
 	return (p);
 }
 
-char **
+const char **
 ParseArgv(const char *s, int comment)
 {
-	char **argv;
+	const char **argv;
 	const char *p;
 	int nargv, largv;
 	int i, quote;
@@ -131,8 +131,7 @@
 			if (*s == '\\') {
 				i = BackSlash(s, NULL);
 				if (i == 0) {
-					argv[0] = __DECONST(void *,
-					    "Illegal backslash sequence");
+					argv[0] = "Illegal backslash sequence";
 					return (argv);
 				}
 				s += i;
@@ -147,8 +146,7 @@
 			if (*s == '"')
 				break;
 			if (*s == '\0') {
-				argv[0] = __DECONST(void *,
-				    "Missing '\"'");
+				argv[0] = "Missing '\"'";
 				return (argv);
 			}
 			s++;
@@ -166,12 +164,12 @@
 }
 
 void
-FreeArgv(char **argv)
+FreeArgv(const char **argv)
 {
 	int i;
 	
 	for (i = 1; argv[i] != NULL; i++)
-		free(argv[i]);
+		free((void *)(uintptr_t)argv[i]);
 	free(argv);
 }
 

Modified: trunk/varnish-cache/lib/libvarnish/cli.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli.c	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/lib/libvarnish/cli.c	2006-04-04 07:24:07 UTC (rev 103)
@@ -19,7 +19,7 @@
  */
 
 void
-cli_func_help(struct cli *cli, char **av, void *priv)
+cli_func_help(struct cli *cli, const char **av, void *priv)
 {
 	struct cli_proto *cp;
 
@@ -41,7 +41,7 @@
 void
 cli_dispatch(struct cli *cli, struct cli_proto *clp, const char *line)
 {
-	char **av;
+	const char **av;
 	unsigned u;
 	struct cli_proto *cp;
 

Modified: trunk/varnish-cache/lib/libvcl/vcl_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_compile.c	2006-04-03 14:41:51 UTC (rev 102)
+++ trunk/varnish-cache/lib/libvcl/vcl_compile.c	2006-04-04 07:24:07 UTC (rev 103)
@@ -33,22 +33,22 @@
  *	and all the rest...
  */
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
 #include <assert.h>
-#include <string.h>
 #include <ctype.h>
-#include <unistd.h>
+#include <errno.h>
 #include <fcntl.h>
-#include <errno.h>
+#include <netdb.h>
+#include <sbuf.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/sbuf.h>
-#include <sys/stat.h>
-#include <sys/queue.h>
+#include <string.h>
+#include <queue.h>
+#include <unistd.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
 #include "vcl_priv.h"
 
 #include "libvcl.h"
@@ -316,15 +316,15 @@
 		case 'b':	*q++ = '\b';	r += 2; break;
 		case '0': case '1': case '2': case '3':
 		case '4': case '5': case '6': case '7':
-			u = digittoint(r[1]);
+			u = r[1] - '0';
 			r += 2;
-			if (isdigit(r[0]) && digittoint(r[0]) < 8) {
+			if (isdigit(r[0]) && (r[0] - '0') < 8) {
 				u <<= 3;
-				u |= digittoint(r[0]);
+				u |= r[0] - '0';
 				r++;
-				if (isdigit(r[0]) && digittoint(r[0]) < 8) {
+				if (isdigit(r[0]) && (r[0] - '0') < 8) {
 					u <<= 3;
-					u |= digittoint(r[0]);
+					u |= r[0] - '0';
 					r++;
 				}
 			}
@@ -471,7 +471,7 @@
 	Expect(tl, CNUM);
 	for (p = tl->t->b; p < tl->t->e; p++) {
 		d *= 10;
-		d += digittoint(*p);
+		d += *p - '0';
 	}
 	NextToken(tl);
 	return (d);
@@ -490,7 +490,7 @@
 	Expect(tl, CNUM);
 	for (p = tl->t->b; p < tl->t->e; p++) {
 		d *= 10;
-		d += digittoint(*p);
+		d += *p - '0';
 	}
 	NextToken(tl);
 	if (tl->t->tok != '.') 
@@ -499,7 +499,7 @@
 	if (tl->t->tok != CNUM)
 		return (d);
 	for (p = tl->t->b; p < tl->t->e; p++) {
-		d += digittoint(*p) * e;
+		d += (*p - '0') * e;
 		e *= 0.1;
 	}
 	NextToken(tl);
@@ -645,9 +645,10 @@
 }
 
 static void
-Cond_String(struct var *vp __unused, struct tokenlist *tl)
+Cond_String(struct var *vp, struct tokenlist *tl)
 {
 
+	(void)vp;
 	switch (tl->t->tok) {
 	case '~':
 		I(tl); sbuf_printf(tl->fc, "string_match(%s, ", vp->cname);




More information about the varnish-commit mailing list