Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison macro.c @ 38:b156910b59b2
Wrap free() in dofree() to allow instrumenting it for debugging.
author | David A. Holland |
---|---|
date | Sat, 30 Mar 2013 21:02:25 -0400 (2013-03-31) |
parents | a5acb7049e4c |
children | 337110e7240a |
comparison
equal
deleted
inserted
replaced
37:70902cac4170 | 38:b156910b59b2 |
---|---|
108 static | 108 static |
109 void | 109 void |
110 expansionitem_destroy(struct expansionitem *ei) | 110 expansionitem_destroy(struct expansionitem *ei) |
111 { | 111 { |
112 if (ei->isstring) { | 112 if (ei->isstring) { |
113 free(ei->string); | 113 dofree(ei->string); |
114 } | 114 } |
115 free(ei); | 115 dofree(ei); |
116 } | 116 } |
117 | 117 |
118 static | 118 static |
119 bool | 119 bool |
120 expansionitem_eq(const struct expansionitem *ei1, | 120 expansionitem_eq(const struct expansionitem *ei1, |
160 void | 160 void |
161 macro_destroy(struct macro *m) | 161 macro_destroy(struct macro *m) |
162 { | 162 { |
163 expansionitemarray_destroyall(&m->expansion); | 163 expansionitemarray_destroyall(&m->expansion); |
164 expansionitemarray_cleanup(&m->expansion); | 164 expansionitemarray_cleanup(&m->expansion); |
165 free(m->name); | 165 dofree(m->name); |
166 free(m); | 166 dofree(m); |
167 } | 167 } |
168 | 168 |
169 static | 169 static |
170 bool | 170 bool |
171 macro_eq(const struct macro *m1, const struct macro *m2) | 171 macro_eq(const struct macro *m1, const struct macro *m2) |
632 expstate_cleanup(struct expstate *es) | 632 expstate_cleanup(struct expstate *es) |
633 { | 633 { |
634 assert(es->state == ES_NORMAL); | 634 assert(es->state == ES_NORMAL); |
635 stringarray_cleanup(&es->args); | 635 stringarray_cleanup(&es->args); |
636 if (es->buf) { | 636 if (es->buf) { |
637 free(es->buf); | 637 dofree(es->buf); |
638 } | 638 } |
639 } | 639 } |
640 | 640 |
641 static | 641 static |
642 void | 642 void |
644 { | 644 { |
645 unsigned i, num; | 645 unsigned i, num; |
646 | 646 |
647 num = stringarray_num(&es->args); | 647 num = stringarray_num(&es->args); |
648 for (i=0; i<num; i++) { | 648 for (i=0; i<num; i++) { |
649 free(stringarray_get(&es->args, i)); | 649 dofree(stringarray_get(&es->args, i)); |
650 } | 650 } |
651 stringarray_setsize(&es->args, 0); | 651 stringarray_setsize(&es->args, 0); |
652 } | 652 } |
653 | 653 |
654 static | 654 static |
655 void | 655 void |
656 expand_send(struct expstate *es, struct place *p, const char *buf, size_t len) | 656 expand_send(struct expstate *es, struct place *p, const char *buf, size_t len) |
657 { | 657 { |
658 if (es->tobuf) { | 658 if (es->tobuf) { |
659 assert(es->bufpos <= es->bufmax); | |
659 if (es->bufpos + len > es->bufmax) { | 660 if (es->bufpos + len > es->bufmax) { |
660 if (es->bufmax == 0) { | 661 if (es->bufmax == 0) { |
661 es->bufmax = 64; | 662 es->bufmax = 64; |
662 } | 663 } |
663 while (es->bufpos + len > es->bufmax) { | 664 while (es->bufpos + len > es->bufmax) { |
665 } | 666 } |
666 es->buf = dorealloc(es->buf, es->bufmax); | 667 es->buf = dorealloc(es->buf, es->bufmax); |
667 } | 668 } |
668 memcpy(es->buf + es->bufpos, buf, len); | 669 memcpy(es->buf + es->bufpos, buf, len); |
669 es->bufpos += len; | 670 es->bufpos += len; |
671 assert(es->bufpos <= es->bufmax); | |
670 } else { | 672 } else { |
671 output(p, buf, len); | 673 output(p, buf, len); |
672 } | 674 } |
673 } | 675 } |
674 | 676 |
794 assert(es->curmacro->inuse == false); | 796 assert(es->curmacro->inuse == false); |
795 es->curmacro->inuse = true; | 797 es->curmacro->inuse = true; |
796 | 798 |
797 newbuf = expand_substitute(p, es); | 799 newbuf = expand_substitute(p, es); |
798 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false); | 800 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false); |
799 free(newbuf); | 801 dofree(newbuf); |
800 expstate_destroyargs(es); | 802 expstate_destroyargs(es); |
801 doexpand(es, p, newbuf2, strlen(newbuf2)); | 803 doexpand(es, p, newbuf2, strlen(newbuf2)); |
802 free(newbuf2); | 804 dofree(newbuf2); |
803 | 805 |
804 es->curmacro->inuse = false; | 806 es->curmacro->inuse = false; |
805 } | 807 } |
806 | 808 |
807 static | 809 static |
847 ei = expansionitemarray_get(&m->expansion, 0); | 849 ei = expansionitemarray_get(&m->expansion, 0); |
848 assert(ei->isstring); | 850 assert(ei->isstring); |
849 newbuf = macroexpand(p, ei->string, | 851 newbuf = macroexpand(p, ei->string, |
850 strlen(ei->string), false); | 852 strlen(ei->string), false); |
851 doexpand(es, p, newbuf, strlen(newbuf)); | 853 doexpand(es, p, newbuf, strlen(newbuf)); |
852 free(newbuf); | 854 dofree(newbuf); |
853 m->inuse = false; | 855 m->inuse = false; |
854 } else { | 856 } else { |
855 es->curmacro = m; | 857 es->curmacro = m; |
856 es->state = ES_WANTLPAREN; | 858 es->state = ES_WANTLPAREN; |
857 } | 859 } |