shithub: mc

Download patch

ref: e6eb15dd1697de78a5be6bfff2dce13002c06b62
parent: 6150817f07afc55f77f9da56baa2383fcd53d9f2
author: Ori Bernstein <[email protected]>
date: Sat May 12 16:27:27 EDT 2012

Add a list free function.

    We could do it manually, but this is less error prone and
    cleaner.

--- a/8/reduce.c
+++ b/8/reduce.c
@@ -360,9 +360,7 @@
             /* drain the increment queue for this expr */
             for (i = 0; i < s->nqueue; i++)
                 append(s, s->incqueue[i]);
-            free(s->incqueue);
-            s->nqueue = 0;
-            s->incqueue = NULL;
+            lfree(&s->incqueue, &s->nqueue);
             break;
         case Nlit:
             r = n;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -296,8 +296,6 @@
 char *tyfmt(char *buf, size_t len, Type *t);
 char *tystr(Type *t);
 
-void tlappend(Type ***tl, int *len, Type *t);
-
 /* node creation */
 Node *mknode(int line, Ntype nt);
 Node *mkfile(char *name);
@@ -345,4 +343,5 @@
 Node *unpickle(FILE *fd);
 
 /* convenience func */
-void lappend(void *nl, size_t *len, void *n); /* ugly hack; nl is void* because void*** != @a*** */
+void lappend(void *l, size_t *len, void *n); /* ugly hack; nl is void* because void*** != @a*** */
+void lfree(void *l, size_t *len);
--- a/parse/util.c
+++ b/parse/util.c
@@ -104,3 +104,12 @@
     (*len)++;
 }
 
+void lfree(void *l, size_t *len)
+{
+    void ***pl;
+
+    assert(l != NULL);
+    pl = l;
+    free(*pl);
+    *len = 0;
+}