applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[platform/upstream/glib.git] / glib / grel.c
index 544da6b..9e4f328 100644 (file)
@@ -2,20 +2,27 @@
  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+/*
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
 /* 
  * MT safe
  */
@@ -146,8 +153,10 @@ g_relation_index (GRelation   *relation,
                  GCompareFunc key_compare_func)
 {
   GRealRelation *rel = (GRealRelation *) relation;
+
+  g_return_if_fail (relation != NULL);
   
-  g_assert (rel->count == 0 && rel->hashed_tuple_tables[field] == NULL);
+  g_return_if_fail (rel->count == 0 && rel->hashed_tuple_tables[field] == NULL);
   
   rel->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_compare_func);
 }
@@ -197,7 +206,9 @@ g_relation_insert (GRelation   *relation,
 }
 
 static void
-g_relation_delete_tuple (gpointer tuple_key, gpointer tuple_value, gpointer user_data)
+g_relation_delete_tuple (gpointer tuple_key,
+                        gpointer tuple_value,
+                        gpointer user_data)
 {
   gpointer      *tuple = (gpointer*) tuple_value;
   GRealRelation *rel = (GRealRelation *) user_data;
@@ -231,16 +242,17 @@ g_relation_delete_tuple (gpointer tuple_key, gpointer tuple_value, gpointer user
 }
 
 gint
-g_relation_delete  (GRelation   *relation,
+g_relation_delete  (GRelation     *relation,
                    gconstpointer  key,
-                   gint         field)
+                   gint           field)
 {
   GRealRelation *rel = (GRealRelation *) relation;
   GHashTable *table = rel->hashed_tuple_tables[field];
   GHashTable *key_table;
   gint        count = rel->count;
   
-  g_assert (table);
+  g_return_val_if_fail (relation != NULL, 0);
+  g_return_val_if_fail (table != NULL, 0);
   
   key_table = g_hash_table_lookup (table, key);
   
@@ -261,7 +273,9 @@ g_relation_delete  (GRelation   *relation,
 }
 
 static void
-g_relation_select_tuple (gpointer tuple_key, gpointer tuple_value, gpointer user_data)
+g_relation_select_tuple (gpointer tuple_key,
+                        gpointer tuple_value,
+                        gpointer user_data)
 {
   gpointer    *tuple = (gpointer*) tuple_value;
   GRealTuples *tuples = (GRealTuples*) user_data;
@@ -277,9 +291,9 @@ g_relation_select_tuple (gpointer tuple_key, gpointer tuple_value, gpointer user
 }
 
 GTuples*
-g_relation_select (GRelation   *relation,
+g_relation_select (GRelation     *relation,
                   gconstpointer  key,
-                  gint         field)
+                  gint           field)
 {
   GRealRelation *rel = (GRealRelation *) relation;
   GHashTable  *table = rel->hashed_tuple_tables[field];
@@ -287,7 +301,8 @@ g_relation_select (GRelation   *relation,
   GRealTuples *tuples = g_new0 (GRealTuples, 1);
   gint count;
   
-  g_assert (table);
+  g_return_val_if_fail (relation != NULL, NULL);
+  g_return_val_if_fail (table != NULL, NULL);
   
   key_table = g_hash_table_lookup (table, key);
   
@@ -307,15 +322,16 @@ g_relation_select (GRelation   *relation,
 }
 
 gint
-g_relation_count (GRelation   *relation,
+g_relation_count (GRelation     *relation,
                  gconstpointer  key,
-                 gint         field)
+                 gint           field)
 {
   GRealRelation *rel = (GRealRelation *) relation;
   GHashTable  *table = rel->hashed_tuple_tables[field];
   GHashTable  *key_table;
   
-  g_assert (table);
+  g_return_val_if_fail (relation != NULL, 0);
+  g_return_val_if_fail (table != NULL, 0);
   
   key_table = g_hash_table_lookup (table, key);
   
@@ -367,7 +383,8 @@ g_tuples_index (GTuples     *tuples0,
 {
   GRealTuples *tuples = (GRealTuples*) tuples0;
   
-  g_assert (field < tuples->width);
+  g_return_val_if_fail (tuples0 != NULL, NULL);
+  g_return_val_if_fail (field < tuples->width, NULL);
   
   return tuples->data[index * tuples->width + field];
 }