Hacked const and volatile modifiers a bit
[fw/sdcc] / src / SDCCset.c
index 61b68a05931d5364ba28ee3ae7131897fd0edd46..5014303f18d63a0b6c2e615d5a6975b137d21fcc 100644 (file)
@@ -31,7 +31,7 @@
 /* newSet - will allocate & return a new set entry             */
 /*-----------------------------------------------------------------*/
 set *
-newSet ()
+newSet (void)
 {
   set *lp;
 
@@ -203,26 +203,24 @@ deleteSetItem (set ** list, void *item)
     return;
 
   /* if this item is at the head of the list */
-  if ((*list)->item == item)
-    {
-      lp = *list;
-      *list = (*list)->next;
-      return;
-    }
+  if ((*list)->item == item) {
+    lp = *list;
+    *list = (*list)->next;
+    Safe_free (lp);
+    return;
+  }
 
   /* find the item in the list */
-  for (lp = *list; lp->next; lp = lp->next)
-    {
-      if (lp->next->item == item)      /* the next one is it */
-       {
-         lp1 = lp->next;       /* this one will need to be freed */
-         lp->next = lp->next->next;    /* take out of list */
-         return;
-       }
+  for (lp = *list; lp->next; lp = lp->next) {
+    if (lp->next->item == item) { /* the next one is it */
+      lp1 = lp->next;             /* this one will need to be freed */
+      lp->next = lp->next->next;  /* take out of list */
+      Safe_free (lp1);
+      return;
     }
+  }
 
   /* could not find it */
-  return;
 }
 
 /*-----------------------------------------------------------------*/
@@ -576,3 +574,30 @@ setToNull (void **item)
   Safe_free (*item);
   *item = NULL;
 }
+
+/*-----------------------------------------------------------------*/
+/* deleteSet - will throw away the entire list                     */
+/*  note - setToNull doesn't actually throw away the whole list.   */
+/*         Instead it only throws away the first item.             */
+/*-----------------------------------------------------------------*/
+void deleteSet(set **s)
+{
+  set *curr;
+  set *next;
+
+  if(!s || !*s)
+    return;
+
+  curr = *s;
+  next = curr->next;
+  while (next) {
+    Safe_free (curr);
+    curr = next;
+    next = next->next;
+  }
+
+  Safe_free (curr);
+
+  *s = NULL;
+}
+