This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: dynamically allocate string constant "<internal>"
- To: gcc-patches at gcc dot gnu dot org
- Subject: C++ PATCH: dynamically allocate string constant "<internal>"
- From: Alex Samuel <samuel at codesourcery dot com>
- Date: Fri, 17 Sep 1999 15:25:26 -0700
- Organization: CodeSourcery, LLC
This patch replaces the string constant "<internal>" with a
dynamically allocated replacement. This string is referred to by tree
nodes and therefore will confuse GCs if statically allocated.
Alex Samuel
CodeSourcery, LLC
1999-09-17 Alex Samuel <samuel@codesourcery.com>
* lex.c (internal_filename): New variable.
(INTERNAL_FILENAME): New macro.
(init_parse): Allocate internal_filename and mark as root. Use it
instead of a string constant.
Index: lex.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/lex.c,v
retrieving revision 1.152
diff -c -r1.152 lex.c
*** lex.c 1999/09/16 22:33:10 1.152
--- lex.c 1999/09/17 21:59:20
***************
*** 213,218 ****
--- 213,223 ----
static struct impl_files *impl_file_chain;
+ /* The string used to represent the filename of internally generated
+ tree nodes. The variable, which is dynamically allocated, should
+ be used; the macro is only used to initialize it. */
+ static char *internal_filename;
+ #define INTERNAL_FILENAME ("<internal>")
/* Return something to represent absolute declarators containing a *.
TARGET is the absolute declarator that the * contains.
***************
*** 720,729 ****
gcc_obstack_init (&inline_text_obstack);
inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
/* Start it at 0, because check_newline is called at the very beginning
and will increment it to 1. */
lineno = 0;
! input_filename = "<internal>";
current_function_decl = NULL;
maxtoken = 40;
--- 725,737 ----
gcc_obstack_init (&inline_text_obstack);
inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
+ internal_filename = ggc_alloc_string (INTERNAL_FILENAME,
+ sizeof (INTERNAL_FILENAME));
+
/* Start it at 0, because check_newline is called at the very beginning
and will increment it to 1. */
lineno = 0;
! input_filename = internal_filename;
current_function_decl = NULL;
maxtoken = 40;
***************
*** 915,920 ****
--- 923,929 ----
ggc_add_tree_root (ansi_opname, LAST_CPLUS_TREE_CODE);
ggc_add_tree_root (ansi_assopname, LAST_CPLUS_TREE_CODE);
+ ggc_add_string_root (&internal_filename, 1);
ggc_add_tree_root (ridpointers, RID_MAX);
ggc_add_tree_root (&defarg_fns, 1);
ggc_add_tree_root (&defarg_parm, 1);