public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix gengtype-state string hashtable
@ 2011-04-17  7:27 Nicola Pero
  2011-04-17  9:48 ` Basile Starynkevitch
  2011-04-19  7:07 ` Laurynas Biveinis
  0 siblings, 2 replies; 3+ messages in thread
From: Nicola Pero @ 2011-04-17  7:27 UTC (permalink / raw)
  To: gcc-patches

While reading GCC code, I noticed that in gengtype-state.c
the equality function in a string hashtable is set to strcmp.

But that returns 0 (ie, false for hashtable.c) when the strings
are equal!  I can't see how that hashtable would ever work.  Do
we have any tests for gengtype-state ?  Am I missing something ? :-)

Else, Ok to commit the following patch ?

Thanks

Index: gengtype-state.c
===================================================================
--- gengtype-state.c    (revision 172522)
+++ gengtype-state.c    (working copy)
@@ -2385,7 +2385,16 @@ equals_type_number (const void *ty1, const void *t
   return type1->state_number == type2->state_number;
 }
 
+static int
+string_eq (const void *a, const void *b)
+{
+  const char *a0 = (const char *)a;
+  const char *b0 = (const char *)b;
 
+  return (strcmp (a0, b0) == 0);
+}
+
+
 /* The function reading the state, called by main from gengtype.c.  */
 void
 read_state (const char *path)
@@ -2408,7 +2417,7 @@ read_state (const char *path)
   state_seen_types =
     htab_create (2017, hash_type_number, equals_type_number, NULL);
   state_ident_tab =
-    htab_create (4027, htab_hash_string, (htab_eq) strcmp, NULL);
+    htab_create (4027, htab_hash_string, string_eq, NULL);
   read_state_version (version_string);
   read_state_srcdir ();
   read_state_languages ();
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 172522)
+++ ChangeLog   (working copy)
@@ -1,3 +1,9 @@
+2011-04-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * gengtype-state.c (string_eq): New.
+       (read_state): Use string_eq instead of strcmp when creating the
+       state_ident_tab.
+
 2011-04-15  Pat Haugen <pthaugen@us.ibm.com>
 
        * config/rs6000/rs6000.c (call_ABI_of_interest): Call


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

* Re: Fix gengtype-state string hashtable
  2011-04-17  7:27 Fix gengtype-state string hashtable Nicola Pero
@ 2011-04-17  9:48 ` Basile Starynkevitch
  2011-04-19  7:07 ` Laurynas Biveinis
  1 sibling, 0 replies; 3+ messages in thread
From: Basile Starynkevitch @ 2011-04-17  9:48 UTC (permalink / raw)
  To: Nicola Pero; +Cc: gcc-patches

On Sun, 17 Apr 2011 02:55:33 +0200 (CEST)
"Nicola Pero" <nicola.pero@meta-innovation.com> wrote:

> While reading GCC code, I noticed that in gengtype-state.c
> the equality function in a string hashtable is set to strcmp.
> 
> But that returns 0 (ie, false for hashtable.c) when the strings
> are equal!  I can't see how that hashtable would ever work.  Do
> we have any tests for gengtype-state ?  Am I missing something ? :-)
> 
> Else, Ok to commit the following patch ?

I am not authorized to Ok it, but I hope it will be oked.

Thanks for finding that bug.

Cheers

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

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

* Re: Fix gengtype-state string hashtable
  2011-04-17  7:27 Fix gengtype-state string hashtable Nicola Pero
  2011-04-17  9:48 ` Basile Starynkevitch
@ 2011-04-19  7:07 ` Laurynas Biveinis
  1 sibling, 0 replies; 3+ messages in thread
From: Laurynas Biveinis @ 2011-04-19  7:07 UTC (permalink / raw)
  To: Nicola Pero; +Cc: gcc-patches, Basile STARYNKEVITCH

2011/4/17 Nicola Pero <nicola.pero@meta-innovation.com>:
> While reading GCC code, I noticed that in gengtype-state.c
> the equality function in a string hashtable is set to strcmp.
>
> But that returns 0 (ie, false for hashtable.c) when the strings
> are equal!  I can't see how that hashtable would ever work.  Do
> we have any tests for gengtype-state ?  Am I missing something ? :-)

The gengtype state is tested during normal bootstrap these days (the
state is dumped and the loaded back). After reading the code I think
that this bug is causing multiple copies of the same string in the
hashtable without any correctness issues, that's why we missed it.

> +2011-04-17  Nicola Pero  <nicola.pero@meta-innovation.com>
> +
> +       * gengtype-state.c (string_eq): New.
> +       (read_state): Use string_eq instead of strcmp when creating the
> +       state_ident_tab.
> +

The patch is OK. Thanks!

-- 
Laurynas

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

end of thread, other threads:[~2011-04-19  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-17  7:27 Fix gengtype-state string hashtable Nicola Pero
2011-04-17  9:48 ` Basile Starynkevitch
2011-04-19  7:07 ` Laurynas Biveinis

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 read-only IMAP folder(s) and NNTP newsgroup(s).