Ignore:
Timestamp:
Apr 19, 2017, 10:15:45 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
cd348e7
Parents:
221c2de (diff), de4ce0e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/c-stack.c

    r221c2de r154fdc8  
    77};
    88
    9 struct stack new_stack() {
    10         return (struct stack){ NULL };
     9struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     10
     11void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) {
     12        struct stack_node** crnt = &s->head;
     13        struct stack_node* next = t->head;
     14        while ( next ) {
     15                *crnt = malloc(sizeof(struct stack_node)); /***/
     16                **crnt = (struct stack_node){ copy(next->value) }; /***/
     17                crnt = &(*crnt)->next;
     18                next = next->next;
     19        }
     20        *crnt = 0;
    1121}
    1222
    13 void clear_stack(struct stack* s) {
     23void clear_stack(struct stack* s, void (*free_el)(void*)) {
    1424        struct stack_node* next = s->head;
    1525        while ( next ) {
    1626                struct stack_node* crnt = next;
    1727                next = crnt->next;
    18                 free(crnt->value);
     28                free_el(crnt->value);
    1929                free(crnt);
    2030        }
     31        s->head = NULL;
    2132}
    2233
    23 _Bool stack_empty(const struct stack* s) {
    24         return s->head == NULL;
    25 }
     34_Bool stack_empty(const struct stack* s) { return s->head == NULL; }
    2635
    2736void push_stack(struct stack* s, void* value) {
    28         struct stack_node* n = malloc(sizeof(struct stack_node));
    29         *n = (struct stack_node){ value, s->head };
     37        struct stack_node* n = malloc(sizeof(struct stack_node)); /***/
     38        *n = (struct stack_node){ value, s->head }; /***/
    3039        s->head = n;
    3140}
Note: See TracChangeset for help on using the changeset viewer.