diff options
author | Mike Karr <mkarr@mathworks.com> | 1999-12-02 16:31:58 +0000 |
---|---|---|
committer | Dave Brolley <brolley@gcc.gnu.org> | 1999-12-02 11:31:58 -0500 |
commit | 0e5732f2b545bdacb18461bbb28d36503cecfd98 (patch) | |
tree | e4ec6d5ffc4e3d8b332654cbbed004c3c45a91c0 /gcc/cccp.c | |
parent | bc622faec91f80027c6dc146f9120fd50001d75a (diff) | |
download | gcc-0e5732f2b545bdacb18461bbb28d36503cecfd98.zip gcc-0e5732f2b545bdacb18461bbb28d36503cecfd98.tar.gz gcc-0e5732f2b545bdacb18461bbb28d36503cecfd98.tar.bz2 |
cccp.c (argdata): Added free_ptr member.
1999-12-02 Mike Karr <mkarr@mathworks.com>
* cccp.c (argdata): Added free_ptr member.
(macroexpand): Initialize free_ptr of each argument. When an
argument's buffers are freed, if the argument's free_ptr corresponds
to a buffer on the input stack, then return the free_ptr to that stack
frame, otherwise, free it.
(macarg): If an argument begins and ends on the same input stack level,
then transfer the free_ptr of that buffer to the argument in case
the stack is popped during the processing of a subsequent argument.
From-SVN: r30760
Diffstat (limited to 'gcc/cccp.c')
-rw-r--r-- | gcc/cccp.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -8443,13 +8443,19 @@ output_line_directive (ip, op, conditional, file_change) into the macro. If the actual use count exceeds 10, the value stored is 10. `free1' and `free2', if nonzero, point to blocks to be freed - when the macro argument data is no longer needed. */ + when the macro argument data is no longer needed. + `free_ptr', if nonzero, points to a value of instack[i].free_ptr + where the raw field points somewhere into this string. The purpose + of this is to hold onto instack[i].buf for macro arguments, even + when the element has been popped off the input stack. +*/ struct argdata { U_CHAR *raw, *expanded; int raw_length, expand_length, expand_size; int stringified_length_bound; U_CHAR *free1, *free2; + U_CHAR *free_ptr; char newlines; char use_count; }; @@ -8502,6 +8508,7 @@ macroexpand (hp, op) args[i].raw_length = args[i].expand_length = args[i].expand_size = args[i].stringified_length_bound = 0; args[i].free1 = args[i].free2 = 0; + args[i].free_ptr = 0; args[i].use_count = 0; } @@ -8845,6 +8852,18 @@ macroexpand (hp, op) xbuf_len = totlen; for (i = 0; i < nargs; i++) { + if (args[i].free_ptr != 0) { + U_CHAR *buf = args[i].free_ptr; + int d; + for (d = indepth; d >= 0; --d) { + if (instack[d].buf == buf) { + instack[d].free_ptr = buf; /* Give ownership back to instack */ + goto no_free; + } + } + free (buf); /* buf is not on the stack; must have been popped */ + no_free:; + } if (args[i].free1 != 0) free (args[i].free1); if (args[i].free2 != 0) @@ -8915,6 +8934,11 @@ macarg (argptr, rest_args) argptr->raw = ip->bufp; argptr->raw_length = bp - ip->bufp; argptr->newlines = ip->lineno - lineno0; + /* The next two statements transfer ownership of the the buffer + from ip to argptr. Note that the second statement ensures that + a given free_ptr is owned by at most one macro argument. */ + argptr->free_ptr = ip->free_ptr; + ip->free_ptr = 0; } ip->bufp = bp; } else { |