ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since fb2ce27 was             fb2ce27, checked in by Aaron Moss <a3moss@…>, 8 years ago | 
        
          | 
Update all benchmarks to match new CFA
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.1 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <stdlib.h> | 
|---|
| 2 | #include "c-stack.h" | 
|---|
| 3 |  | 
|---|
| 4 | struct stack_node { | 
|---|
| 5 | void* value; | 
|---|
| 6 | struct stack_node* next; | 
|---|
| 7 | }; | 
|---|
| 8 |  | 
|---|
| 9 | struct stack new_stack() { return (struct stack){ NULL }; /***/ } | 
|---|
| 10 |  | 
|---|
| 11 | void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) { | 
|---|
| 12 | struct stack_node** crnt = &s->head; | 
|---|
| 13 | for ( struct stack_node* next = t->head; next; next = next->next ) { | 
|---|
| 14 | *crnt = malloc(sizeof(struct stack_node)); /***/ | 
|---|
| 15 | (*crnt)->value = copy(next->value); | 
|---|
| 16 | crnt = &(*crnt)->next; | 
|---|
| 17 | } | 
|---|
| 18 | *crnt = NULL; | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | void clear_stack(struct stack* s, void (*free_el)(void*)) { | 
|---|
| 22 | for ( struct stack_node* next = s->head; next; ) { | 
|---|
| 23 | struct stack_node* crnt = next; | 
|---|
| 24 | next = crnt->next; | 
|---|
| 25 | free_el(crnt->value); | 
|---|
| 26 | free(crnt); | 
|---|
| 27 | } | 
|---|
| 28 | s->head = NULL; | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | _Bool stack_empty(const struct stack* s) { return s->head == NULL; } | 
|---|
| 32 |  | 
|---|
| 33 | void push_stack(struct stack* s, void* value) { | 
|---|
| 34 | struct stack_node* n = malloc(sizeof(struct stack_node)); /***/ | 
|---|
| 35 | *n = (struct stack_node){ value, s->head }; /***/ | 
|---|
| 36 | s->head = n; | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | void* pop_stack(struct stack* s) { | 
|---|
| 40 | struct stack_node* n = s->head; | 
|---|
| 41 | s->head = n->next; | 
|---|
| 42 | void* x = n->value; | 
|---|
| 43 | free(n); | 
|---|
| 44 | return x; | 
|---|
| 45 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.