summaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-28 09:40:22 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-28 09:40:22 +0000
commit1fdf6039a543331eeabe2198b36e89fd0a3bd06d (patch)
tree04de76def0a1a191465d81cb782799aeec34587f /gcc/cpplib.c
parent012dc873918b9c28244b2e353fba69870c3c8de4 (diff)
downloadgcc-1fdf6039a543331eeabe2198b36e89fd0a3bd06d.tar.gz
* cpphash.h (struct cpp_buff): Make unsigned.
(_cpp_get_buff): Take length of size_t. (_cpp_unaligned_alloc): New. (BUFF_ROOM, BUFF_FRONT, BUFF_LIMIT): New. (struct cpp_reader): Remove ident_pool. Add u_buff. * cppinit.c (cpp_create_reader): Initialize u_buff, not ident_pool. (cpp_destroy): Destroy u_buff, not ident_pool. * cpplex.c (parse_number, parse_string, save_comment, cpp_token_as_text): Update to use the unaligned buffer. (new_buff): Make unsigned. (_cpp_unaligned_alloc): New. * cpplib.c (glue_header_name): Update to use the unaligned buffer. * cppmacro.c (new_number_token, builtin_macro, stringify_arg): Similarly. (collect_args): Make unsigned. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45858 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index d164b4e2492..2d5968a37c8 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -493,13 +493,13 @@ glue_header_name (pfile)
{
cpp_token *header = NULL;
const cpp_token *token;
- unsigned char *buffer, *token_mem;
- size_t len, total_len = 0, capacity = 1024;
+ unsigned char *dest;
+ size_t len;
/* To avoid lexed tokens overwriting our glued name, we can only
allocate from the string pool once we've lexed everything. */
- buffer = (unsigned char *) xmalloc (capacity);
+ dest = BUFF_FRONT (pfile->u_buff);
for (;;)
{
token = cpp_get_token (pfile);
@@ -507,35 +507,34 @@ glue_header_name (pfile)
if (token->type == CPP_GREATER || token->type == CPP_EOF)
break;
- len = cpp_token_len (token);
- if (total_len + len > capacity)
+ /* + 1 for terminating NUL. */
+ len = cpp_token_len (token) + 1;
+ if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
{
- capacity = (capacity + len) * 2;
- buffer = (unsigned char *) xrealloc (buffer, capacity);
+ size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
+ pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, len);
+ dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
}
if (token->flags & PREV_WHITE)
- buffer[total_len++] = ' ';
+ *dest++ = ' ';
- total_len = cpp_spell_token (pfile, token, &buffer[total_len]) - buffer;
+ dest = cpp_spell_token (pfile, token, dest);
}
if (token->type == CPP_EOF)
cpp_error (pfile, "missing terminating > character");
else
{
- token_mem = _cpp_pool_alloc (&pfile->ident_pool, total_len + 1);
- memcpy (token_mem, buffer, total_len);
- token_mem[total_len] = '\0';
-
header = _cpp_temp_token (pfile);
header->type = CPP_HEADER_NAME;
- header->flags &= ~PREV_WHITE;
- header->val.str.len = total_len;
- header->val.str.text = token_mem;
+ header->flags = 0;
+ header->val.str.len = dest - BUFF_FRONT (pfile->u_buff);
+ header->val.str.text = BUFF_FRONT (pfile->u_buff);
+ *dest++ = '\0';
+ BUFF_FRONT (pfile->u_buff) = dest;
}
- free ((PTR) buffer);
return header;
}