PATCH: abstract over necessary casts for obstack_finish
Gabriel Dos Reis
gdr@integrable-solutions.net
Mon Jun 6 19:21:00 GMT 2005
Hi,
There are quite a few uses of obstack_finish() that need explicit
cast to seat at the intersection of C90 and C++. Instead of
springling casts here and there, I'm proposing a macro, XOBFINISH()
-- in the spirit of existing ones -- for addition to libiberty.h.
This patch contains that and its application to gcc/*.c.
Bootstrapped and tested on an i686-pc-linux-gnu.
OK?
-- Gaby
libiberty/
2005-06-06 Gabriel Dos Reis <gdr@integrable-solutions.net>
* libiberty.h (XOBFINISH): New.
gcc/
2005-06-06 Gabriel Dos Reis <gdr@integrable-solutions.net>
* c-lex.c (lex_string): Use XOBFINISH.
* collect2.c (extract_string, dump_file): Likewise.
* dbxout.c (dbxout_finish_complex_stabs): Likewise.
* gcc.c (init_spec, build_search_list, convert_filename,
set_collect_gcc_options, do_spec_2, do_spec_1, main): Likewise.
* genpreds.c (write_predicate_subfunction): Likewise.
* genflags.c (main): Likewise.
* read-rtl.c (mode_attr_index, apply_macro_to_string,
join_c_conditions, read_quoted_string, read_braced_string,
read_rtx_1): Likewise.
* stringpool.c (ggc_alloc_string): Likewise.
* tlink.c (obstack_fgets, recompile_files): Likewise.
Index: gcc/c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.248
diff -u -r1.248 c-lex.c
--- gcc/c-lex.c 25 May 2005 03:58:54 -0000 1.248
+++ gcc/c-lex.c 6 Jun 2005 18:33:33 -0000
@@ -762,7 +762,7 @@
/* We have read one more token than we want. */
_cpp_backup_tokens (parse_in, 1);
if (concats)
- strs = (cpp_string *) obstack_finish (&str_ob);
+ strs = XOBFINISH (&str_ob, cpp_string *);
if (concats && !objc_string && !in_system_header)
warning (OPT_Wtraditional,
Index: gcc/collect2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/collect2.c,v
retrieving revision 1.175
diff -u -r1.175 collect2.c
--- gcc/collect2.c 3 Jun 2005 10:48:06 -0000 1.175
+++ gcc/collect2.c 6 Jun 2005 18:33:33 -0000
@@ -453,7 +453,7 @@
obstack_1grow (&temporary_obstack, '\0');
*pp = p;
- return obstack_finish (&temporary_obstack);
+ return XOBFINISH (&temporary_obstack, char *);
}
void
@@ -474,7 +474,7 @@
const char *word, *p;
char *result;
obstack_1grow (&temporary_obstack, '\0');
- word = obstack_finish (&temporary_obstack);
+ word = XOBFINISH (&temporary_obstack, const char *);
if (*word == '.')
++word, putc ('.', to);
Index: gcc/dbxout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dbxout.c,v
retrieving revision 1.234
diff -u -r1.234 dbxout.c
--- gcc/dbxout.c 17 May 2005 20:11:41 -0000 1.234
+++ gcc/dbxout.c 6 Jun 2005 18:33:35 -0000
@@ -856,7 +856,7 @@
obstack_1grow (&stabstr_ob, '\0');
len = obstack_object_size (&stabstr_ob);
- chunk = str = obstack_finish (&stabstr_ob);
+ chunk = str = XOBFINISH (&stabstr_ob, char *);
/* Within the buffer are a sequence of NUL-separated strings,
each of which is to be written out as a separate stab
@@ -889,7 +889,7 @@
comma than to do a two-character fputs. */
obstack_grow (&stabstr_ob, "\",", 2);
len = obstack_object_size (&stabstr_ob);
- str = obstack_finish (&stabstr_ob);
+ str = XOBFINISH (&stabstr_ob, char *);
fwrite (str, 1, len, asm_out_file);
DBX_FINISH_STABS (sym, code, line, addr, label, number);
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.458
diff -u -r1.458 gcc.c
--- gcc/gcc.c 15 May 2005 17:06:16 -0000 1.458
+++ gcc/gcc.c 6 Jun 2005 18:33:39 -0000
@@ -1736,7 +1736,7 @@
}
obstack_1grow (&obstack, '\0');
- libgcc_spec = obstack_finish (&obstack);
+ libgcc_spec = XOBFINISH (&obstack, const char *);
}
#endif
#ifdef USE_AS_TRADITIONAL_FORMAT
@@ -1745,14 +1745,14 @@
static const char tf[] = "--traditional-format ";
obstack_grow (&obstack, tf, sizeof(tf) - 1);
obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
- asm_spec = obstack_finish (&obstack);
+ asm_spec = XOBFINISH (&obstack, const char *);
}
#endif
#ifdef LINK_EH_SPEC
/* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1);
obstack_grow0 (&obstack, link_spec, strlen (link_spec));
- link_spec = obstack_finish (&obstack);
+ link_spec = XOBFINISH (&obstack, const char *);
#endif
specs = sl;
@@ -2393,7 +2393,7 @@
}
obstack_1grow (&collect_obstack, '\0');
- return obstack_finish (&collect_obstack);
+ return XOBFINISH (&collect_obstack, char *);
}
/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
@@ -2980,7 +2980,7 @@
{
obstack_grow (&obstack, name, len - 2);
obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
- name = obstack_finish (&obstack);
+ name = XOBFINISH (&obstack, const char *);
}
#endif
@@ -3001,7 +3001,7 @@
obstack_grow (&obstack, name, len);
obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
strlen (TARGET_EXECUTABLE_SUFFIX));
- name = obstack_finish (&obstack);
+ name = XOBFINISH (&obstack, const char *);
#endif
return name;
@@ -4154,7 +4154,7 @@
}
}
obstack_grow (&collect_obstack, "\0", 1);
- putenv (obstack_finish (&collect_obstack));
+ putenv (XOBFINISH (&collect_obstack, char *));
}
/* Process a spec string, accumulating and running commands. */
@@ -4253,7 +4253,7 @@
if (arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -4488,7 +4488,7 @@
if (arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -4533,7 +4533,7 @@
if (arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -4552,7 +4552,7 @@
if (arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -4914,7 +4914,7 @@
if (arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -5243,7 +5243,7 @@
if (processing_spec_function && arg_going)
{
obstack_1grow (&obstack, 0);
- string = obstack_finish (&obstack);
+ string = XOBFINISH (&obstack, const char *);
if (this_is_library_file)
string = find_file (string);
store_arg (string, delete_this_arg, this_is_output_file);
@@ -6037,21 +6037,21 @@
obstack_grow (&multilib_obstack, p, strlen (p));
obstack_1grow (&multilib_obstack, 0);
- multilib_select = obstack_finish (&multilib_obstack);
+ multilib_select = XOBFINISH (&multilib_obstack, const char *);
q = multilib_matches_raw;
while ((p = *q++) != (char *) 0)
obstack_grow (&multilib_obstack, p, strlen (p));
obstack_1grow (&multilib_obstack, 0);
- multilib_matches = obstack_finish (&multilib_obstack);
+ multilib_matches = XOBFINISH (&multilib_obstack, const char *);
q = multilib_exclusions_raw;
while ((p = *q++) != (char *) 0)
obstack_grow (&multilib_obstack, p, strlen (p));
obstack_1grow (&multilib_obstack, 0);
- multilib_exclusions = obstack_finish (&multilib_obstack);
+ multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
need_space = FALSE;
for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
@@ -6065,7 +6065,7 @@
}
obstack_1grow (&multilib_obstack, 0);
- multilib_defaults = obstack_finish (&multilib_obstack);
+ multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
}
/* Set up to remember the pathname of gcc and any options
@@ -6074,7 +6074,7 @@
obstack_init (&collect_obstack);
obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
- putenv (obstack_finish (&collect_obstack));
+ putenv (XOBFINISH (&collect_obstack, char *));
#ifdef INIT_ENVIRONMENT
/* Set up any other necessary machine specific environment variables. */
@@ -6160,7 +6160,7 @@
{
obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
obstack_grow0 (&obstack, link_spec, strlen (link_spec));
- set_spec ("link", obstack_finish (&obstack));
+ set_spec ("link", XOBFINISH (&obstack, const char *));
}
#endif
@@ -6349,7 +6349,7 @@
obstack_init (&obstack);
do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
obstack_1grow (&obstack, '\0');
- thrmod = obstack_finish (&obstack);
+ thrmod = XOBFINISH (&obstack, const char *);
#else
thrmod = thread_model;
#endif
@@ -7071,7 +7071,7 @@
obstack_grow (&multilib_obstack, start, end - start);
obstack_1grow (&multilib_obstack, 0);
- mdswitches[i].str = obstack_finish (&multilib_obstack);
+ mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
mdswitches[i++].len = end - start;
if (*end == '\0')
Index: gcc/genflags.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genflags.c,v
retrieving revision 1.53
diff -u -r1.53 genflags.c
--- gcc/genflags.c 9 Sep 2004 13:22:33 -0000 1.53
+++ gcc/genflags.c 6 Jun 2005 18:33:39 -0000
@@ -267,7 +267,7 @@
/* Print out the prototypes now. */
dummy = (rtx) 0;
obstack_grow (&obstack, &dummy, sizeof (rtx));
- insns = (rtx *) obstack_finish (&obstack);
+ insns = XOBFINISH (&obstack, rtx *);
for (insn_ptr = insns; *insn_ptr; insn_ptr++)
gen_proto (*insn_ptr);
Index: gcc/genpreds.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genpreds.c,v
retrieving revision 1.15
diff -u -r1.15 genpreds.c
--- gcc/genpreds.c 4 Mar 2005 11:10:34 -0000 1.15
+++ gcc/genpreds.c 6 Jun 2005 18:33:39 -0000
@@ -122,7 +122,7 @@
obstack_grow (rtl_obstack, p->name, strlen (p->name));
obstack_grow (rtl_obstack, "_1 (op, mode)",
sizeof "_1 (op, mode)");
- match_test_str = obstack_finish (rtl_obstack);
+ match_test_str = XOBFINISH (rtl_obstack, const char *);
/* Add the function-call expression to the complete expression to be
evaluated. */
Index: gcc/read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.39
diff -u -r1.39 read-rtl.c
--- gcc/read-rtl.c 18 May 2005 13:46:39 -0000 1.39
+++ gcc/read-rtl.c 6 Jun 2005 18:33:40 -0000
@@ -321,7 +321,7 @@
/* Copy the attribute string into permanent storage, without the
angle brackets around it. */
obstack_grow0 (&string_obstack, string + 1, strlen (string) - 2);
- p = (char *) obstack_finish (&string_obstack);
+ p = XOBFINISH (&string_obstack, char *);
mv = XNEW (struct map_value);
mv->number = *mode_maps == 0 ? 0 : (*mode_maps)->number + 1;
@@ -404,7 +404,7 @@
if (base != copy)
{
obstack_grow (&string_obstack, base, strlen (base) + 1);
- copy = obstack_finish (&string_obstack);
+ copy = XOBFINISH (&string_obstack, char *);
copy_rtx_ptr_loc (copy, string);
return copy;
}
@@ -785,7 +785,7 @@
obstack_ptr_grow (&joined_conditions_obstack, result);
obstack_ptr_grow (&joined_conditions_obstack, cond1);
obstack_ptr_grow (&joined_conditions_obstack, cond2);
- entry = obstack_finish (&joined_conditions_obstack);
+ entry = XOBFINISH (&joined_conditions_obstack, const void **);
*htab_find_slot (joined_conditions, entry, INSERT) = entry;
return result;
}
@@ -998,7 +998,7 @@
}
obstack_1grow (&string_obstack, 0);
- return (char *) obstack_finish (&string_obstack);
+ return XOBFINISH (&string_obstack, char *);
}
/* Read a braced string (a la Tcl) onto the string obstack. Caller
@@ -1036,7 +1036,7 @@
}
obstack_1grow (&string_obstack, 0);
- return (char *) obstack_finish (&string_obstack);
+ return XOBFINISH (&string_obstack, char *);
}
/* Read some kind of string constant. This is the high-level routine
@@ -1581,7 +1581,7 @@
obstack_grow (&string_obstack, fn, strlen (fn));
sprintf (line_name, ":%d", read_rtx_lineno);
obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
- stringbuf = (char *) obstack_finish (&string_obstack);
+ stringbuf = XOBFINISH (&string_obstack, char *);
}
if (star_if_braced)
Index: gcc/stringpool.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stringpool.c,v
retrieving revision 1.28
diff -u -r1.28 stringpool.c
--- gcc/stringpool.c 14 Mar 2005 13:10:51 -0000 1.28
+++ gcc/stringpool.c 6 Jun 2005 18:33:40 -0000
@@ -95,7 +95,7 @@
return digit_string (contents[0] - '0');
obstack_grow0 (&string_stack, contents, length);
- return obstack_finish (&string_stack);
+ return XOBFINISH (&string_stack, const char *);
}
/* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
Index: gcc/tlink.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tlink.c,v
retrieving revision 1.62
diff -u -r1.62 tlink.c
--- gcc/tlink.c 31 Mar 2005 14:53:17 -0000 1.62
+++ gcc/tlink.c 6 Jun 2005 18:33:40 -0000
@@ -311,7 +311,7 @@
if (obstack_object_size (ob) == 0)
return NULL;
obstack_1grow (ob, '\0');
- return obstack_finish (ob);
+ return XOBFINISH (ob, char *);
}
static char *
@@ -528,7 +528,7 @@
done:
obstack_ptr_grow (&temporary_obstack, f->main);
obstack_ptr_grow (&temporary_obstack, NULL);
- argv = obstack_finish (&temporary_obstack);
+ argv = XOBFINISH (&temporary_obstack, char **);
if (tlink_verbose)
fprintf (stderr, _("collect: recompiling %s\n"), f->main);
Index: gcc/tree-sra.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-sra.c,v
retrieving revision 2.61
diff -u -r2.61 tree-sra.c
--- gcc/tree-sra.c 1 Jun 2005 02:50:58 -0000 2.61
+++ gcc/tree-sra.c 6 Jun 2005 18:33:41 -0000
@@ -1094,7 +1094,7 @@
{
build_element_name_1 (elt);
obstack_1grow (&sra_obstack, '\0');
- return obstack_finish (&sra_obstack);
+ return XOBFINISH (&sra_obstack, char *);
}
/* Instantiate an element as an independent variable. */
Index: include/libiberty.h
===================================================================
RCS file: /cvs/gcc/gcc/include/libiberty.h,v
retrieving revision 1.58
diff -u -r1.58 libiberty.h
--- include/libiberty.h 2 Jun 2005 02:01:03 -0000 1.58
+++ include/libiberty.h 6 Jun 2005 18:33:50 -0000
@@ -326,7 +326,7 @@
/* Type-safe obstack allocator. */
#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
-
+#define XOBFINISH(O, T) ((T) obstack_finish ((O)))
/* hex character manipulation routines */
More information about the Gcc-patches
mailing list