diff mbox

Speedups/Cleanups: End of GSOC patch collection

Message ID alpine.LNX.2.02.1208181927590.20463@localhost.localdomain
State New
Headers show

Commit Message

Dimitrios Apostolou Aug. 18, 2012, 4:36 p.m. UTC
Hi, these are the type-safe obstack macros that I use in other patches. As 
requested, I also changed XOBFINISH to return (T *) and changed all 
callers, felt a little strange to change (char *) to char. I also replaced 
all _obstack_begin() calls in libcpp with obstack_init() which is the 
documented way of allocating macros.


2012-08-18  Dimitrios Apostolou  <jimis@gmx.net>

 	* include/libiberty.h (XOBDELETE, XOBGROW, XOBGROWVEC, XOBSHRINK)
 	(XOBSHRINKVEC, XOBFINISH): New type-safe macros for obstack
 	operations.
 	(XOBFINISH): Changed to return (T *) instead of T. All callers
 	updated.
 	* libcpp/include/symtab.h (obstack_chunk_alloc)
 	(obstack_chunk_free): Define, so that obstack_init() can be used.
 	* libcpp/internal.h (struct cset_converter): Same.
 	* libcpp/files.c (_cpp_init_files): Changed _obstack_begin() to
 	obstack_init().
 	* libcpp/identifiers.c (_cpp_init_hashtable): Same.
 	* libcpp/symtab.c (ht_create): Same.
 	* libcpp/init.c (cpp_create_reader): Same.



Thanks,
Dimitris
2012-08-18  Dimitrios Apostolou  <jimis@gmx.net>

	* include/libiberty.h (XOBDELETE, XOBGROW, XOBGROWVEC, XOBSHRINK)
	(XOBSHRINKVEC, XOBFINISH): New type-safe macros for obstack
	operations.
	(XOBFINISH): Changed to return (T *) instead of T. All callers
	updated.
	* libcpp/include/symtab.h (obstack_chunk_alloc)
	(obstack_chunk_free): Define, so that obstack_init() can be used.
	* libcpp/internal.h (struct cset_converter): Same.
	* libcpp/files.c (_cpp_init_files): Changed _obstack_begin() to
	obstack_init().
	* libcpp/identifiers.c (_cpp_init_hashtable): Same.
	* libcpp/symtab.c (ht_create): Same.
	* libcpp/init.c (cpp_create_reader): Same.

Comments

Dodji Seketeli Aug. 20, 2012, 9:19 a.m. UTC | #1
Dimitrios Apostolou <jimis@gmx.net> a écrit:

[...]

> 	* include/libiberty.h (XOBDELETE, XOBGROW, XOBGROWVEC, XOBSHRINK)
> 	(XOBSHRINKVEC, XOBFINISH): New type-safe macros for obstack
> 	operations.
> 	(XOBFINISH): Changed to return (T *) instead of T. All callers
> 	updated.
> 	* libcpp/include/symtab.h (obstack_chunk_alloc)
> 	(obstack_chunk_free): Define, so that obstack_init() can be used.
> 	* libcpp/internal.h (struct cset_converter): Same.
> 	* libcpp/files.c (_cpp_init_files): Changed _obstack_begin() to
> 	obstack_init().
> 	* libcpp/identifiers.c (_cpp_init_hashtable): Same.
> 	* libcpp/symtab.c (ht_create): Same.
> 	* libcpp/init.c (cpp_create_reader): Same.
>

[...]

> +++ libcpp/include/symtab.h	2012-08-18 15:07:01 +0000

[...]

> +#ifndef obstack_chunk_alloc

Please add a comment here, as you did bellow in hunk for
libcpp/internal.h:

    > +#ifndef obstack_chunk_alloc
    > +  /* Needed for calling obstack_init().  */
    > +  #define obstack_chunk_alloc 	(void *(*) (long)) xmalloc
    > +  #define obstack_chunk_free 	(void (*) (void *)) free
    > +#endif

> +  #define obstack_chunk_alloc 	(void *(*) (long)) xmalloc
> +  #define obstack_chunk_free 	(void (*) (void *)) free
> +#endif

[...]

With these changes, the libcpp parts look OK to me if they still
boostrap post c++ conversion.  I am not a maintainer so I a deferring to
Tom and the other maintainers.

Thanks.
Tom Tromey Aug. 24, 2012, 3:41 p.m. UTC | #2
>>>>> "Dodji" == Dodji Seketeli <dodji@seketeli.org> writes:

Dodji> With these changes, the libcpp parts look OK to me if they still
Dodji> boostrap post c++ conversion.  I am not a maintainer so I a deferring to
Dodji> Tom and the other maintainers.

I agree.  Dodji, thanks for looking at this.
Dmitris, thanks for writing it -- patch ok with that change.

Tom
diff mbox

Patch

=== modified file 'gcc/c-family/c-lex.c'
--- gcc/c-family/c-lex.c	2012-06-19 19:55:33 +0000
+++ gcc/c-family/c-lex.c	2012-08-18 13:42:37 +0000
@@ -1037,7 +1037,7 @@  lex_string (const cpp_token *tok, tree *
   /* We have read one more token than we want.  */
   _cpp_backup_tokens (parse_in, 1);
   if (concats)
-    strs = XOBFINISH (&str_ob, cpp_string *);
+    strs = XOBFINISH (&str_ob, cpp_string);
 
   if (concats && !objc_string && !in_system_header)
     warning (OPT_Wtraditional,

=== modified file 'gcc/collect2.c'
--- gcc/collect2.c	2012-05-31 20:19:00 +0000
+++ gcc/collect2.c	2012-08-18 13:42:51 +0000
@@ -514,7 +514,7 @@  extract_string (const char **pp)
 
   obstack_1grow (&temporary_obstack, '\0');
   *pp = p;
-  return XOBFINISH (&temporary_obstack, char *);
+  return XOBFINISH (&temporary_obstack, char);
 }
 
 void
@@ -535,7 +535,7 @@  dump_ld_file (const char *name, FILE *to
 	  const char *word, *p;
 	  char *result;
 	  obstack_1grow (&temporary_obstack, '\0');
-	  word = XOBFINISH (&temporary_obstack, const char *);
+	  word = XOBFINISH (&temporary_obstack, const char);
 
 	  if (*word == '.')
 	    ++word, putc ('.', to);
@@ -943,7 +943,7 @@  maybe_run_lto_and_relink (char **lto_ld_
 
 	lto_o_files = XNEWVEC (char *, num_files + 1);
 	lto_o_files[num_files] = NULL;
-	start = XOBFINISH (&temporary_obstack, char *);
+	start = XOBFINISH (&temporary_obstack, char);
 	for (i = 0; i < num_files; ++i)
 	  {
 	    end = start;

=== modified file 'gcc/dbxout.c'
--- gcc/dbxout.c	2012-06-24 17:58:46 +0000
+++ gcc/dbxout.c	2012-08-18 13:48:19 +0000
@@ -864,7 +864,7 @@  dbxout_finish_complex_stabs (tree sym, s
       obstack_1grow (&stabstr_ob, '\0');
 
       len = obstack_object_size (&stabstr_ob);
-      chunk = str = XOBFINISH (&stabstr_ob, char *);
+      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
@@ -897,7 +897,7 @@  dbxout_finish_complex_stabs (tree sym, s
 	 comma than to do a two-character fputs.  */
       obstack_grow (&stabstr_ob, "\",", 2);
       len = obstack_object_size (&stabstr_ob);
-      str = XOBFINISH (&stabstr_ob, char *);
+      str = XOBFINISH (&stabstr_ob, char);
 
       fwrite (str, 1, len, asm_out_file);
       DBX_FINISH_STABS (sym, code, line, addr, label, number);

=== modified file 'gcc/gcc.c'
--- gcc/gcc.c	2012-08-15 01:56:07 +0000
+++ gcc/gcc.c	2012-08-18 13:47:06 +0000
@@ -1435,7 +1435,7 @@  init_spec (void)
       }
 
     obstack_1grow (&obstack, '\0');
-    libgcc_spec = XOBFINISH (&obstack, const char *);
+    libgcc_spec = XOBFINISH (&obstack, const char);
   }
 #endif
 #ifdef USE_AS_TRADITIONAL_FORMAT
@@ -1444,7 +1444,7 @@  init_spec (void)
     static const char tf[] = "--traditional-format ";
     obstack_grow (&obstack, tf, sizeof(tf) - 1);
     obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
-    asm_spec = XOBFINISH (&obstack, const char *);
+    asm_spec = XOBFINISH (&obstack, const char);
   }
 #endif
 
@@ -1469,7 +1469,7 @@  init_spec (void)
   }
 # endif
   obstack_grow0 (&obstack, link_spec, strlen (link_spec));
-  link_spec = XOBFINISH (&obstack, const char *);
+  link_spec = XOBFINISH (&obstack, const char);
 #endif
 
   specs = sl;
@@ -2277,7 +2277,7 @@  build_search_list (const struct path_pre
   for_each_path (paths, do_multi, 0, add_to_obstack, &info);
 
   obstack_1grow (&collect_obstack, '\0');
-  return XOBFINISH (&collect_obstack, char *);
+  return XOBFINISH (&collect_obstack, char);
 }
 
 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
@@ -2924,7 +2924,7 @@  convert_filename (const char *name, int
     {
       obstack_grow (&obstack, name, len - 2);
       obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
-      name = XOBFINISH (&obstack, const char *);
+      name = XOBFINISH (&obstack, const char);
     }
 #endif
 
@@ -2945,7 +2945,7 @@  convert_filename (const char *name, int
   obstack_grow (&obstack, name, len);
   obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
 		 strlen (TARGET_EXECUTABLE_SUFFIX));
-  name = XOBFINISH (&obstack, const char *);
+  name = XOBFINISH (&obstack, const char);
 #endif
 
   return name;
@@ -4047,7 +4047,7 @@  set_collect_gcc_options (void)
 	}
     }
   obstack_grow (&collect_obstack, "\0", 1);
-  xputenv (XOBFINISH (&collect_obstack, char *));
+  xputenv (XOBFINISH (&collect_obstack, char));
 }
 
 /* Process a spec string, accumulating and running commands.  */
@@ -4117,7 +4117,7 @@  end_going_arg (void)
       const char *string;
 
       obstack_1grow (&obstack, 0);
-      string = XOBFINISH (&obstack, const char *);
+      string = XOBFINISH (&obstack, const char);
       if (this_is_library_file)
 	string = find_file (string);
       if (this_is_linker_script)
@@ -6242,21 +6242,21 @@  main (int argc, char **argv)
       obstack_grow (&multilib_obstack, p, strlen (p));
 
     obstack_1grow (&multilib_obstack, 0);
-    multilib_select = XOBFINISH (&multilib_obstack, const char *);
+    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 = XOBFINISH (&multilib_obstack, const char *);
+    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 = XOBFINISH (&multilib_obstack, const char *);
+    multilib_exclusions = XOBFINISH (&multilib_obstack, const char);
 
     need_space = FALSE;
     for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
@@ -6270,7 +6270,7 @@  main (int argc, char **argv)
       }
 
     obstack_1grow (&multilib_obstack, 0);
-    multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
+    multilib_defaults = XOBFINISH (&multilib_obstack, const char);
   }
 
 #ifdef INIT_ENVIRONMENT
@@ -6357,7 +6357,7 @@  main (int argc, char **argv)
     {
       obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
       obstack_grow0 (&obstack, link_spec, strlen (link_spec));
-      set_spec ("link", XOBFINISH (&obstack, const char *), false);
+      set_spec ("link", XOBFINISH (&obstack, const char), false);
     }
 #endif
 
@@ -6508,7 +6508,7 @@  main (int argc, char **argv)
   obstack_init (&collect_obstack);
   obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
   obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
-  xputenv (XOBFINISH (&collect_obstack, char *));
+  xputenv (XOBFINISH (&collect_obstack, char));
 
   /* Set up to remember the pathname of the lto wrapper. */
 
@@ -6525,7 +6525,7 @@  main (int argc, char **argv)
 		    sizeof ("COLLECT_LTO_WRAPPER=") - 1);
       obstack_grow (&collect_obstack, lto_wrapper_spec,
 		    strlen (lto_wrapper_spec) + 1);
-      xputenv (XOBFINISH (&collect_obstack, char *));
+      xputenv (XOBFINISH (&collect_obstack, char));
     }
 
   /* Reject switches that no pass was interested in.  */
@@ -6665,7 +6665,7 @@  warranty; not even for MERCHANTABILITY o
       obstack_init (&obstack);
       do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
       obstack_1grow (&obstack, '\0');
-      thrmod = XOBFINISH (&obstack, const char *);
+      thrmod = XOBFINISH (&obstack, const char);
 #else
       thrmod = thread_model;
 #endif
@@ -7391,7 +7391,7 @@  set_multilib_dir (void)
 
 	  obstack_grow (&multilib_obstack, start, end - start);
 	  obstack_1grow (&multilib_obstack, 0);
-	  mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
+	  mdswitches[i].str = XOBFINISH (&multilib_obstack, const char);
 	  mdswitches[i++].len = end - start;
 
 	  if (*end == '\0')

=== modified file 'gcc/genflags.c'
--- gcc/genflags.c	2011-01-03 20:52:22 +0000
+++ gcc/genflags.c	2012-08-18 13:47:29 +0000
@@ -286,7 +286,7 @@  main (int argc, char **argv)
   /* Print out the prototypes now.  */
   dummy = (rtx) 0;
   obstack_grow (&obstack, &dummy, sizeof (rtx));
-  insns = XOBFINISH (&obstack, rtx *);
+  insns = XOBFINISH (&obstack, rtx);
 
   for (insn_ptr = insns; *insn_ptr; insn_ptr++)
     gen_proto (*insn_ptr);

=== modified file 'gcc/gengtype-state.c'
--- gcc/gengtype-state.c	2012-08-15 01:56:07 +0000
+++ gcc/gengtype-state.c	2012-08-18 13:45:57 +0000
@@ -306,7 +306,7 @@  read_a_state_token (void)
       if (c >= 0)
 	ungetc (c, state_file);
       obstack_1grow (&id_obstack, (char) 0);
-      ids = XOBFINISH (&id_obstack, char *);
+      ids = XOBFINISH (&id_obstack, char);
       sid = state_ident_by_name (ids, INSERT);
       obstack_free (&id_obstack, NULL);
       ids = NULL;
@@ -403,7 +403,7 @@  read_a_state_token (void)
       if (c != '"')
 	fatal_reading_state (NULL_STATE_TOKEN, "Unterminated string");
       obstack_1grow (&bstring_obstack, '\0');
-      cstr = XOBFINISH (&bstring_obstack, char *);
+      cstr = XOBFINISH (&bstring_obstack, char);
       cslen = strlen (cstr);
       tk = (struct state_token_st *)
 	xcalloc (sizeof (struct state_token_st) + cslen, 1);

=== modified file 'gcc/gengtype.c'
--- gcc/gengtype.c	2012-08-15 01:56:07 +0000
+++ gcc/gengtype.c	2012-08-18 13:41:45 +0000
@@ -2033,7 +2033,7 @@  matching_file_name_substitute (const cha
       obstack_1grow (&str_obstack, c);
   }
   obstack_1grow (&str_obstack, '\0');
-  rawstr = XOBFINISH (&str_obstack, char *);
+  rawstr = XOBFINISH (&str_obstack, char);
   str = xstrdup (rawstr);
   obstack_free (&str_obstack, NULL);
   DBGPRINTF ("matched replacement %s", str);

=== modified file 'gcc/genpreds.c'
--- gcc/genpreds.c	2011-04-12 12:51:10 +0000
+++ gcc/genpreds.c	2012-08-18 13:47:57 +0000
@@ -138,7 +138,7 @@  write_predicate_subfunction (struct pred
   obstack_grow (rtl_obstack, p->name, strlen (p->name));
   obstack_grow (rtl_obstack, "_1 (op, mode)",
 		sizeof "_1 (op, mode)");
-  match_test_str = XOBFINISH (rtl_obstack, const char *);
+  match_test_str = XOBFINISH (rtl_obstack, const char);
 
   /* Add the function-call expression to the complete expression to be
      evaluated.  */
@@ -703,7 +703,7 @@  mangle (const char *name)
       }
 
   obstack_1grow (rtl_obstack, '\0');
-  return XOBFINISH (rtl_obstack, const char *);
+  return XOBFINISH (rtl_obstack, const char);
 }
 
 /* Add one constraint, of any sort, to the tables.  NAME is its name;

=== modified file 'gcc/gensupport.c'
--- gcc/gensupport.c	2012-07-09 08:45:12 +0000
+++ gcc/gensupport.c	2012-08-18 13:42:59 +0000
@@ -1297,7 +1297,7 @@  gen_mnemonic_setattr (htab_t mnemonic_ht
   obstack_1grow (&string_obstack, '\0');
 
   set_attr = rtx_alloc (SET_ATTR);
-  XSTR (set_attr, 1) = XOBFINISH (&string_obstack, char *);
+  XSTR (set_attr, 1) = XOBFINISH (&string_obstack, char);
   attr_name = XNEWVAR (char, strlen (MNEMONIC_ATTR_NAME) + 1);
   strcpy (attr_name, MNEMONIC_ATTR_NAME);
   XSTR (set_attr, 0) = attr_name;
@@ -1388,7 +1388,7 @@  gen_mnemonic_attr (void)
 
   /* Replace the last ',' with the zero end character.  */
   *((char *)obstack_next_free (&string_obstack) - 1) = '\0';
-  XSTR (mnemonic_attr, 1) = XOBFINISH (&string_obstack, char *);
+  XSTR (mnemonic_attr, 1) = XOBFINISH (&string_obstack, char);
 }
 
 /* The entry point for initializing the reader.  */

=== modified file 'gcc/java/class.c'
--- gcc/java/class.c	2012-08-15 01:56:07 +0000
+++ gcc/java/class.c	2012-08-18 13:46:10 +0000
@@ -2458,7 +2458,7 @@  layout_class (tree this_class)
 	  obstack_grow (&temporary_obstack, buffer, strlen (buffer));
 	}
       obstack_1grow (&temporary_obstack, '\0');
-      report = XOBFINISH (&temporary_obstack, char *);
+      report = XOBFINISH (&temporary_obstack, char);
       cyclic_inheritance_report = ggc_strdup (report);
       obstack_free (&temporary_obstack, report);
       TYPE_SIZE (this_class) = error_mark_node;

=== modified file 'gcc/java/jvgenmain.c'
--- gcc/java/jvgenmain.c	2012-07-11 08:58:58 +0000
+++ gcc/java/jvgenmain.c	2012-08-18 13:46:02 +0000
@@ -192,5 +192,5 @@  do_mangle_classname (const char *string)
   append_gpp_mangled_name (&ptr [-count], count);
   obstack_grow (mangle_obstack, "6class$E", strlen ("6class$E"));
   obstack_1grow (mangle_obstack, '\0');
-  return XOBFINISH (mangle_obstack, char *);
+  return XOBFINISH (mangle_obstack, char);
 }

=== modified file 'gcc/lto-opts.c'
--- gcc/lto-opts.c	2011-11-08 13:41:57 +0000
+++ gcc/lto-opts.c	2012-08-18 13:47:24 +0000
@@ -124,7 +124,7 @@  lto_write_options (void)
 				       option->canonical_option[j]);
     }
   obstack_grow (&temporary_obstack, "\0", 1);
-  args = XOBFINISH (&temporary_obstack, char *);
+  args = XOBFINISH (&temporary_obstack, char);
   lto_output_data_stream (&stream, args, strlen (args) + 1);
 
   lto_write_stream (&stream);

=== modified file 'gcc/lto-wrapper.c'
--- gcc/lto-wrapper.c	2012-05-29 14:14:06 +0000
+++ gcc/lto-wrapper.c	2012-08-18 13:48:07 +0000
@@ -336,7 +336,7 @@  get_options_from_collect_gcc_options (co
 
   obstack_ptr_grow (&argv_obstack, NULL);
   argc = obstack_object_size (&argv_obstack) / sizeof (void *) - 1;
-  argv = XOBFINISH (&argv_obstack, const char **);
+  argv = XOBFINISH (&argv_obstack, const char *);
 
   decode_cmdline_options_to_array (argc, (const char **)argv,
 				   lang_mask,
@@ -732,7 +732,7 @@  run_gcc (unsigned argc, char *argv[])
     obstack_ptr_grow (&argv_obstack, argv[i]);
   obstack_ptr_grow (&argv_obstack, NULL);
 
-  new_argv = XOBFINISH (&argv_obstack, const char **);
+  new_argv = XOBFINISH (&argv_obstack, const char *);
   argv_ptr = &new_argv[new_head_argc];
   fork_execute (CONST_CAST (char **, new_argv));
 
@@ -807,7 +807,7 @@  cont:
 	     the resulting name to the LTRANS output list.  */
 	  obstack_grow (&env_obstack, input_name, strlen (input_name) - 2);
 	  obstack_grow (&env_obstack, ".ltrans.o", sizeof (".ltrans.o"));
-	  output_name = XOBFINISH (&env_obstack, char *);
+	  output_name = XOBFINISH (&env_obstack, char);
 
 	  /* Adjust the dumpbase if the linker output file was seen.  */
 	  if (linker_output)

=== modified file 'gcc/objc/objc-encoding.c'
--- gcc/objc/objc-encoding.c	2012-06-29 16:12:35 +0000
+++ gcc/objc/objc-encoding.c	2012-08-18 13:48:31 +0000
@@ -164,7 +164,7 @@  encode_method_prototype (tree method_dec
 
   finish_encoding:
   obstack_1grow (&util_obstack, '\0');
-  result = get_identifier (XOBFINISH (&util_obstack, char *));
+  result = get_identifier (XOBFINISH (&util_obstack, char));
   obstack_free (&util_obstack, util_firstobj);
   return result;
 }
@@ -179,7 +179,7 @@  objc_build_encode_expr (tree type)
   encode_type (type, obstack_object_size (&util_obstack),
 	       OBJC_ENCODE_INLINE_DEFS);
   obstack_1grow (&util_obstack, 0);    /* null terminate string */
-  string = XOBFINISH (&util_obstack, const char *);
+  string = XOBFINISH (&util_obstack, const char);
 
   /* Synthesize a string that represents the encoded struct/union.  */
   result = my_build_string (strlen (string) + 1, string);
@@ -847,7 +847,7 @@  encode_field_decl (tree field_decl)
   obstack_1grow (&util_obstack, 0);
 
   /* Get identifier for the string.  */
-  result = get_identifier (XOBFINISH (&util_obstack, char *));
+  result = get_identifier (XOBFINISH (&util_obstack, char));
   obstack_free (&util_obstack, util_firstobj);
 
   return result;
@@ -945,7 +945,7 @@  objc_v2_encode_prop_attr (tree property)
 
   /* NULL-terminate string.  */
   obstack_1grow (&util_obstack, 0);
-  string = XOBFINISH (&util_obstack, char *);
+  string = XOBFINISH (&util_obstack, char);
   obstack_free (&util_obstack, util_firstobj);
   return get_identifier (string);
 }

=== modified file 'gcc/pretty-print.c'
--- gcc/pretty-print.c	2012-08-07 22:14:29 +0000
+++ gcc/pretty-print.c	2012-08-18 13:47:40 +0000
@@ -273,7 +273,7 @@  pp_base_format (pretty_printer *pp, text
 	  /* Handled in phase 2.  Terminate the plain chunk here.  */
 	  obstack_1grow (&buffer->chunk_obstack, '\0');
 	  gcc_assert (chunk < PP_NL_ARGMAX * 2);
-	  args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+	  args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char);
 	  break;
 	}
 
@@ -352,12 +352,12 @@  pp_base_format (pretty_printer *pp, text
 
       obstack_1grow (&buffer->chunk_obstack, '\0');
       gcc_assert (chunk < PP_NL_ARGMAX * 2);
-      args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+      args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char);
     }
 
   obstack_1grow (&buffer->chunk_obstack, '\0');
   gcc_assert (chunk < PP_NL_ARGMAX * 2);
-  args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+  args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char);
   args[chunk] = 0;
 
   /* Set output to the argument obstack, and switch line-wrapping and
@@ -515,7 +515,7 @@  pp_base_format (pretty_printer *pp, text
 	pp_string (pp, close_quote);
 
       obstack_1grow (&buffer->chunk_obstack, '\0');
-      *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *);
+      *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char);
     }
 
 #ifdef ENABLE_CHECKING

=== modified file 'gcc/read-md.c'
--- gcc/read-md.c	2012-05-04 20:04:47 +0000
+++ gcc/read-md.c	2012-08-18 13:47:51 +0000
@@ -206,7 +206,7 @@  join_c_conditions (const char *cond1, co
   obstack_ptr_grow (&joined_conditions_obstack, result);
   obstack_ptr_grow (&joined_conditions_obstack, cond1);
   obstack_ptr_grow (&joined_conditions_obstack, cond2);
-  entry = XOBFINISH (&joined_conditions_obstack, const void **);
+  entry = XOBFINISH (&joined_conditions_obstack, const void *);
   *htab_find_slot (joined_conditions, entry, INSERT) = entry;
   return result;
 }
@@ -512,7 +512,7 @@  read_quoted_string (void)
     }
 
   obstack_1grow (&string_obstack, 0);
-  return XOBFINISH (&string_obstack, char *);
+  return XOBFINISH (&string_obstack, char);
 }
 
 /* Read a braced string (a la Tcl) onto the string obstack.  Caller
@@ -549,7 +549,7 @@  read_braced_string (void)
     }
 
   obstack_1grow (&string_obstack, 0);
-  return XOBFINISH (&string_obstack, char *);
+  return XOBFINISH (&string_obstack, char);
 }
 
 /* Read some kind of string constant.  This is the high-level routine

=== modified file 'gcc/read-rtl.c'
--- gcc/read-rtl.c	2012-06-18 10:43:03 +0000
+++ gcc/read-rtl.c	2012-08-18 13:41:34 +0000
@@ -263,7 +263,7 @@  apply_iterator_to_string (const char *st
   if (base != copy)
     {
       obstack_grow (&string_obstack, base, strlen (base) + 1);
-      copy = XOBFINISH (&string_obstack, char *);
+      copy = XOBFINISH (&string_obstack, char);
       copy_md_ptr_loc (copy, string);
       return copy;
     }
@@ -723,7 +723,7 @@  record_potential_iterator_use (struct it
       /* Copy the attribute string into permanent storage, without the
 	 angle brackets around it.  */
       obstack_grow0 (&string_obstack, name + 1, len - 2);
-      record_attribute_use (group, ptr, XOBFINISH (&string_obstack, char *));
+      record_attribute_use (group, ptr, XOBFINISH (&string_obstack, char));
     }
   else
     {
@@ -1028,7 +1028,7 @@  read_rtx_code (const char *code_name)
 	      obstack_grow (&string_obstack, fn, strlen (fn));
 	      sprintf (line_name, ":%d", read_md_lineno);
 	      obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
-	      stringbuf = XOBFINISH (&string_obstack, char *);
+	      stringbuf = XOBFINISH (&string_obstack, char);
 	    }
 
 	  if (star_if_braced)

=== modified file 'gcc/tlink.c'
--- gcc/tlink.c	2012-05-31 20:19:00 +0000
+++ gcc/tlink.c	2012-08-18 13:47:18 +0000
@@ -319,7 +319,7 @@  obstack_fgets (FILE *stream, struct obst
   if (obstack_object_size (ob) == 0)
     return NULL;
   obstack_1grow (ob, '\0');
-  return XOBFINISH (ob, char *);
+  return XOBFINISH (ob, char);
 }
 
 static char *
@@ -542,7 +542,7 @@  recompile_files (void)
     done:
       obstack_ptr_grow (&temporary_obstack, f->main);
       obstack_ptr_grow (&temporary_obstack, NULL);
-      argv = XOBFINISH (&temporary_obstack, char **);
+      argv = XOBFINISH (&temporary_obstack, char *);
 
       if (tlink_verbose)
 	fprintf (stderr, _("collect: recompiling %s\n"), f->main);

=== modified file 'gcc/tree-sra.c'
--- gcc/tree-sra.c	2012-08-17 07:51:31 +0000
+++ gcc/tree-sra.c	2012-08-18 13:48:12 +0000
@@ -1416,7 +1416,7 @@  make_fancy_name (tree expr)
 {
   make_fancy_name_1 (expr);
   obstack_1grow (&name_obstack, '\0');
-  return XOBFINISH (&name_obstack, char *);
+  return XOBFINISH (&name_obstack, char);
 }
 
 /* Construct a MEM_REF that would reference a part of aggregate BASE of type

=== modified file 'include/libiberty.h'
--- include/libiberty.h	2011-09-28 19:04:30 +0000
+++ include/libiberty.h	2012-08-18 13:33:45 +0000
@@ -361,12 +361,27 @@  extern unsigned int xcrc32 (const unsign
 #define XDUPVAR(T, P, S1, S2)	((T *) xmemdup ((P), (S1), (S2)))
 #define XRESIZEVAR(T, P, S)	((T *) xrealloc ((P), (S)))
 
-/* Type-safe obstack allocator.  */
+/* Type-safe obstack allocator. You must first initialize the obstack.
+   T: Type,  O: Obstack,  N: Number of elements,  S: Size in bytes,
+   P: Pointer to element.  */
 
 #define XOBNEW(O, T)		((T *) obstack_alloc ((O), sizeof (T)))
 #define XOBNEWVEC(O, T, N)	((T *) obstack_alloc ((O), sizeof (T) * (N)))
 #define XOBNEWVAR(O, T, S)	((T *) obstack_alloc ((O), (S)))
-#define XOBFINISH(O, T)         ((T) obstack_finish ((O)))
+#define XOBDELETE(O, P)		(obstack_free ((O), (P)))
+
+/* The following is for growing/shrinking objects in an obstack (D: Data to
+   grow the object with). This is useful when you don't know the object size
+   in advance, so you can't use obstack_alloc() You must finalise it with
+   obstack_finish() before actually using it.
+
+   See http://gcc.gnu.org/onlinedocs/libiberty/Growing-Objects.html */
+
+#define XOBGROW(O, T, D)	obstack_grow ((O), (D), sizeof (T))
+#define XOBGROWVEC(O, T, D, N)	obstack_grow ((O), (D), sizeof (T) * (N))
+#define XOBSHRINK(O, T)		obstack_blank ((O), -1 * sizeof (T))
+#define XOBSHRINKVEC(O, T, N)	obstack_blank ((O), -1 * sizeof (T) * (N))
+#define XOBFINISH(O, T)		((T *) obstack_finish ((O)))
 
 /* hex character manipulation routines */
 

=== modified file 'libcpp/files.c'
--- libcpp/files.c	2012-04-30 16:57:22 +0000
+++ libcpp/files.c	2012-08-18 14:52:41 +0000
@@ -1210,9 +1210,7 @@  _cpp_init_files (cpp_reader *pfile)
   pfile->nonexistent_file_hash = htab_create_alloc (127, htab_hash_string,
 						    nonexistent_file_hash_eq,
 						    NULL, xcalloc, free);
-  _obstack_begin (&pfile->nonexistent_file_ob, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_init (&pfile->nonexistent_file_ob);
 }
 
 /* Finalize everything in this source file.  */

=== modified file 'libcpp/identifiers.c'
--- libcpp/identifiers.c	2012-08-15 01:56:07 +0000
+++ libcpp/identifiers.c	2012-08-18 14:22:22 +0000
@@ -55,9 +55,7 @@  _cpp_init_hashtable (cpp_reader *pfile,
       table = ht_create (13);	/* 8K (=2^13) entries.  */
       table->alloc_node = alloc_node;
 
-      _obstack_begin (&pfile->hash_ob, 0, 0,
-		      (void *(*) (long)) xmalloc,
-		      (void (*) (void *)) free);
+      obstack_init (&pfile->hash_ob);
     }
 
   table->pfile = pfile;

=== modified file 'libcpp/include/symtab.h'
--- libcpp/include/symtab.h	2012-08-15 01:56:07 +0000
+++ libcpp/include/symtab.h	2012-08-18 15:07:01 +0000
@@ -21,6 +21,11 @@  along with this program; see the file CO
 
 #include "obstack.h"
 
+#ifndef obstack_chunk_alloc
+  #define obstack_chunk_alloc 	(void *(*) (long)) xmalloc
+  #define obstack_chunk_free 	(void (*) (void *)) free
+#endif
+
 #ifndef GTY
 #define GTY(x) /* nothing */
 #endif

=== modified file 'libcpp/init.c'
--- libcpp/init.c	2012-08-15 01:56:07 +0000
+++ libcpp/init.c	2012-08-18 14:27:50 +0000
@@ -242,9 +242,7 @@  cpp_create_reader (enum c_lang lang, cpp
   _cpp_expand_op_stack (pfile);
 
   /* Initialize the buffer obstack.  */
-  _obstack_begin (&pfile->buffer_ob, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_init (&pfile->buffer_ob);
 
   _cpp_init_files (pfile);
 

=== modified file 'libcpp/internal.h'
--- libcpp/internal.h	2012-08-15 01:56:07 +0000
+++ libcpp/internal.h	2012-08-18 15:05:59 +0000
@@ -51,6 +51,12 @@  struct cset_converter
   int width;
 };
 
+#ifndef obstack_chunk_alloc
+  /* Needed for calling obstack_init().  */
+  #define obstack_chunk_alloc 	(void *(*) (long)) xmalloc
+  #define obstack_chunk_free 	(void (*) (void *)) free
+#endif
+
 #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
 
 /* Test if a sign is valid within a preprocessing number.  */

=== modified file 'libcpp/symtab.c'
--- libcpp/symtab.c	2012-08-15 01:56:07 +0000
+++ libcpp/symtab.c	2012-08-18 15:06:27 +0000
@@ -62,9 +62,7 @@  ht_create (unsigned int order)
   table = XCNEW (cpp_hash_table);
 
   /* Strings need no alignment.  */
-  _obstack_begin (&table->stack, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_init (&table->stack);
 
   obstack_alignment_mask (&table->stack) = 0;