[ccan] Testing ccanlint on Cygwin (gcc 4.3.4-3)

Rusty Russell rusty at rustcorp.com.au
Thu Mar 17 18:05:38 EST 2011


On Wed, 16 Mar 2011 01:06:19 -0400, Joseph Adams <joeyadams3.14159 at gmail.com> wrote:
> On Thu, Mar 10, 2011 at 7:20 PM, Rusty Russell <rusty at rustcorp.com.au> wrote:
> > Meanwhile, we have four options:
> >
> > (1) Create ccan wrappers which warn (using __builtin_compatible_p).
> > (2) Create ccan wrappers which fix (using an extra test, maybe getting
> >    tricky with __builtin_compatible_p to optimize)
> > (3) Create ccan replacements, eg. cisupper etc.
> > (4) Fix our own code then stick our heads back in the sand.
> 
> Here's one idea:
> 
>  1.) Add a ccanlint test that compiles the program (and maybe even
> runs the tests), replacing invocations of ctype functions with
> wrappers that warn.

After some pondering, I agree.  So here's what I've done:

1) Added checking wrappers to ccan/str, but only when CCAN_STR_DEBUG is
   defined (since they cause all the calls to be out-of-lined).

2) Scan the module code for the various problematic tokens.  If found,
   compile as you suggested (prepending #define CCAN_STR_DEBUG 1,
   #include <ccan/str/str.h>).

3) I also wrapped strstr, strchr and strrchr to be const-preserving in
   a similar way.

4) Fixed all the modules.

>  2.) Create a CCAN module containing a different set of wrappers which
> instead cast to unsigned char.

Yep.  Here's what I did:

1) Turned on CCAN_STR_DEBUG by default when compiling tools

2) Put cis<foo> wrappers into str.h.

3) Made tools use the wrappers (since they already use str.h).

Cheers,
Rusty.

PS. Here's the patch for the ciniparser code:

>From c080a6226a2d868f0b6bc748de9902bea4cfd078 Mon Sep 17 00:00:00 2001
From: Rusty Russell <rusty at rustcorp.com.au>
Date: Thu, 17 Mar 2011 17:09:10 +1030
Subject: [PATCH] ciniparser: fix isspace usage.

isspace() wants an unsigned value; it also includes '\n' so we can
simplify the logic a little in one place.
---
 ccan/ciniparser/ciniparser.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/ccan/ciniparser/ciniparser.c b/ccan/ciniparser/ciniparser.c
index d28c158..807b9f3 100644
--- a/ccan/ciniparser/ciniparser.c
+++ b/ccan/ciniparser/ciniparser.c
@@ -95,12 +95,12 @@ static char *strstrip(const char *s)
 	if (s == NULL)
 		return NULL;
 
-	while (isspace(*s))
+	while (isspace((unsigned char)*s))
 		s++;
 
 	for (i = numspc = 0; s[i] && i < ASCIILINESZ; i++) {
 		l[i] = s[i];
-		if (isspace(l[i]))
+		if (isspace((unsigned char)l[i]))
 			numspc++;
 		else
 			numspc = 0;
@@ -416,8 +416,7 @@ dictionary *ciniparser_load(const char *ininame)
 		}
 
 		/* Get rid of \n and spaces at end of line */
-		while ((len >= 0) &&
-				((line[len] == '\n') || (isspace(line[len])))) {
+		while ((len >= 0) && (isspace((unsigned char)line[len]))) {
 			line[len] = 0;
 			len--;
 		}
-- 
1.7.1



More information about the ccan mailing list