linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Variable "combinations" in tokenize.c and token.h
  2007-05-01 21:29 Variable "combinations" in tokenize.c and token.h Josh Triplett
@ 2007-05-01 21:27 ` Christopher Li
  2007-05-02  4:56   ` Josh Triplett
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Li @ 2007-05-01 21:27 UTC (permalink / raw)
  To: Josh Triplett; +Cc: linux-sparse

On Tue, May 01, 2007 at 02:29:10PM -0700, Josh Triplett wrote:
> 
> Apart from triggering a -Wshadow warning, this seems somewhat wasteful.
> The reason appears to relate to the presence or absence of a '\0'
> terminator at the end of each item.  Does that matter?  Could
> show_special change somehow to avoid the duplication?  Alternatively,
> could the global version just include '\0' terminators?
> 
> - Josh Triplett
> 

You mean some thing like that?

Chris

Combinations string clean up

Signed-Off-By: Christopher Li <sparse@chrisli.org>

Index: sparse/token.h
===================================================================
--- sparse.orig/token.h	2007-03-23 11:32:54.000000000 -0700
+++ sparse/token.h	2007-05-01 13:53:22.000000000 -0700
@@ -100,7 +100,7 @@ enum token_type {
 	"<", ">", "<=", ">="	\
 }
 
-extern unsigned char combinations[][3];
+extern unsigned char combinations[][4];
 
 enum special_token {
 	SPECIAL_BASE = 256,
Index: sparse/tokenize.c
===================================================================
--- sparse.orig/tokenize.c	2007-03-23 11:32:54.000000000 -0700
+++ sparse/tokenize.c	2007-05-01 13:54:31.000000000 -0700
@@ -59,13 +59,12 @@ static struct position stream_pos(stream
 
 const char *show_special(int val)
 {
-	static const char *combinations[] = COMBINATION_STRINGS;
 	static char buffer[4];
 
 	buffer[0] = val;
 	buffer[1] = 0;
 	if (val >= SPECIAL_BASE)
-		strcpy(buffer, combinations[val - SPECIAL_BASE]);
+		strcpy(buffer, (char *) combinations[val - SPECIAL_BASE]);
 	return buffer;
 }
 
@@ -611,7 +610,7 @@ static int drop_stream_comment(stream_t 
 	return nextchar(stream);
 }
 
-unsigned char combinations[][3] = COMBINATION_STRINGS;
+unsigned char combinations[][4] = COMBINATION_STRINGS;
 
 #define NR_COMBINATIONS (SPECIAL_ARG_SEPARATOR - SPECIAL_BASE)
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Variable "combinations" in tokenize.c and token.h
@ 2007-05-01 21:29 Josh Triplett
  2007-05-01 21:27 ` Christopher Li
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Triplett @ 2007-05-01 21:29 UTC (permalink / raw)
  To: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

token.h contains this:
> /* Combination tokens */
> #define COMBINATION_STRINGS {   \
>         "+=", "++",             \
>         "-=", "--", "->",       \
>         "*=",                   \
>         "/=",                   \
>         "%=",                   \
>         "<=", ">=",             \
>         "==", "!=",             \
>         "&&", "&=",             \
>         "||", "|=",             \
>         "^=", "##",             \
>         "<<", ">>", "..",       \
>         "<<=", ">>=", "...",    \
>         "",                     \
>         "<", ">", "<=", ">="    \
> }
> 
> extern unsigned char combinations[][3];

tokenize.c contains this:
> const char *show_special(int val)
> {
>         static const char *combinations[] = COMBINATION_STRINGS;
>         static char buffer[4];
> 
>         buffer[0] = val;
>         buffer[1] = 0;
>         if (val >= SPECIAL_BASE)
>                 strcpy(buffer, combinations[val - SPECIAL_BASE]);
>         return buffer;
> }
[...]
> unsigned char combinations[][3] = COMBINATION_STRINGS;

Apart from triggering a -Wshadow warning, this seems somewhat wasteful.
The reason appears to relate to the presence or absence of a '\0'
terminator at the end of each item.  Does that matter?  Could
show_special change somehow to avoid the duplication?  Alternatively,
could the global version just include '\0' terminators?

- Josh Triplett


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Variable "combinations" in tokenize.c and token.h
  2007-05-01 21:27 ` Christopher Li
@ 2007-05-02  4:56   ` Josh Triplett
  0 siblings, 0 replies; 3+ messages in thread
From: Josh Triplett @ 2007-05-02  4:56 UTC (permalink / raw)
  To: Christopher Li; +Cc: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]

Christopher Li wrote:
> On Tue, May 01, 2007 at 02:29:10PM -0700, Josh Triplett wrote:
>> Apart from triggering a -Wshadow warning, this seems somewhat wasteful.
>> The reason appears to relate to the presence or absence of a '\0'
>> terminator at the end of each item.  Does that matter?  Could
>> show_special change somehow to avoid the duplication?  Alternatively,
>> could the global version just include '\0' terminators?
>>
>> - Josh Triplett
>>
> 
> You mean some thing like that?
[snip patch]

Perfect, thanks.  Applied.

- Josh Triplett



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-02  4:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 21:29 Variable "combinations" in tokenize.c and token.h Josh Triplett
2007-05-01 21:27 ` Christopher Li
2007-05-02  4:56   ` Josh Triplett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).