* src/mcs51/gen.c (genMinus): fixed bug 696436
[fw/sdcc] / src / SDCCset.c
index f56b6cf4d1644c046e94c910d716f36b2dffbd1a..3007157c73afe0d68e42207bd8442f275929fec6 100644 (file)
 -------------------------------------------------------------------------*/
 
 #include <stdio.h>
-#if defined(__APPLE__) && defined(__MACH__)
-#include <sys/malloc.h>
-#else
-#include <malloc.h>
-#endif
 #include "newalloc.h"
 #include <assert.h>
 #include "SDCCset.h"
 /* newSet - will allocate & return a new set entry             */
 /*-----------------------------------------------------------------*/
 set *
-newSet ()
+newSet (void)
 {
   set *lp;
 
-  lp = Safe_calloc (1, sizeof (set));
+  lp = Safe_alloc ( sizeof (set));
 //  if (lp == 0) {
   //  fprintf(stderr, "out of virtual memory: %s\n", __FILE__);
   //  exit(1);
@@ -409,6 +404,26 @@ elementsInSet (set * s)
   return count;
 }
 
+/*-----------------------------------------------------------------*/
+/* reverseSet - reverse the order of the items of a set            */
+/*-----------------------------------------------------------------*/
+
+set *
+reverseSet(set * s)
+{
+  set *t = NULL;
+  set *u = NULL;
+
+  while(s->next) {
+    t = s->next;
+    s->next = u;
+    u = s;
+    s = t;
+  }
+  s->next = u;
+  return s;
+}
+
 /*-----------------------------------------------------------------*/
 /* subtractFromSet - take away from set1 elements of set2          */
 /*-----------------------------------------------------------------*/
@@ -558,6 +573,33 @@ setToNull (void **item)
 
   if (!*item)
     return;
-  free (*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;
+}
+