This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH to libiberty: Move to the intersection of C90 an C++


Hi,

  This patch brings libiberty at the intersection of C90 and C++. It
survives testing on i686-pc-linux-gnu, sparc-sun-solaris2.7 and
sparc-sun-solaris2.8.

htab_size() and htab_elements() are now static inline, instead of
using the "pseudo-semantics" of extern inline (problem discovered when
building the GNU C compiler with g++). 

ATTRIBUTE_UNUSED_LABEL needs adjustment when __cplusplus because g++
does not understand attributes on lables. 

OK to apply when mainline is back?

-- Gaby

include/
2005-05-23  Gabriel Dos Reis  <gdr@integrable-solutions.net>

	* libiberty.h (ACONCAT): Properly cast value of alloca().

	* hashtab.h (htab_size): Make static inline.
	(htab_elements): Likewise.

	* ansidecl.h (ATTRIBUTE_UNUSED_LABEL): Don't define if
	__cplusplus. 

libiberty/
2005-05-23  Gabriel Dos Reis  <gdr@integrable-solutions.net>

	* configure.ac: Check declarations for calloc(), getenv(),
	malloc(), realloc() and sbrk(). 
	* config.in: Regenerate.
	* configure: Likewise.

	* alloca.c (C_alloca): Change "new" to "new_storage".  Use XNEWVEC
	instead of xmalloc.
	* choose-temp.c (choose_temp_base): Use XNEWVEC instea od xmalloc.
	* concat.c (liiberty_concat_ptr): Surround definition with an
	extern "C" block, if __cplusplus.
	(concat): Use XNEWVEC instead of xmalloc.
	(reconcat): Likewise.
	* cp-demangle.c (struct d_print_template): Rename member
	"template" to "template_decl".  Adjust use throughout the file. 
	(d_print_resize): Properly cast return value of realloc().
	(cplus_demangle_print): Same for malloc().
	(d_demangle): Likewise.
	* cp-demint.c (cplus_demangle_fill_builtin_type): Rename parameter
	"typename" to "type_name".
	* cplus-dem.c (grow_vect): Use XRESIZEVEC instead of xrealloc().
	(work_stuff_copy_to_from): Use XNEWVEC insteand of xmalloc().
	(demangle_template_value_parm): Likewise.
	(demangle_template): Likewise.
	(recursively_demangle): Likewise.
	(do_hpacc_template_literal): Likewise.
	(do_arg): Likewise.
	(remember_type): Likewise.
	(remember_Ktype): Likewise.
	(register_Btype): Likewise.
	(string_need): Use XRESIZEVEC instead of xrealloc().
	* dyn-string.c (dyn_string_init): Use XNEWVEC.
	(dyn_string_new): Use XNEW.
	(dyn_string_resize): Use XRESIZEVEC.
	* fnmatch.c (fnmatch): Rename local variable "not" to "negate".
	* getopt.c (getenv): Declare only if !__cplusplus and !getenv.
	Otherwise include <stdlib.h>.
	(exchange): Cast return value of malloc().
	* getpwd.c (getpwd): Use XNEWVEC.
	* hashtab.c (htab_size, htab_elements): Move definition to
	include/hashtab.h as static inline.
	(htab_create_alloc_ex): Use C90 prototype-style.
	* lrealpath.c (lrealpath): Appropriately cast return value of
	malloc(). 
	* make-relative-prefix.c (save_string): Likewise.
	* make-temp-file.c (try_dir): Rename from "try".  Adjust use in
	the file.
	(choose_tmpdir): Use XNEWVEC.
	* mkstemps.c (mkstemps): Rename parameter "template" to "pattern".
	* pex-common.c (pex_init_common): Use XNEW.
	(pex_add_remove): Use XRESIZEVEC.
	(pex_run): Likewise.
	(pex_get_status_and_time): Likewise.
	* pex-djgpp.c (pex_djgpp_exec_child): Likewise.
	* pex-msdos.c (pex_init): Use XNEW.
	(pex_msdos_exec_child): Likewise.
	(pex_msdos_exec_child): Use XRESIZEVEC.
	* pex-unix.c (pex_wait): Use XNEW.
	* pex-win32.c (fix_argv): Use XNEWVEC.
	* pexecute.c (pwait): Likewise.
	* setenv.c (setenv): Properly cast return value of malloc().
	* sigsetmask.c (sigsetmask): Rename local variables "old" and
	"new" to "old_sig" and "new_sig".
	* sort.c (main): Use XNEWVEC.
	* spaces.c (spaces): Cast return value of malloc().
	* strndup.c (strndup): Likewise.
	* ternary.c (ternary_insert): Use XNEW.
	* xmalloc.c (malloc, realloc, calloc, sbrk): Surround declaration
	with an extern "C" block if __cplusplus.
	* xstrdup.c (xstrdup): Cast return value of memcpy().
	* xstrerror.c (strerror): Enclose declaration in an extern "C"
	block if __cplusplus.
	* xstrndup.c (xstrndup): Use XNEW. Cast return value of memcpy().

Index: include/ansidecl.h
===================================================================
RCS file: /cvs/gcc/gcc/include/ansidecl.h,v
retrieving revision 1.21
diff -u -r1.21 ansidecl.h
--- include/ansidecl.h	10 May 2005 15:22:21 -0000	1.21
+++ include/ansidecl.h	24 May 2005 01:46:57 -0000
@@ -258,11 +258,11 @@
 
 /* Attributes on labels were valid as of gcc 2.93. */
 #ifndef ATTRIBUTE_UNUSED_LABEL
-# if (GCC_VERSION >= 2093)
+# if (!defined (__cplusplus) && GCC_VERSION >= 2093)
 #  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
 # else
 #  define ATTRIBUTE_UNUSED_LABEL
-# endif /* GNUC >= 2.93 */
+# endif /* !__cplusplus && GNUC >= 2.93 */
 #endif /* ATTRIBUTE_UNUSED_LABEL */
 
 #ifndef ATTRIBUTE_UNUSED
Index: include/hashtab.h
===================================================================
RCS file: /cvs/gcc/gcc/include/hashtab.h,v
retrieving revision 1.25
diff -u -r1.25 hashtab.h
--- include/hashtab.h	10 May 2005 15:22:21 -0000	1.25
+++ include/hashtab.h	24 May 2005 01:46:57 -0000
@@ -172,10 +172,25 @@
 extern void	htab_traverse (htab_t, htab_trav, void *);
 extern void	htab_traverse_noresize (htab_t, htab_trav, void *);
 
-extern size_t	htab_size (htab_t);
-extern size_t	htab_elements (htab_t);
 extern double	htab_collisions	(htab_t);
 
+   
+/* Return the current size of given hash table. */
+
+static inline size_t
+htab_size (htab_t htab)
+{
+  return htab->size;
+}
+
+/* Return the current number of elements in given hash table. */
+
+static inline size_t
+htab_elements (htab_t htab)
+{
+  return htab->n_elements - htab->n_deleted;
+}
+
 /* A hash function for pointers.  */
 extern htab_hash htab_hash_pointer;
 
Index: include/libiberty.h
===================================================================
RCS file: /cvs/gcc/gcc/include/libiberty.h,v
retrieving revision 1.55
diff -u -r1.55 libiberty.h
--- include/libiberty.h	12 May 2005 19:29:53 -0000	1.55
+++ include/libiberty.h	24 May 2005 01:46:57 -0000
@@ -156,7 +156,7 @@
    strings.  Allocates memory using alloca.  The arguments are
    evaluated twice!  */
 #define ACONCAT(ACONCAT_PARAMS) \
-  (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \
+  (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \
    concat_copy2 ACONCAT_PARAMS)
 
 /* Check whether two file descriptors refer to the same file.  */
Index: libiberty/alloca.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/alloca.c,v
retrieving revision 1.9
diff -u -r1.9 alloca.c
--- libiberty/alloca.c	26 Mar 2005 19:24:31 -0000	1.9
+++ libiberty/alloca.c	24 May 2005 01:46:58 -0000
@@ -57,9 +57,15 @@
 
 /* These variables are used by the ASTRDUP implementation that relies
    on C_alloca.  */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
 const char *libiberty_optr;
 char *libiberty_nptr;
 unsigned long libiberty_len;
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
 
 /* If your stack is a linked list of frames, you have to
    provide an "address metric" ADDRESS_FUNCTION macro.  */
@@ -191,20 +197,20 @@
   /* Allocate combined header + user data storage.  */
 
   {
-    register PTR new = xmalloc (sizeof (header) + size);
+    register void *new_storage = XNEWVEC (char, sizeof (header) + size);
     /* Address of header.  */
 
-    if (new == 0)
+    if (new_storage == 0)
       abort();
 
-    ((header *) new)->h.next = last_alloca_header;
-    ((header *) new)->h.deep = depth;
+    ((header *) new_storage)->h.next = last_alloca_header;
+    ((header *) new_storage)->h.deep = depth;
 
-    last_alloca_header = (header *) new;
+    last_alloca_header = (header *) new_storage;
 
     /* User storage begins just after header.  */
 
-    return (PTR) ((char *) new + sizeof (header));
+    return (PTR) ((char *) new_storage + sizeof (header));
   }
 }
 
Index: libiberty/choose-temp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/choose-temp.c,v
retrieving revision 1.20
diff -u -r1.20 choose-temp.c
--- libiberty/choose-temp.c	10 May 2005 15:33:14 -0000	1.20
+++ libiberty/choose-temp.c	24 May 2005 01:46:58 -0000
@@ -61,7 +61,7 @@
   int len;
 
   len = strlen (base);
-  temp_filename = xmalloc (len + TEMP_FILE_LEN + 1);
+  temp_filename = XNEWVEC (char, len + TEMP_FILE_LEN + 1);
   strcpy (temp_filename, base);
   strcpy (temp_filename + len, TEMP_FILE);
 
Index: libiberty/concat.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/concat.c,v
retrieving revision 1.14
diff -u -r1.14 concat.c
--- libiberty/concat.c	10 May 2005 15:33:14 -0000	1.14
+++ libiberty/concat.c	24 May 2005 01:46:58 -0000
@@ -127,7 +127,13 @@
   return save_dst;
 }
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
 char *libiberty_concat_ptr;
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
 
 /* @undocumented concat_copy2 */
 
@@ -150,7 +156,7 @@
   /* First compute the size of the result and get sufficient memory.  */
   VA_OPEN (args, first);
   VA_FIXEDARG (args, const char *, first);
-  newstr = (char *) xmalloc (vconcat_length (first, args) + 1);
+  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
   VA_CLOSE (args);
 
   /* Now copy the individual pieces to the result string. */
@@ -188,7 +194,7 @@
   VA_OPEN (args, first);
   VA_FIXEDARG (args, char *, optr);
   VA_FIXEDARG (args, const char *, first);
-  newstr = (char *) xmalloc (vconcat_length (first, args) + 1);
+  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
   VA_CLOSE (args);
 
   /* Now copy the individual pieces to the result string. */
Index: libiberty/config.in
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/config.in,v
retrieving revision 1.41
diff -u -r1.41 config.in
--- libiberty/config.in	7 May 2005 01:08:23 -0000	1.41
+++ libiberty/config.in	24 May 2005 01:46:58 -0000
@@ -45,9 +45,29 @@
    don't. */
 #undef HAVE_DECL_BASENAME
 
+/* Define to 1 if you have the declaration of `calloc', and to 0 if you don't.
+   */
+#undef HAVE_DECL_CALLOC
+
 /* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */
 #undef HAVE_DECL_FFS
 
+/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
+   */
+#undef HAVE_DECL_GETENV
+
+/* Define to 1 if you have the declaration of `malloc', and to 0 if you don't.
+   */
+#undef HAVE_DECL_MALLOC
+
+/* Define to 1 if you have the declaration of `realloc', and to 0 if you
+   don't. */
+#undef HAVE_DECL_REALLOC
+
+/* Define to 1 if you have the declaration of `sbrk', and to 0 if you don't.
+   */
+#undef HAVE_DECL_SBRK
+
 /* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_VASPRINTF
Index: libiberty/configure
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure,v
retrieving revision 1.96
diff -u -r1.96 configure
--- libiberty/configure	7 May 2005 01:18:14 -0000	1.96
+++ libiberty/configure	24 May 2005 01:46:59 -0000
@@ -7217,6 +7217,358 @@
 fi
 
 
+  echo "$as_me:$LINENO: checking whether calloc is declared" >&5
+echo $ECHO_N "checking whether calloc is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_calloc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef calloc
+  char *p = (char *) calloc;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_calloc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_calloc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_calloc" >&5
+echo "${ECHO_T}$ac_cv_have_decl_calloc" >&6
+if test $ac_cv_have_decl_calloc = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_CALLOC 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_CALLOC 0
+_ACEOF
+
+
+fi
+echo "$as_me:$LINENO: checking whether getenv is declared" >&5
+echo $ECHO_N "checking whether getenv is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_getenv+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef getenv
+  char *p = (char *) getenv;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_getenv=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_getenv=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_getenv" >&5
+echo "${ECHO_T}$ac_cv_have_decl_getenv" >&6
+if test $ac_cv_have_decl_getenv = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_GETENV 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_GETENV 0
+_ACEOF
+
+
+fi
+echo "$as_me:$LINENO: checking whether malloc is declared" >&5
+echo $ECHO_N "checking whether malloc is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_malloc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef malloc
+  char *p = (char *) malloc;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_malloc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_malloc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_malloc" >&5
+echo "${ECHO_T}$ac_cv_have_decl_malloc" >&6
+if test $ac_cv_have_decl_malloc = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_MALLOC 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_MALLOC 0
+_ACEOF
+
+
+fi
+echo "$as_me:$LINENO: checking whether realloc is declared" >&5
+echo $ECHO_N "checking whether realloc is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_realloc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef realloc
+  char *p = (char *) realloc;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_realloc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_realloc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_realloc" >&5
+echo "${ECHO_T}$ac_cv_have_decl_realloc" >&6
+if test $ac_cv_have_decl_realloc = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_REALLOC 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_REALLOC 0
+_ACEOF
+
+
+fi
+echo "$as_me:$LINENO: checking whether sbrk is declared" >&5
+echo $ECHO_N "checking whether sbrk is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_sbrk+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef sbrk
+  char *p = (char *) sbrk;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_sbrk=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_sbrk=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_sbrk" >&5
+echo "${ECHO_T}$ac_cv_have_decl_sbrk" >&6
+if test $ac_cv_have_decl_sbrk = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_SBRK 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_SBRK 0
+_ACEOF
+
+
+fi
+
+
   echo "$as_me:$LINENO: checking whether canonicalize_file_name must be declared" >&5
 echo $ECHO_N "checking whether canonicalize_file_name must be declared... $ECHO_C" >&6
 if test "${libiberty_cv_decl_needed_canonicalize_file_name+set}" = set; then
Index: libiberty/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure.ac,v
retrieving revision 1.24
diff -u -r1.24 configure.ac
--- libiberty/configure.ac	7 May 2005 01:18:14 -0000	1.24
+++ libiberty/configure.ac	24 May 2005 01:46:59 -0000
@@ -519,6 +519,7 @@
 
   AC_CHECK_FUNCS($checkfuncs)
   AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf])
+  AC_CHECK_DECLS([calloc, getenv, malloc, realloc, sbrk])
   libiberty_NEED_DECLARATION(canonicalize_file_name)
 fi
 
Index: libiberty/cp-demangle.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/cp-demangle.c,v
retrieving revision 1.80
diff -u -r1.80 cp-demangle.c
--- libiberty/cp-demangle.c	10 May 2005 15:33:14 -0000	1.80
+++ libiberty/cp-demangle.c	24 May 2005 01:47:00 -0000
@@ -210,7 +210,7 @@
   /* Next template on the list.  */
   struct d_print_template *next;
   /* This template.  */
-  const struct demangle_component *template;
+  const struct demangle_component *template_decl;
 };
 
 /* A list of type modifiers.  This is used while printing.  */
@@ -2551,7 +2551,7 @@
       char *newbuf;
 
       newalc = dpi->alc * 2;
-      newbuf = realloc (dpi->buf, newalc);
+      newbuf = (char *) realloc (dpi->buf, newalc);
       if (newbuf == NULL)
 	{
 	  free (dpi->buf);
@@ -2629,7 +2629,7 @@
   dpi.options = options;
 
   dpi.alc = estimate + 1;
-  dpi.buf = malloc (dpi.alc);
+  dpi.buf = (char *) malloc (dpi.alc);
   if (dpi.buf == NULL)
     {
       *palc = 1;
@@ -2730,7 +2730,7 @@
 	  {
 	    dpt.next = dpi->templates;
 	    dpi->templates = &dpt;
-	    dpt.template = typed_name;
+	    dpt.template_decl = typed_name;
 	  }
 
 	/* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
@@ -2826,7 +2826,7 @@
 	    return;
 	  }
 	i = dc->u.s_number.number;
-	for (a = d_right (dpi->templates->template);
+	for (a = d_right (dpi->templates->template_decl);
 	     a != NULL;
 	     a = d_right (a))
 	  {
@@ -3683,7 +3683,7 @@
 
       dpt.next = dpi->templates;
       dpi->templates = &dpt;
-      dpt.template = d_left (dc);
+      dpt.template_decl = d_left (dc);
 
       d_print_comp (dpi, d_left (d_left (dc)));
 
@@ -3764,7 +3764,7 @@
     {
       char *r;
 
-      r = malloc (40 + len - 11);
+      r = (char *) malloc (40 + len - 11);
       if (r == NULL)
 	*palc = 1;
       else
Index: libiberty/cp-demint.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/cp-demint.c,v
retrieving revision 1.4
diff -u -r1.4 cp-demint.c
--- libiberty/cp-demint.c	10 May 2005 15:33:16 -0000	1.4
+++ libiberty/cp-demint.c	24 May 2005 01:47:00 -0000
@@ -130,18 +130,18 @@
 
 int
 cplus_demangle_fill_builtin_type (struct demangle_component *p,
-                                  const char *typename)
+                                  const char *type_name)
 {
   int len;
   unsigned int i;
 
-  if (p == NULL || typename == NULL)
+  if (p == NULL || type_name == NULL)
     return 0;
-  len = strlen (typename);
+  len = strlen (type_name);
   for (i = 0; i < D_BUILTIN_TYPE_COUNT; ++i)
     {
       if (len == cplus_demangle_builtin_types[i].len
-	  && strcmp (typename, cplus_demangle_builtin_types[i].name) == 0)
+	  && strcmp (type_name, cplus_demangle_builtin_types[i].name) == 0)
 	{
 	  p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
 	  p->u.s_builtin.type = &cplus_demangle_builtin_types[i];
Index: libiberty/cplus-dem.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/cplus-dem.c,v
retrieving revision 1.98
diff -u -r1.98 cplus-dem.c
--- libiberty/cplus-dem.c	10 May 2005 15:33:16 -0000	1.98
+++ libiberty/cplus-dem.c	24 May 2005 01:47:00 -0000
@@ -892,7 +892,7 @@
       *size *= 2;
       if (*size < min_size)
 	*size = min_size;
-      *old_vect = (void *) xrealloc (*old_vect, *size * element_size);
+      *old_vect = XRESIZEVAR (char, *old_vect, *size * element_size);
     }
 }
 
@@ -1102,56 +1102,52 @@
 
   /* Deep-copy dynamic storage.  */
   if (from->typevec_size)
-    to->typevec
-      = (char **) xmalloc (from->typevec_size * sizeof (to->typevec[0]));
+    to->typevec = XNEWVEC (char *, from->typevec_size);
 
   for (i = 0; i < from->ntypes; i++)
     {
       int len = strlen (from->typevec[i]) + 1;
 
-      to->typevec[i] = xmalloc (len);
+      to->typevec[i] = XNEWVEC (char, len);
       memcpy (to->typevec[i], from->typevec[i], len);
     }
 
   if (from->ksize)
-    to->ktypevec
-      = (char **) xmalloc (from->ksize * sizeof (to->ktypevec[0]));
+    to->ktypevec = XNEWVEC (char *, from->ksize);
 
   for (i = 0; i < from->numk; i++)
     {
       int len = strlen (from->ktypevec[i]) + 1;
 
-      to->ktypevec[i] = xmalloc (len);
+      to->ktypevec[i] = XNEWVEC (char, len);
       memcpy (to->ktypevec[i], from->ktypevec[i], len);
     }
 
   if (from->bsize)
-    to->btypevec
-      = (char **) xmalloc (from->bsize * sizeof (to->btypevec[0]));
+    to->btypevec = XNEWVEC (char *, from->bsize);
 
   for (i = 0; i < from->numb; i++)
     {
       int len = strlen (from->btypevec[i]) + 1;
 
-      to->btypevec[i] = xmalloc (len);
+      to->btypevec[i] = XNEWVEC (char , len);
       memcpy (to->btypevec[i], from->btypevec[i], len);
     }
 
   if (from->ntmpl_args)
-    to->tmpl_argvec
-      = (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
+    to->tmpl_argvec = XNEWVEC (char *, from->ntmpl_args);
 
   for (i = 0; i < from->ntmpl_args; i++)
     {
       int len = strlen (from->tmpl_argvec[i]) + 1;
 
-      to->tmpl_argvec[i] = xmalloc (len);
+      to->tmpl_argvec[i] = XNEWVEC (char, len);
       memcpy (to->tmpl_argvec[i], from->tmpl_argvec[i], len);
     }
 
   if (from->previous_argument)
     {
-      to->previous_argument = (string*) xmalloc (sizeof (string));
+      to->previous_argument = XNEW (string);
       string_init (to->previous_argument);
       string_appends (to->previous_argument, from->previous_argument);
     }
@@ -1895,7 +1891,7 @@
 	    string_appendn (s, "0", 1);
 	  else
 	    {
-	      char *p = xmalloc (symbol_len + 1), *q;
+	      char *p = XNEWVEC (char, symbol_len + 1), *q;
 	      strncpy (p, *mangled, symbol_len);
 	      p [symbol_len] = '\0';
 	      /* We use cplus_demangle here, rather than
@@ -2001,7 +1997,7 @@
   if (!is_type)
     {
       /* Create an array for saving the template argument values. */
-      work->tmpl_argvec = (char**) xmalloc (r * sizeof (char *));
+      work->tmpl_argvec = XNEWVEC (char *, r);
       work->ntmpl_args = r;
       for (i = 0; i < r; i++)
 	work->tmpl_argvec[i] = 0;
@@ -2026,7 +2022,7 @@
 		{
 		  /* Save the template argument. */
 		  int len = temp.p - temp.b;
-		  work->tmpl_argvec[i] = xmalloc (len + 1);
+		  work->tmpl_argvec[i] = XNEWVEC (char, len + 1);
 		  memcpy (work->tmpl_argvec[i], temp.b, len);
 		  work->tmpl_argvec[i][len] = '\0';
 		}
@@ -2054,7 +2050,7 @@
 		{
 		  /* Save the template argument. */
 		  int len = r2;
-		  work->tmpl_argvec[i] = xmalloc (len + 1);
+		  work->tmpl_argvec[i] = XNEWVEC (char, len + 1);
 		  memcpy (work->tmpl_argvec[i], *mangled, len);
 		  work->tmpl_argvec[i][len] = '\0';
 		}
@@ -2100,7 +2096,7 @@
 	  if (!is_type)
 	    {
 	      int len = s->p - s->b;
-	      work->tmpl_argvec[i] = xmalloc (len + 1);
+	      work->tmpl_argvec[i] = XNEWVEC (char, len + 1);
 	      memcpy (work->tmpl_argvec[i], s->b, len);
 	      work->tmpl_argvec[i][len] = '\0';
 
@@ -2998,7 +2994,7 @@
   char * recurse = (char *)NULL;
   char * recurse_dem = (char *)NULL;
 
-  recurse = (char *) xmalloc (namelength + 1);
+  recurse = XNEWVEC (char, namelength + 1);
   memcpy (recurse, *mangled, namelength);
   recurse[namelength] = '\000';
 
@@ -3969,7 +3965,7 @@
   string_append (result, "&");
 
   /* Now recursively demangle the literal name */
-  recurse = (char *) xmalloc (literal_len + 1);
+  recurse = XNEWVEC (char, literal_len + 1);
   memcpy (recurse, *mangled, literal_len);
   recurse[literal_len] = '\000';
 
@@ -4071,7 +4067,7 @@
   if (work->previous_argument)
     string_delete (work->previous_argument);
   else
-    work->previous_argument = (string*) xmalloc (sizeof (string));
+    work->previous_argument = XNEW (string);
 
   if (!do_type (work, mangled, work->previous_argument))
     return 0;
@@ -4095,18 +4091,16 @@
       if (work -> typevec_size == 0)
 	{
 	  work -> typevec_size = 3;
-	  work -> typevec
-	    = (char **) xmalloc (sizeof (char *) * work -> typevec_size);
+	  work -> typevec = XNEWVEC (char *, work->typevec_size);
 	}
       else
 	{
 	  work -> typevec_size *= 2;
 	  work -> typevec
-	    = (char **) xrealloc ((char *)work -> typevec,
-				  sizeof (char *) * work -> typevec_size);
+	    = XRESIZEVEC (char *, work->typevec, work->typevec_size);
 	}
     }
-  tem = xmalloc (len + 1);
+  tem = XNEWVEC (char, len + 1);
   memcpy (tem, start, len);
   tem[len] = '\0';
   work -> typevec[work -> ntypes++] = tem;
@@ -4124,18 +4118,16 @@
       if (work -> ksize == 0)
 	{
 	  work -> ksize = 5;
-	  work -> ktypevec
-	    = (char **) xmalloc (sizeof (char *) * work -> ksize);
+	  work -> ktypevec = XNEWVEC (char *, work->ksize);
 	}
       else
 	{
 	  work -> ksize *= 2;
 	  work -> ktypevec
-	    = (char **) xrealloc ((char *)work -> ktypevec,
-				  sizeof (char *) * work -> ksize);
+	    = XRESIZEVEC (char *, work->ktypevec, work->ksize);
 	}
     }
-  tem = xmalloc (len + 1);
+  tem = XNEWVEC (char, len + 1);
   memcpy (tem, start, len);
   tem[len] = '\0';
   work -> ktypevec[work -> numk++] = tem;
@@ -4155,15 +4147,13 @@
       if (work -> bsize == 0)
 	{
 	  work -> bsize = 5;
-	  work -> btypevec
-	    = (char **) xmalloc (sizeof (char *) * work -> bsize);
+	  work -> btypevec = XNEWVEC (char *, work->bsize);
 	}
       else
 	{
 	  work -> bsize *= 2;
 	  work -> btypevec
-	    = (char **) xrealloc ((char *)work -> btypevec,
-				  sizeof (char *) * work -> bsize);
+	    = XRESIZEVEC (char *, work->btypevec, work->bsize);
 	}
     }
   ret = work -> numb++;
@@ -4179,7 +4169,7 @@
 {
   char *tem;
 
-  tem = xmalloc (len + 1);
+  tem = XNEWVEC (char, len + 1);
   memcpy (tem, start, len);
   tem[len] = '\0';
   work -> btypevec[index] = tem;
@@ -4600,7 +4590,7 @@
 	{
 	  n = 32;
 	}
-      s->p = s->b = xmalloc (n);
+      s->p = s->b = XNEWVEC (char, n);
       s->e = s->b + n;
     }
   else if (s->e - s->p < n)
@@ -4608,7 +4598,7 @@
       tem = s->p - s->b;
       n += tem;
       n *= 2;
-      s->b = xrealloc (s->b, n);
+      s->b = XRESIZEVEC (char, s->b, n);
       s->p = s->b + tem;
       s->e = s->b + n;
     }
Index: libiberty/dyn-string.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/dyn-string.c,v
retrieving revision 1.10
diff -u -r1.10 dyn-string.c
--- libiberty/dyn-string.c	10 May 2005 15:33:16 -0000	1.10
+++ libiberty/dyn-string.c	24 May 2005 01:47:00 -0000
@@ -67,7 +67,7 @@
   if (ds_struct_ptr->s == NULL)
     return 0;
 #else
-  ds_struct_ptr->s = (char *) xmalloc (space);
+  ds_struct_ptr->s = XNEWVEC (char, space);
 #endif
   ds_struct_ptr->allocated = space;
   ds_struct_ptr->length = 0;
@@ -96,7 +96,7 @@
       return NULL;
     }
 #else
-  result = (dyn_string_t) xmalloc (sizeof (struct dyn_string));
+  result = XNEW (struct dyn_string);
   dyn_string_init (result, space);
 #endif
   return result;
@@ -159,7 +159,7 @@
 	  return NULL;
 	}
 #else
-      ds->s = (char *) xrealloc (ds->s, ds->allocated);
+      ds->s = XRESIZEVEC (char, ds->s, ds->allocated);
 #endif
     }
 
Index: libiberty/fnmatch.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/fnmatch.c,v
retrieving revision 1.8
diff -u -r1.8 fnmatch.c
--- libiberty/fnmatch.c	10 May 2005 15:33:17 -0000	1.8
+++ libiberty/fnmatch.c	24 May 2005 01:47:00 -0000
@@ -124,7 +124,7 @@
 	case '[':
 	  {
 	    /* Nonzero if the sense of the character class is inverted.  */
-	    register int not;
+	    register int negate;
 
 	    if (*n == '\0')
 	      return FNM_NOMATCH;
@@ -133,8 +133,8 @@
 		(n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
 	      return FNM_NOMATCH;
 
-	    not = (*p == '!' || *p == '^');
-	    if (not)
+	    negate = (*p == '!' || *p == '^');
+	    if (negate)
 	      ++p;
 
 	    c = *p++;
@@ -177,7 +177,7 @@
 		if (c == ']')
 		  break;
 	      }
-	    if (!not)
+	    if (!negate)
 	      return FNM_NOMATCH;
 	    break;
 
@@ -194,7 +194,7 @@
 		  /* XXX 1003.2d11 is unclear if this is right.  */
 		  ++p;
 	      }
-	    if (not)
+	    if (negate)
 	      return FNM_NOMATCH;
 	  }
 	  break;
Index: libiberty/getopt.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/getopt.c,v
retrieving revision 1.10
diff -u -r1.10 getopt.c
--- libiberty/getopt.c	10 May 2005 15:33:17 -0000	1.10
+++ libiberty/getopt.c	24 May 2005 01:47:00 -0000
@@ -212,8 +212,16 @@
 /* Avoid depending on library functions or files
    whose names are inconsistent.  */
 
-#ifndef getenv
-extern char *getenv ();
+#if HAVE_STDLIB_H && HAVE_DECL_GETENV
+#  include <stdlib.h>
+#elif !defined(getenv)
+#  ifdef __cplusplus
+extern "C" {
+#  endif /* __cplusplus */
+extern char *getenv (const char *);
+#  ifdef __cplusplus
+}
+#  endif /* __cplusplus */
 #endif
 
 static char *
@@ -325,7 +333,7 @@
     {
       /* We must extend the array.  The user plays games with us and
 	 presents new arguments.  */
-      char *new_str = malloc (top + 1);
+      char *new_str = (char *) malloc (top + 1);
       if (new_str == NULL)
 	nonoption_flags_len = nonoption_flags_max_len = 0;
       else
Index: libiberty/getpwd.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/getpwd.c,v
retrieving revision 1.7
diff -u -r1.7 getpwd.c
--- libiberty/getpwd.c	16 May 2005 13:52:39 -0000	1.7
+++ libiberty/getpwd.c	24 May 2005 01:47:00 -0000
@@ -84,7 +84,7 @@
 	     && dotstat.st_dev == pwdstat.st_dev))
 
 	/* The shortcut didn't work.  Try the slow, ``sure'' way.  */
-	for (s = GUESSPATHLEN;  ! getcwd (p = xmalloc (s), s);  s *= 2)
+	for (s = GUESSPATHLEN;  !getcwd (p = XNEWVEC (char, s), s);  s *= 2)
 	  {
 	    int e = errno;
 	    free (p);
@@ -117,7 +117,7 @@
   static char *pwd = 0;
 
   if (!pwd)
-    pwd = getcwd (xmalloc (MAXPATHLEN + 1), MAXPATHLEN + 1
+    pwd = getcwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1
 #ifdef VMS
 		  , 0
 #endif
Index: libiberty/hashtab.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/hashtab.c,v
retrieving revision 1.44
diff -u -r1.44 hashtab.c
--- libiberty/hashtab.c	10 May 2005 15:33:17 -0000	1.44
+++ libiberty/hashtab.c	24 May 2005 01:47:00 -0000
@@ -216,22 +216,6 @@
   return p1 == p2;
 }
 
-/* Return the current size of given hash table. */
-
-inline size_t
-htab_size (htab_t htab)
-{
-  return htab->size;
-}
-
-/* Return the current number of elements in given hash table. */
-
-inline size_t
-htab_elements (htab_t htab)
-{
-  return htab->n_elements - htab->n_deleted;
-}
-
 /* Return X % Y.  */
 
 static inline hashval_t
@@ -317,15 +301,10 @@
    an extra argument.  */
 
 htab_t
-htab_create_alloc_ex (size, hash_f, eq_f, del_f, alloc_arg, alloc_f,
-		      free_f)
-     size_t size;
-     htab_hash hash_f;
-     htab_eq eq_f;
-     htab_del del_f;
-     PTR alloc_arg;
-     htab_alloc_with_arg alloc_f;
-     htab_free_with_arg free_f;
+htab_create_alloc_ex (size_t size, htab_hash hash_f, htab_eq eq_f,
+                      htab_del del_f, void *alloc_arg,
+                      htab_alloc_with_arg alloc_f,
+		      htab_free_with_arg free_f)
 {
   htab_t result;
   unsigned int size_prime_index;
Index: libiberty/lrealpath.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/lrealpath.c,v
retrieving revision 1.4
diff -u -r1.4 lrealpath.c
--- libiberty/lrealpath.c	10 May 2005 15:33:17 -0000	1.4
+++ libiberty/lrealpath.c	24 May 2005 01:47:00 -0000
@@ -117,7 +117,7 @@
       {
 	/* PATH_MAX is bounded.  */
 	char *buf, *rp, *ret;
-	buf = malloc (path_max);
+	buf = (char *) malloc (path_max);
 	if (buf == NULL)
 	  return NULL;
 	rp = realpath (filename, buf);
Index: libiberty/make-relative-prefix.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/make-relative-prefix.c,v
retrieving revision 1.6
diff -u -r1.6 make-relative-prefix.c
--- libiberty/make-relative-prefix.c	10 May 2005 15:33:17 -0000	1.6
+++ libiberty/make-relative-prefix.c	24 May 2005 01:47:00 -0000
@@ -102,7 +102,7 @@
 static char *
 save_string (const char *s, int len)
 {
-  char *result = malloc (len + 1);
+  char *result = (char *) malloc (len + 1);
 
   memcpy (result, s, len);
   result[len] = 0;
Index: libiberty/make-temp-file.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/make-temp-file.c,v
retrieving revision 1.7
diff -u -r1.7 make-temp-file.c
--- libiberty/make-temp-file.c	10 May 2005 15:33:17 -0000	1.7
+++ libiberty/make-temp-file.c	24 May 2005 01:47:01 -0000
@@ -61,10 +61,10 @@
    If success, DIR is returned.
    Otherwise NULL is returned.  */
 
-static inline const char *try (const char *, const char *);
+static inline const char *try_dir (const char *, const char *);
 
 static inline const char *
-try (const char *dir, const char *base)
+try_dir (const char *dir, const char *base)
 {
   if (base != 0)
     return base;
@@ -103,18 +103,18 @@
   if (memoized_tmpdir)
     return memoized_tmpdir;
 
-  base = try (getenv ("TMPDIR"), base);
-  base = try (getenv ("TMP"), base);
-  base = try (getenv ("TEMP"), base);
+  base = try_dir (getenv ("TMPDIR"), base);
+  base = try_dir (getenv ("TMP"), base);
+  base = try_dir (getenv ("TEMP"), base);
 
 #ifdef P_tmpdir
-  base = try (P_tmpdir, base);
+  base = try_dir (P_tmpdir, base);
 #endif
 
   /* Try /var/tmp, /usr/tmp, then /tmp.  */
-  base = try (vartmp, base);
-  base = try (usrtmp, base);
-  base = try (tmp, base);
+  base = try_dir (vartmp, base);
+  base = try_dir (usrtmp, base);
+  base = try_dir (tmp, base);
  
   /* If all else fails, use the current directory!  */
   if (base == 0)
@@ -123,7 +123,7 @@
   /* Append DIR_SEPARATOR to the directory we've chosen
      and return it.  */
   len = strlen (base);
-  tmpdir = xmalloc (len + 2);
+  tmpdir = XNEWVEC (char, len + 2);
   strcpy (tmpdir, base);
   tmpdir[len] = DIR_SEPARATOR;
   tmpdir[len+1] = '\0';
@@ -158,7 +158,7 @@
   base_len = strlen (base);
   suffix_len = strlen (suffix);
 
-  temp_filename = xmalloc (base_len
+  temp_filename = XNEWVEC (char, base_len
 			   + TEMP_FILE_LEN
 			   + suffix_len + 1);
   strcpy (temp_filename, base);
Index: libiberty/mkstemps.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/mkstemps.c,v
retrieving revision 1.10
diff -u -r1.10 mkstemps.c
--- libiberty/mkstemps.c	10 May 2005 15:33:17 -0000	1.10
+++ libiberty/mkstemps.c	24 May 2005 01:47:01 -0000
@@ -51,17 +51,17 @@
 
 /*
 
-@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len})
+@deftypefn Replacement int mkstemps (char *@var{pattern}, int @var{suffix_len})
 
-Generate a unique temporary file name from @var{template}.
-@var{template} has the form:
+Generate a unique temporary file name from @var{pattern}.
+@var{pattern} has the form:
 
 @example
    @var{path}/ccXXXXXX@var{suffix}
 @end example
 
 @var{suffix_len} tells us how long @var{suffix} is (it can be zero
-length).  The last six characters of @var{template} before @var{suffix}
+length).  The last six characters of @var{pattern} before @var{suffix}
 must be @samp{XXXXXX}; they are replaced with a string that makes the
 filename unique.  Returns a file descriptor open on the file for
 reading and writing.
@@ -71,7 +71,7 @@
 */
 
 int
-mkstemps (char *template, int suffix_len)
+mkstemps (char *pattern, int suffix_len)
 {
   static const char letters[]
     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@ -83,15 +83,15 @@
   size_t len;
   int count;
 
-  len = strlen (template);
+  len = strlen (pattern);
 
   if ((int) len < 6 + suffix_len
-      || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6))
+      || strncmp (&pattern[len - 6 - suffix_len], "XXXXXX", 6))
     {
       return -1;
     }
 
-  XXXXXX = &template[len - 6 - suffix_len];
+  XXXXXX = &pattern[len - 6 - suffix_len];
 
 #ifdef HAVE_GETTIMEOFDAY
   /* Get some more or less random data.  */
@@ -119,7 +119,7 @@
       v /= 62;
       XXXXXX[5] = letters[v % 62];
 
-      fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600);
+      fd = open (pattern, O_RDWR|O_CREAT|O_EXCL, 0600);
       if (fd >= 0)
 	/* The file does not exist.  */
 	return fd;
@@ -131,6 +131,6 @@
     }
 
   /* We return the null string if we can't find a unique file name.  */
-  template[0] = '\0';
+  pattern[0] = '\0';
   return -1;
 }
Index: libiberty/pex-common.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pex-common.c,v
retrieving revision 1.2
diff -u -r1.2 pex-common.c
--- libiberty/pex-common.c	10 May 2005 15:33:17 -0000	1.2
+++ libiberty/pex-common.c	24 May 2005 01:47:01 -0000
@@ -55,7 +55,7 @@
 {
   struct pex_obj *obj;
 
-  obj = xmalloc (sizeof (*obj));
+  obj = XNEW (struct pex_obj);
   obj->flags = flags;
   obj->pname = pname;
   obj->tempbase = tempbase;
@@ -83,7 +83,7 @@
   char *add;
 
   ++obj->remove_count;
-  obj->remove = xrealloc (obj->remove, obj->remove_count * sizeof (char *));
+  obj->remove = XRESIZEVEC (char *, obj->remove, obj->remove_count);
   if (allocated)
     add = (char *) name;
   else
@@ -280,7 +280,7 @@
     goto error_exit;
 
   ++obj->count;
-  obj->children = xrealloc (obj->children, obj->count * sizeof (long));
+  obj->children = XRESIZEVEC (long, obj->children, obj->count);
   obj->children[obj->count - 1] = pid;
 
   return NULL;
@@ -352,9 +352,9 @@
   if (obj->number_waited == obj->count)
     return 1;
 
-  obj->status = xrealloc (obj->status, obj->count * sizeof (int));
+  obj->status = XRESIZEVEC (int, obj->status, obj->count);
   if ((obj->flags & PEX_RECORD_TIMES) != 0)
-    obj->time = xrealloc (obj->time, obj->count * sizeof (struct pex_time));
+    obj->time = XRESIZEVEC (struct pex_time, obj->time, obj->count);
 
   ret = 1;
   for (i = obj->number_waited; i < obj->count; ++i)
Index: libiberty/pex-djgpp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pex-djgpp.c,v
retrieving revision 1.5
diff -u -r1.5 pex-djgpp.c
--- libiberty/pex-djgpp.c	12 May 2005 03:44:58 -0000	1.5
+++ libiberty/pex-djgpp.c	24 May 2005 01:47:01 -0000
@@ -257,7 +257,7 @@
      is the number of children which have executed before this
      one.  */
   statuses = (int *) obj->sysdep;
-  statuses = xrealloc (statuses, (obj->count + 1) * sizeof (int));
+  statuses = XRESIZEVEC (int, statuses, obj->count + 1);
   statuses[obj->count] = status;
   obj->sysdep = (void *) statuses;
 
Index: libiberty/pex-msdos.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pex-msdos.c,v
retrieving revision 1.4
diff -u -r1.4 pex-msdos.c
--- libiberty/pex-msdos.c	10 May 2005 15:33:18 -0000	1.4
+++ libiberty/pex-msdos.c	24 May 2005 01:47:01 -0000
@@ -89,7 +89,7 @@
 
   ret = pex_init_common (flags, pname, tempbase, funcs);
 
-  ret->sysdep = xmalloc (sizeof (struct pex_msdos));
+  ret->sysdep = XNEW (struct pex_msdos);
   for (i = 0; i < PEX_MSDOS_FILE_COUNT; ++i)
     ret->files[i] = NULL;
   ret->statuses = NULL;
@@ -210,7 +210,7 @@
       outfile = ms->files[outindex];
     }
 
-  scmd = xmalloc (strlen (program)
+  scmd = XNEWVEC (char, strlen (program)
 		  + ((flags & PEXECUTE_SEARCH) != 0 ? 4 : 0)
 		  + strlen (rf)
 		  + strlen (infile)
@@ -269,7 +269,7 @@
   /* Save the exit status for later.  When we are called, obj->count
      is the number of children which have executed before this
      one.  */
-  ms->statuses = xrealloc (ms->statuses, (obj->count + 1) * sizeof (int));
+  ms->statuses = XRESIZEVEC(int, ms->statuses, obj->count + 1);
   ms->statuses[obj->count] = status;
 
   return obj->count;
Index: libiberty/pex-unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pex-unix.c,v
retrieving revision 1.6
diff -u -r1.6 pex-unix.c
--- libiberty/pex-unix.c	10 May 2005 15:33:18 -0000	1.6
+++ libiberty/pex-unix.c	24 May 2005 01:47:01 -0000
@@ -252,7 +252,7 @@
 	  return cpid;
 	}
 
-      psl = xmalloc (sizeof (struct status_list));
+      psl = XNEW (struct status_list);
       psl->pid = cpid;
       psl->status = *status;
       if (time != NULL)
Index: libiberty/pex-win32.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pex-win32.c,v
retrieving revision 1.7
diff -u -r1.7 pex-win32.c
--- libiberty/pex-win32.c	10 May 2005 15:33:18 -0000	1.7
+++ libiberty/pex-win32.c	24 May 2005 01:47:01 -0000
@@ -79,7 +79,7 @@
 
   for (i = 0; argvec[i] != NULL; i++)
     ;
-  argv = xmalloc ((i + 1) * sizeof (char *));
+  argv = XNEWVEC (char *, i + 1);
   for (i = 0; argvec[i] != NULL; i++)
     argv[i] = xstrdup (argvec[i]);
   argv[i] = NULL;
@@ -105,7 +105,7 @@
         {
           if (temp[j] == '"')
             {
-              newtemp = xmalloc (len + 2);
+              newtemp = XNEWVEC (char, len + 2);
               strncpy (newtemp, temp, j);
               newtemp [j] = '\\';
               strncpy (&newtemp [j+1], &temp [j], len-j);
@@ -150,7 +150,7 @@
 
 	  len += 2;			/* and for the enclosing quotes. */
 
-	  temp = xmalloc (len + 1);
+	  temp = XNEWVEC (char, len + 1);
 	  temp[0] = '"';
 	  strcpy (temp + 1, argv[i]);
 	  if (trailing_backslash)
Index: libiberty/pexecute.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/pexecute.c,v
retrieving revision 1.26
diff -u -r1.26 pexecute.c
--- libiberty/pexecute.c	10 May 2005 15:33:18 -0000	1.26
+++ libiberty/pexecute.c	24 May 2005 01:47:01 -0000
@@ -99,7 +99,7 @@
     {
       int *vector;
 
-      vector = xmalloc (idx * sizeof (int));
+      vector = XNEWVEC (int, idx);
       if (!pex_get_status (pex, idx, vector))
 	return -1;
       *status = vector[pid];
Index: libiberty/setenv.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/setenv.c,v
retrieving revision 1.12
diff -u -r1.12 setenv.c
--- libiberty/setenv.c	10 May 2005 15:33:18 -0000	1.12
+++ libiberty/setenv.c	24 May 2005 01:47:01 -0000
@@ -115,7 +115,7 @@
 	  return -1;
 	}
 
-      new_environ[size] = malloc (namelen + 1 + vallen);
+      new_environ[size] = (char *) malloc (namelen + 1 + vallen);
       if (new_environ[size] == NULL)
 	{
 	  free ((char *) new_environ);
@@ -142,13 +142,13 @@
       if (len + 1 < namelen + 1 + vallen)
 	{
 	  /* The existing string is too short; malloc a new one.  */
-	  char *new = malloc (namelen + 1 + vallen);
-	  if (new == NULL)
+	  char *new_string = (char *) malloc (namelen + 1 + vallen);
+	  if (new_string == NULL)
 	    {
 	      UNLOCK;
 	      return -1;
 	    }
-	  *ep = new;
+	  *ep = new_string;
 	}
       memcpy (*ep, name, namelen);
       (*ep)[namelen] = '=';
Index: libiberty/sigsetmask.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/sigsetmask.c,v
retrieving revision 1.6
diff -u -r1.6 sigsetmask.c
--- libiberty/sigsetmask.c	28 Mar 2005 04:22:33 -0000	1.6
+++ libiberty/sigsetmask.c	24 May 2005 01:47:01 -0000
@@ -27,14 +27,14 @@
 int
 sigsetmask (int set)
 {
-    sigset_t new;
-    sigset_t old;
+    sigset_t new_sig;
+    sigset_t old_sig;
     
-    sigemptyset (&new);
+    sigemptyset (&new_sig);
     if (set != 0) {
       abort();	/* FIXME, we don't know how to translate old mask to new */
     }
-    sigprocmask(SIG_SETMASK, &new, &old);
+    sigprocmask(SIG_SETMASK, &new_sig, &old_sig);
     return 1;	/* FIXME, we always return 1 as old value.  */
 }
 #endif
Index: libiberty/sort.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/sort.c,v
retrieving revision 1.7
diff -u -r1.7 sort.c
--- libiberty/sort.c	10 May 2005 15:33:18 -0000	1.7
+++ libiberty/sort.c	24 May 2005 01:47:01 -0000
@@ -155,8 +155,8 @@
   else
     k = 10;
 
-  pointers = xmalloc (k * sizeof (void *));
-  work = xmalloc (k * sizeof (void *));
+  pointers = XNEWVEC (void*, k);
+  work = XNEWVEC (void*, k);
 
   for (i = 0; i < k; ++i)
     {
Index: libiberty/spaces.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/spaces.c,v
retrieving revision 1.6
diff -u -r1.6 spaces.c
--- libiberty/spaces.c	10 May 2005 15:33:18 -0000	1.6
+++ libiberty/spaces.c	24 May 2005 01:47:01 -0000
@@ -57,7 +57,7 @@
 	{
 	  free (buf);
 	}
-      buf = malloc (count + 1);
+      buf = (char *) malloc (count + 1);
       if (buf == (char *) 0)
 	return 0;
       for (t = buf + count ; t != buf ; )
Index: libiberty/strndup.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/strndup.c,v
retrieving revision 1.3
diff -u -r1.3 strndup.c
--- libiberty/strndup.c	10 May 2005 15:33:18 -0000	1.3
+++ libiberty/strndup.c	24 May 2005 01:47:01 -0000
@@ -46,10 +46,10 @@
   if (n < len)
     len = n;
 
-  result = malloc (len + 1);
+  result = (char *) malloc (len + 1);
   if (!result)
     return 0;
 
   result[len] = '\0';
-  return memcpy (result, s, len);
+  return (char *) memcpy (result, s, len);
 }
Index: libiberty/ternary.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/ternary.c,v
retrieving revision 1.4
diff -u -r1.4 ternary.c
--- libiberty/ternary.c	10 May 2005 15:33:18 -0000	1.4
+++ libiberty/ternary.c	24 May 2005 01:47:01 -0000
@@ -74,7 +74,7 @@
   for (;;)
     {
       /* Allocate the memory for the node, and fill it in */
-      *pcurr = (ternary_tree) xmalloc (sizeof (ternary_node));
+      *pcurr = XNEW (ternary_node);
       curr = *pcurr;
       curr->splitchar = *s;
       curr->lokid = curr->hikid = curr->eqkid = 0;
Index: libiberty/xmalloc.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xmalloc.c,v
retrieving revision 1.18
diff -u -r1.18 xmalloc.c
--- libiberty/xmalloc.c	10 May 2005 15:33:18 -0000	1.18
+++ libiberty/xmalloc.c	24 May 2005 01:47:01 -0000
@@ -75,11 +75,23 @@
 #include <unixlib.h>
 #else
 /* For systems with larger pointers than ints, these must be declared.  */
-PTR malloc (size_t);
-PTR realloc (PTR, size_t);
-PTR calloc (size_t, size_t);
-PTR sbrk (ptrdiff_t);
-#endif
+#  if HAVE_STDLIB_H && HAVE_UNISTD_H && HAVE_DECL_MALLOC \
+      && HAVE_DECL_REALLOC && HAVE_DECL_CALLOC && HAVE_DECL_SBRK
+#    include <stdlib.h>
+#    include <unistd.h>
+#  else
+#    ifdef __cplusplus
+extern "C" {
+#    endif /* __cplusplus */
+void *malloc (size_t);
+void *realloc (void *, size_t);
+void *calloc (size_t, size_t);
+void *sbrk (ptrdiff_t);
+#    ifdef __cplusplus
+}
+#    endif /* __cplusplus */
+#  endif /* HAVE_STDLIB_H ...  */
+#endif /* VMS */
 
 /* The program name if set.  */
 static const char *name = "";
Index: libiberty/xstrdup.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xstrdup.c,v
retrieving revision 1.9
diff -u -r1.9 xstrdup.c
--- libiberty/xstrdup.c	28 Mar 2005 01:28:01 -0000	1.9
+++ libiberty/xstrdup.c	24 May 2005 01:47:01 -0000
@@ -31,6 +31,6 @@
 xstrdup (const char *s)
 {
   register size_t len = strlen (s) + 1;
-  register char *ret = xmalloc (len);
+  register char *ret = XNEWVEC (char, len);
   return (char *) memcpy (ret, s, len);
 }
Index: libiberty/xstrerror.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xstrerror.c,v
retrieving revision 1.6
diff -u -r1.6 xstrerror.c
--- libiberty/xstrerror.c	28 Mar 2005 01:28:01 -0000	1.6
+++ libiberty/xstrerror.c	24 May 2005 01:47:01 -0000
@@ -19,15 +19,28 @@
 #include "libiberty.h"
 
 #ifdef VMS
-#include <errno.h>
-#if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
+#  include <errno.h>
+#  if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
+#    ifdef __cplusplus
+extern "C" {
+#    endif /* __cplusplus */
 extern char *strerror (int,...);
-#define DONT_DECLARE_STRERROR
-#endif
-#endif	/* VMS */
+#    define DONT_DECLARE_STRERROR
+#    ifdef __cplusplus
+}
+#    endif /* __cplusplus */
+#  endif
+#endif  /* VMS */
+
 
 #ifndef DONT_DECLARE_STRERROR
+#  ifdef __cplusplus
+extern "C" {
+#  endif /* __cplusplus */
 extern char *strerror (int);
+#  ifdef __cplusplus
+}
+#  endif /* __cplusplus */
 #endif
 
 /* If strerror returns NULL, we'll format the number into a static buffer.  */
Index: libiberty/xstrndup.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xstrndup.c,v
retrieving revision 1.3
diff -u -r1.3 xstrndup.c
--- libiberty/xstrndup.c	10 May 2005 15:33:18 -0000	1.3
+++ libiberty/xstrndup.c	24 May 2005 01:47:01 -0000
@@ -53,8 +53,8 @@
   if (n < len)
     len = n;
 
-  result = xmalloc (len + 1);
+  result = XNEWVEC (char, len + 1);
 
   result[len] = '\0';
-  return memcpy (result, s, len);
+  return (char *) memcpy (result, s, len);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]