X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCset.c;h=3007157c73afe0d68e42207bd8442f275929fec6;hb=c2a0ea8e1e3331b8ea967a0c23cfaabf6fc33e59;hp=24e936aa440381f28daed9610ebfcd484ffd003b;hpb=29779804200986ce903b5086441b49265a122dc5;p=fw%2Fsdcc diff --git a/src/SDCCset.c b/src/SDCCset.c index 24e936aa..3007157c 100644 --- a/src/SDCCset.c +++ b/src/SDCCset.c @@ -31,11 +31,11 @@ /* 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); @@ -171,10 +171,13 @@ deleteItemIf (set ** sset, int (*cond) (void *, va_list),...) set *sp = *sset; va_list ap; - va_start (ap, cond); - while (sp) { + // On the x86 va_list is just a pointer, so due to pass by value + // ap is not mofified by the called function. On the PPC va_list + // is a pointer to a structure, so ap is modified. Re-init each time. + va_start (ap, cond); + if ((*cond) (sp->item, ap)) { deleteSetItem (sset, sp->item); @@ -182,6 +185,7 @@ deleteItemIf (set ** sset, int (*cond) (void *, va_list),...) continue; } + va_end(ap); sp = sp->next; } } @@ -400,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 */ /*-----------------------------------------------------------------*/ @@ -549,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; +} +