This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: "[PATCH] - cpplib mem init"
On Mon, Jul 10, 2000 at 11:43:48AM -0700, Donn Terry wrote:
>Later code assumes that pfile->contexts is initialized to zero; make it so.
>(This fixes a real bug that I ran across.)
I believe it should only be necessary to clear the base context; all
other contexts are properly initialized when they are stacked.
>Also, add casts to a couple of memory management calls to cast away
>const-ness, which some compilers complain about.
This needs to be writen (PTR) whatever, not (void *) whatever, in
order to play nice with K+R compilers.
I'm testing this modified version of your patch; mind giving it a
whirl yourself? (It will be offset due to other changes in my tree
which I've edited out of the patch.)
zw
===================================================================
Index: cpplex.c
--- cpplex.c 2000/07/09 09:19:44 1.66
+++ cpplex.c 2000/07/11 01:48:20
@@ -1994,7 +1990,7 @@ free_macro_args (args)
macro_args *args;
{
if (args->tokens)
- free (args->tokens);
+ free ((PTR) args->tokens);
free (args->ends);
free (args);
}
@@ -2090,7 +2086,8 @@ save_token (args, token)
{
args->capacity += args->capacity + 100;
args->tokens = (const cpp_token **)
- xrealloc (args->tokens, args->capacity * sizeof (const cpp_token *));
+ xrealloc ((PTR) args->tokens,
+ args->capacity * sizeof (const cpp_token *));
}
args->tokens[args->used++] = token;
}
@@ -3274,18 +3276,26 @@ void
_cpp_init_input_buffer (pfile)
cpp_reader *pfile;
{
+ cpp_context *base;
+
init_trigraph_map ();
+ _cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN);
+ pfile->no_expand_level = UINT_MAX;
pfile->context_cap = 20;
- pfile->contexts = (cpp_context *)
- xmalloc (pfile->context_cap * sizeof (cpp_context));
pfile->cur_context = 0;
- pfile->contexts[0].u.list = &pfile->token_list;
- pfile->contexts[0].posn = 0;
- pfile->contexts[0].count = 0;
- pfile->no_expand_level = UINT_MAX;
+ pfile->contexts = (cpp_context *)
+ xmalloc (pfile->context_cap * sizeof (cpp_context));
- _cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN);
+ /* Clear the base context. */
+ base = &pfile->contexts[0];
+ base->u.list = &pfile->token_list;
+ base->posn = 0;
+ base->count = 0;
+ base->args = 0;
+ base->level = 0;
+ base->flags = 0;
+ base->pushed_token = 0;
}
/* Moves to the end of the directive line, popping contexts as