Author: miguel
Date: 2006-08-21 01:11:02 -0400 (Mon, 21 Aug 2006)
New Revision: 64120

Modified:
   trunk/mono/eglib/ChangeLog
   trunk/mono/eglib/src/ghashtable.c
   trunk/mono/eglib/src/goutput.c
Log:
2006-08-21  Miguel de Icaza  <[EMAIL PROTECTED]>

        * src/ghashtable.c (g_hash_table_new): The glib test suite
        uncovered a bunch of bugs, the g_hash_table_new should actually
        have parameters.

        (g_hash_table_remove, g_hash_table_foreach_remove): Fixed bugs
        uncovered. 

        * src/goutput.c: Fix g_log so it actually formats the data. 




Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog  2006-08-21 04:15:35 UTC (rev 64119)
+++ trunk/mono/eglib/ChangeLog  2006-08-21 05:11:02 UTC (rev 64120)
@@ -1,3 +1,14 @@
+2006-08-21  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * src/goutput.c: Fix g_log so it actually formats the data. 
+
+       * src/ghashtable.c (g_hash_table_new): The glib test suite
+       uncovered a bunch of bugs, the g_hash_table_new should actually
+       have parameters.
+
+       (g_hash_table_remove, g_hash_table_foreach_remove): Fixed bugs
+       uncovered. 
+
 2006-08-20  Aaron Bockover  <[EMAIL PROTECTED]>
 
        * src/gmisc.c: added g_setenv, g_getenv, g_unsetenv

Modified: trunk/mono/eglib/src/ghashtable.c
===================================================================
--- trunk/mono/eglib/src/ghashtable.c   2006-08-21 04:15:35 UTC (rev 64119)
+++ trunk/mono/eglib/src/ghashtable.c   2006-08-21 05:11:02 UTC (rev 64120)
@@ -112,9 +112,10 @@
 {
        GHashTable *hash;
 
-       g_return_val_if_fail (hash_func != NULL, NULL);
-       g_return_val_if_fail (key_equal_func != NULL, NULL);
-                         
+       if (hash_func == NULL)
+               hash_func = g_direct_hash;
+       if (key_equal_func == NULL)
+               key_equal_func = g_direct_equal;
        hash = g_new0 (GHashTable, 1);
 
        hash->hash_func = hash_func;
@@ -211,7 +212,8 @@
        g_return_val_if_fail (hash != NULL, FALSE);
        equal = hash->key_equal_func;
 
-       hashcode = ((*hash->hash_func) (key)) % hash->table_size;       
+       hashcode = ((*hash->hash_func) (key)) % hash->table_size;
+       
        for (s = hash->table [hashcode]; s != NULL; s = s->next){
                if ((*equal)(s->key, key)){
                        *orig_key = s->key;
@@ -260,26 +262,29 @@
 g_hash_table_remove (GHashTable *hash, gconstpointer key)
 {
        GEqualFunc equal;
-       Slot *s, **last;
+       Slot *s, *last;
        guint hashcode;
        
        g_return_val_if_fail (hash != NULL, FALSE);
        equal = hash->key_equal_func;
 
        hashcode = ((*hash->hash_func)(key)) % hash->table_size;
-       last = &hash->table [hashcode];
-       for (s = *last; s != NULL; s = s->next){
+       last = NULL;
+       for (s = hash->table [hashcode]; s != NULL; s = s->next){
                if ((*equal)(s->key, key)){
                        if (hash->key_destroy_func != NULL)
                                (*hash->key_destroy_func)(s->key);
                        if (hash->value_destroy_func != NULL)
                                (*hash->value_destroy_func)(s->value);
-                       *last = s->next;
+                       if (last == NULL)
+                               hash->table [hashcode] = s->next;
+                       else
+                               last->next = s->next;
                        g_free (s);
                        hash->in_use--;
                        return TRUE;
                }
-               last = &s;
+               last = s;
        }
        return FALSE;
 }
@@ -294,19 +299,31 @@
        g_return_val_if_fail (func != NULL, 0);
 
        for (i = 0; i < hash->table_size; i++){
-               Slot *s, **last;
+               Slot *s, *last;
 
-               last = &hash->table [i];
-               for (s = hash->table [i]; s != NULL; s = s->next){
+               last = NULL;
+               for (s = hash->table [i]; s != NULL; ){
                        if ((*func)(s->key, s->value, user_data)){
+                               Slot *n;
+
                                if (hash->key_destroy_func != NULL)
                                        (*hash->key_destroy_func)(s->key);
                                if (hash->value_destroy_func != NULL)
                                        (*hash->value_destroy_func)(s->value);
-                               *last = s->next;
+                               if (last == NULL){
+                                       hash->table [i] = s->next;
+                                       n = s->next;
+                               } else  {
+                                       last->next = s->next;
+                                       n = last->next;
+                               }
                                g_free (s);
                                hash->in_use--;
                                count++;
+                               s = n;
+                       } else {
+                               last = s;
+                               s = s->next;
                        }
                }
        }

Modified: trunk/mono/eglib/src/goutput.c
===================================================================
--- trunk/mono/eglib/src/goutput.c      2006-08-21 04:15:35 UTC (rev 64119)
+++ trunk/mono/eglib/src/goutput.c      2006-08-21 05:11:02 UTC (rev 64120)
@@ -24,6 +24,7 @@
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <glib.h>
@@ -65,10 +66,14 @@
 void
 g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar 
*format, va_list args)
 {
+       char *msg;
+       
+       vasprintf (&msg, format, args);
        printf ("%s%s%s",
                log_domain != NULL ? log_domain : "",
                log_domain != NULL ? ": " : "",
-               format);
+               msg);
+       free (msg);
        if (log_level & fatal)
                abort ();
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to