This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH to libcpp: Move to the intersection of C90 an C++
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Zack Weinberg <zack at codesourcery dot com>, Per Bothner <per at bothner dot com>
- Date: 24 May 2005 06:33:07 +0200
- Subject: PATCH to libcpp: Move to the intersection of C90 an C++
Hi,
This patch moves libcpp to the intersection of C90 and C++.
It survived testing on i686-pc-linux-gnu, sparc-sun-solaris2.7 and
sparc-sun-solaris2.8
HAVE_DESIGNATED_INITIALIZERS cannot be true if __cplusplus.
We don't want to #define to unsigned char if __cplusplus
(that causes link failure when bulding the GNU C compiler with
g++, as gcc/system.h do not #define bool in that case).
The definition of union _cpp_hashnode_value needs to be moved at the
global scope, because a structure defines a scope in C++ (while they
don't in C)
OK to install when mainline is back?
-- Gaby
2005-05-23 Gabriel Dos Reis <gdr@integrable-solutions.net>
* configure.ac: Check declarations for asprintf and vasprintf.
* config.in: Regenerate.
* configure: Likewise.
* charset.c (conversion_loop): Use XRESIZEVEC.
(convert_no_conversion): Likewise.
(convert_using_iconv): Likewise.
(init_iconv_desc): Cast return value of alloca.
(cpp_host_to_exec_charset): Use XNEWVEC.
(emit_numeric_escape): Use XRESIZEVEC.
(cpp_interpret_string): Use XNEWVEC.
(cpp_interpret_string): Use XRESIZEVEC.
(_cpp_interpret_identifier): Cast return value of alloca.
(_cpp_convert_input): Use XNEWVEC and XRESIZEVEC.
* directives.c (glue_header_name): Use XNEWVEC and XRESIZEVEC.
(parse_include): Use XNEWVEC.
(insert_pragma_entry): Rename local variable "new" to
"new_entry".
(save_registered_pragmas): Cast return value of xmemdup.
(destringize_and_run): Same for alloca.
(parse_assertion): Likewise.
(do_assert): Cast allocated storage to proper type.
(cpp_define): Likewise.
(_cpp_define_builtin): Likewise.
(cpp_undef): Likewise.
(handle_assertion): Likewise.
(cpp_push_buffer): Rename local variable "new" to "new_buffer".
* expr.c (CPP_UPLUS): Cast value to type cpp_ttype.
(CPP_UMINUS): Likewise.
(struct cpp_operator): Rename from struct operator.
(_cpp_expand_op_stack): Use XRESIZEVEC.
* files.c (pch_open_file): Use XNEWVEC.
(pch_open_file): Use XRESIZEVEC.
(read_file_guts): Use XNEWVEC and XRESIZEVEC.
(dir_name_of_file): Use XNEWVEC.
(make_cpp_file): Use XCNEW.
(make_cpp_dir): Likewise.
(allocate_file_hash_entries): USE XNEWVEC.
(cpp_included): Cast return value of htab_find_with_hash.
(append_file_to_dir): Use XNEWVEC.
(read_filename_string): Likewise. Use XRESIZEVEC too.
(read_name_map): Cast return value of alloca. Use XRESIZEVEC.
(remap_filename): Use XNEWVEC.
(struct pchf_entry): Move definition out of struct pchf_data.
(_cpp_save_file_entries): Use XCNEWVAR.
(_cpp_read_file_entries): Use XNEWVAR.
* identifiers.c (alloc_node): Use XOBNEW.
* init.c (cpp_create_reader): Use XCNEW.
(cpp_init_builtins): Cast of b->value to enum builtin_type.
(read_original_directory): Cast return value of alloca.
* lex.c (add_line_note): Use XRESIZEVEC.
(warn_about_normalization): Use XNEWVEC.
(_cpp_lex_direct): Cast node->directive_index to (enum cpp_ttype).
(new_buff): Use XNEWVEC.
* line-map.c (linemap_add): Use XRESIZEVEC.
* macro.c (builtin_macro): Cast return value of alloca.
(paste_tokens): Likewise.
(expand_arg): Use XNEWVEC and XRESIZEVEC.
(_cpp_save_parameter): Use XRESIZEVEC.
(create_iso_definition): Cast allocated storage to proper type.
(_cpp_create_definition): Likewise.
(cpp_macro_definition): Use XRESIZEVEC.
* makedepend.c (add_clm): Use XNEW.
(add_dir): Likewise.
* mkdeps.c (munge): Use XNEWVEC.
(deps_init): Use XCNEW.
(deps_add_target): Use XRESIZEVEC.
(deps_add_default_target): Cast return value of alloca.
(deps_add_dep): Use XRESIZEVEC.
(deps_add_vpath): Likewise. Use XNEWVEC too.
(deps_restore): Likewise.
* pch.c (save_idents): Use XNEW and XNEWVEC.
(cpp_save_state): Use XNEW.
(count_defs): Cast return value of htab_find.
(write_defs): Likewise.
(cpp_write_pch_deps): Use XNEWVEC.
(collect_ht_nodes): Use XRESIZEVEC.
(cpp_valid_state): Use XNEWVEC.
(save_macros): Use XRESIZEVEC. Cast return value of xmemdup.
* symtab.c (ht_create): Use XCNEW.
(ht_lookup_with_hash): Cast return value of obstack_copy0.
(ht_expand): Use XCNEWVEC.
* system.h (HAVE_DESIGNATED_INITIALIZERS): False if __cplusplus.
(bool): Do not define if __cplusplus.
Index: libcpp/charset.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/charset.c,v
retrieving revision 1.8
diff -u -r1.8 charset.c
--- libcpp/charset.c 16 Mar 2005 00:59:30 -0000 1.8
+++ libcpp/charset.c 24 May 2005 03:13:15 -0000
@@ -486,7 +486,7 @@
outbytesleft += OUTBUF_BLOCK_SIZE;
to->asize += OUTBUF_BLOCK_SIZE;
- to->text = xrealloc (to->text, to->asize);
+ to->text = XRESIZEVEC (uchar, to->text, to->asize);
outbuf = to->text + to->asize - outbytesleft;
}
}
@@ -538,7 +538,7 @@
if (to->len + flen > to->asize)
{
to->asize = to->len + flen;
- to->text = xrealloc (to->text, to->asize);
+ to->text = XRESIZEVEC (uchar, to->text, to->asize);
}
memcpy (to->text + to->len, from, flen);
to->len += flen;
@@ -578,7 +578,7 @@
outbytesleft += OUTBUF_BLOCK_SIZE;
to->asize += OUTBUF_BLOCK_SIZE;
- to->text = xrealloc (to->text, to->asize);
+ to->text = XRESIZEVEC (uchar, to->text, to->asize);
outbuf = (char *)to->text + to->asize - outbytesleft;
}
}
@@ -628,7 +628,7 @@
return ret;
}
- pair = alloca(strlen(to) + strlen(from) + 2);
+ pair = (char *) alloca(strlen(to) + strlen(from) + 2);
strcpy(pair, from);
strcat(pair, "/");
@@ -751,7 +751,7 @@
/* This should never need to reallocate, but just in case... */
tbuf.asize = 1;
- tbuf.text = xmalloc (tbuf.asize);
+ tbuf.text = XNEWVEC (uchar, tbuf.asize);
tbuf.len = 0;
if (!APPLY_CONVERSION (pfile->narrow_cset_desc, sbuf, 1, &tbuf))
@@ -1087,7 +1087,7 @@
if (tbuf->len + nbwc > tbuf->asize)
{
tbuf->asize += OUTBUF_BLOCK_SIZE;
- tbuf->text = xrealloc (tbuf->text, tbuf->asize);
+ tbuf->text = XRESIZEVEC (uchar, tbuf->text, tbuf->asize);
}
for (i = 0; i < nbwc; i++)
@@ -1105,7 +1105,7 @@
if (tbuf->len + 1 > tbuf->asize)
{
tbuf->asize += OUTBUF_BLOCK_SIZE;
- tbuf->text = xrealloc (tbuf->text, tbuf->asize);
+ tbuf->text = XRESIZEVEC (uchar, tbuf->text, tbuf->asize);
}
tbuf->text[tbuf->len++] = n;
}
@@ -1306,7 +1306,7 @@
= wide ? pfile->wide_cset_desc : pfile->narrow_cset_desc;
tbuf.asize = MAX (OUTBUF_BLOCK_SIZE, from->len);
- tbuf.text = xmalloc (tbuf.asize);
+ tbuf.text = XNEWVEC (uchar, tbuf.asize);
tbuf.len = 0;
for (i = 0; i < count; i++)
@@ -1337,7 +1337,7 @@
/* NUL-terminate the 'to' buffer and translate it to a cpp_string
structure. */
emit_numeric_escape (pfile, 0, &tbuf, wide);
- tbuf.text = xrealloc (tbuf.text, tbuf.len);
+ tbuf.text = XRESIZEVEC (uchar, tbuf.text, tbuf.len);
to->text = tbuf.text;
to->len = tbuf.len;
return true;
@@ -1526,7 +1526,7 @@
{
/* It turns out that a UCN escape always turns into fewer characters
than the escape itself, so we can allocate a temporary in advance. */
- uchar * buf = alloca (len + 1);
+ uchar * buf = (uchar *) alloca (len + 1);
uchar * bufp = buf;
size_t idp;
@@ -1598,7 +1598,7 @@
else
{
to.asize = MAX (65536, len);
- to.text = xmalloc (to.asize);
+ to.text = XNEWVEC (uchar, to.asize);
to.len = 0;
if (!APPLY_CONVERSION (input_cset, input, len, &to))
@@ -1616,7 +1616,7 @@
/* Resize buffer if we allocated substantially too much, or if we
haven't enough space for the \n-terminator. */
if (to.len + 4096 < to.asize || to.len >= to.asize)
- to.text = xrealloc (to.text, to.len + 1);
+ to.text = XRESIZEVEC (uchar, to.text, to.len + 1);
/* If the file is using old-school Mac line endings (\r only),
terminate with another \r, not an \n, so that we do not mistake
Index: libcpp/config.in
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/config.in,v
retrieving revision 1.5
diff -u -r1.5 config.in
--- libcpp/config.in 11 Apr 2005 21:46:59 -0000 1.5
+++ libcpp/config.in 24 May 2005 03:13:15 -0000
@@ -29,6 +29,10 @@
*/
#undef HAVE_DECL_ABORT
+/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_ASPRINTF
+
/* Define to 1 if you have the declaration of `basename', and to 0 if you
don't. */
#undef HAVE_DECL_BASENAME
@@ -105,6 +109,10 @@
don't. */
#undef HAVE_DECL_PUTC_UNLOCKED
+/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_VASPRINTF
+
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
Index: libcpp/configure
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/configure,v
retrieving revision 1.16
diff -u -r1.16 configure
--- libcpp/configure 12 May 2005 12:22:08 -0000 1.16
+++ libcpp/configure 24 May 2005 03:13:15 -0000
@@ -5077,6 +5077,76 @@
fi
+echo "$as_me:$LINENO: checking whether asprintf is declared" >&5
+echo $ECHO_N "checking whether asprintf is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_asprintf+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 asprintf
+ char *p = (char *) asprintf;
+#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_asprintf=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_asprintf=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_asprintf" >&5
+echo "${ECHO_T}$ac_cv_have_decl_asprintf" >&6
+if test $ac_cv_have_decl_asprintf = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_ASPRINTF 1
+_ACEOF
+
+
+else
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_ASPRINTF 0
+_ACEOF
+
+
+fi
echo "$as_me:$LINENO: checking whether basename is declared" >&5
echo $ECHO_N "checking whether basename is declared... $ECHO_C" >&6
if test "${ac_cv_have_decl_basename+set}" = set; then
@@ -6407,6 +6477,76 @@
fi
+echo "$as_me:$LINENO: checking whether vasprintf is declared" >&5
+echo $ECHO_N "checking whether vasprintf is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_vasprintf+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 vasprintf
+ char *p = (char *) vasprintf;
+#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_vasprintf=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_vasprintf=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_vasprintf" >&5
+echo "${ECHO_T}$ac_cv_have_decl_vasprintf" >&6
+if test $ac_cv_have_decl_vasprintf = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_VASPRINTF 1
+_ACEOF
+
+
+else
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_VASPRINTF 0
+_ACEOF
+
+
+fi
Index: libcpp/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/configure.ac,v
retrieving revision 1.13
diff -u -r1.13 configure.ac
--- libcpp/configure.ac 11 Apr 2005 21:46:59 -0000 1.13
+++ libcpp/configure.ac 24 May 2005 03:13:15 -0000
@@ -50,7 +50,8 @@
fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked dnl
putchar_unlocked putc_unlocked)
AC_CHECK_FUNCS(libcpp_UNLOCKED_FUNCS)
-AC_CHECK_DECLS(m4_split(m4_normalize(abort basename errno getopt libcpp_UNLOCKED_FUNCS)))
+AC_CHECK_DECLS(m4_split(m4_normalize(abort asprintf basename errno getopt \
+ libcpp_UNLOCKED_FUNCS vasprintf)))
# Checks for library functions.
AC_FUNC_ALLOCA
Index: libcpp/directives.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/directives.c,v
retrieving revision 1.15
diff -u -r1.15 directives.c
--- libcpp/directives.c 12 May 2005 18:31:10 -0000 1.15
+++ libcpp/directives.c 24 May 2005 03:13:16 -0000
@@ -588,7 +588,7 @@
/* To avoid lexed tokens overwriting our glued name, we can only
allocate from the string pool once we've lexed everything. */
- buffer = xmalloc (capacity);
+ buffer = XNEWVEC (char, capacity);
for (;;)
{
token = get_token_no_padding (pfile);
@@ -605,7 +605,7 @@
if (total_len + len > capacity)
{
capacity = (capacity + len) * 2;
- buffer = xrealloc (buffer, capacity);
+ buffer = XRESIZEVEC (char, buffer, capacity);
}
if (token->flags & PREV_WHITE)
@@ -633,7 +633,7 @@
header = get_token_no_padding (pfile);
if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME)
{
- fname = xmalloc (header->val.str.len - 1);
+ fname = XNEWVEC (char, header->val.str.len - 1);
memcpy (fname, header->val.str.text + 1, header->val.str.len - 2);
fname[header->val.str.len - 2] = '\0';
*pangle_brackets = header->type == CPP_HEADER_NAME;
@@ -985,27 +985,27 @@
const cpp_hashnode *pragma, pragma_cb handler,
bool allow_expansion, bool internal)
{
- struct pragma_entry *new;
+ struct pragma_entry *new_entry;
- new = (struct pragma_entry *)
+ new_entry = (struct pragma_entry *)
_cpp_aligned_alloc (pfile, sizeof (struct pragma_entry));
- new->pragma = pragma;
+ new_entry->pragma = pragma;
if (handler)
{
- new->is_nspace = 0;
- new->u.handler = handler;
+ new_entry->is_nspace = 0;
+ new_entry->u.handler = handler;
}
else
{
- new->is_nspace = 1;
- new->u.space = NULL;
+ new_entry->is_nspace = 1;
+ new_entry->u.space = NULL;
}
- new->allow_expansion = allow_expansion;
- new->is_internal = internal;
- new->next = *chain;
- *chain = new;
- return new;
+ new_entry->allow_expansion = allow_expansion;
+ new_entry->is_internal = internal;
+ new_entry->next = *chain;
+ *chain = new_entry;
+ return new_entry;
}
/* Register a pragma NAME in namespace SPACE. If SPACE is null, it
@@ -1110,9 +1110,9 @@
{
if (pe->is_nspace)
sd = save_registered_pragmas (pe->u.space, sd);
- *sd++ = xmemdup (HT_STR (&pe->pragma->ident),
- HT_LEN (&pe->pragma->ident),
- HT_LEN (&pe->pragma->ident) + 1);
+ *sd++ = (char *) xmemdup (HT_STR (&pe->pragma->ident),
+ HT_LEN (&pe->pragma->ident),
+ HT_LEN (&pe->pragma->ident) + 1);
}
return sd;
}
@@ -1383,7 +1383,7 @@
const unsigned char *src, *limit;
char *dest, *result;
- dest = result = alloca (in->len - 1);
+ dest = result = (char *) alloca (in->len - 1);
src = in->text + 1 + (in->text[0] == 'L');
limit = in->text + in->len - 1;
while (src < limit)
@@ -1760,7 +1760,7 @@
else if (parse_answer (pfile, answerp, type) == 0)
{
unsigned int len = NODE_LEN (predicate->val.node);
- unsigned char *sym = alloca (len + 1);
+ unsigned char *sym = (unsigned char *) alloca (len + 1);
/* Prefix '#' to get it out of macro namespace. */
sym[0] = '#';
@@ -1855,7 +1855,8 @@
if (pfile->hash_table->alloc_subobject)
{
struct answer *temp_answer = new_answer;
- new_answer = pfile->hash_table->alloc_subobject (answer_size);
+ new_answer = (struct answer *) pfile->hash_table->alloc_subobject
+ (answer_size);
memcpy (new_answer, temp_answer, answer_size);
}
else
@@ -1917,7 +1918,7 @@
tack " 1" on the end. */
count = strlen (str);
- buf = alloca (count + 3);
+ buf = (char *) alloca (count + 3);
memcpy (buf, str, count);
p = strchr (str, '=');
@@ -1938,7 +1939,7 @@
_cpp_define_builtin (cpp_reader *pfile, const char *str)
{
size_t len = strlen (str);
- char *buf = alloca (len + 1);
+ char *buf = (char *) alloca (len + 1);
memcpy (buf, str, len);
buf[len] = '\n';
run_directive (pfile, T_DEFINE, buf, len);
@@ -1949,7 +1950,7 @@
cpp_undef (cpp_reader *pfile, const char *macro)
{
size_t len = strlen (macro);
- char *buf = alloca (len + 1);
+ char *buf = (char *) alloca (len + 1);
memcpy (buf, macro, len);
buf[len] = '\n';
run_directive (pfile, T_UNDEF, buf, len);
@@ -1978,7 +1979,7 @@
/* Copy the entire option so we can modify it. Change the first
"=" in the string to a '(', and tack a ')' on the end. */
- char *buf = alloca (count + 2);
+ char *buf = (char *) alloca (count + 2);
memcpy (buf, str, count);
if (p)
@@ -2036,20 +2037,20 @@
cpp_push_buffer (cpp_reader *pfile, const uchar *buffer, size_t len,
int from_stage3)
{
- cpp_buffer *new = XOBNEW (&pfile->buffer_ob, cpp_buffer);
+ cpp_buffer *new_buffer = XOBNEW (&pfile->buffer_ob, cpp_buffer);
/* Clears, amongst other things, if_stack and mi_cmacro. */
- memset (new, 0, sizeof (cpp_buffer));
+ memset (new_buffer, 0, sizeof (cpp_buffer));
- new->next_line = new->buf = buffer;
- new->rlimit = buffer + len;
- new->from_stage3 = from_stage3;
- new->prev = pfile->buffer;
- new->need_line = true;
+ new_buffer->next_line = new_buffer->buf = buffer;
+ new_buffer->rlimit = buffer + len;
+ new_buffer->from_stage3 = from_stage3;
+ new_buffer->prev = pfile->buffer;
+ new_buffer->need_line = true;
- pfile->buffer = new;
+ pfile->buffer = new_buffer;
- return new;
+ return new_buffer;
}
/* Pops a single buffer, with a file change call-back if appropriate.
Index: libcpp/expr.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/expr.c,v
retrieving revision 1.2
diff -u -r1.2 expr.c
--- libcpp/expr.c 4 Jul 2004 12:57:46 -0000 1.2
+++ libcpp/expr.c 24 May 2005 03:13:16 -0000
@@ -65,8 +65,8 @@
static void check_promotion (cpp_reader *, const struct op *);
/* Token type abuse to create unary plus and minus operators. */
-#define CPP_UPLUS (CPP_LAST_CPP_OP + 1)
-#define CPP_UMINUS (CPP_LAST_CPP_OP + 2)
+#define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
+#define CPP_UMINUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 2))
/* With -O2, gcc appears to produce nice code, moving the error
message load and subsequent jump completely out of the main path. */
@@ -627,7 +627,7 @@
/* Operator to priority map. Must be in the same order as the first
N entries of enum cpp_ttype. */
-static const struct operator
+static const struct cpp_operator
{
uchar prio;
uchar flags;
@@ -975,7 +975,7 @@
size_t old_size = (size_t) (pfile->op_limit - pfile->op_stack);
size_t new_size = old_size * 2 + 20;
- pfile->op_stack = xrealloc (pfile->op_stack, new_size * sizeof (struct op));
+ pfile->op_stack = XRESIZEVEC (struct op, pfile->op_stack, new_size);
pfile->op_limit = pfile->op_stack + new_size;
return pfile->op_stack + old_size;
Index: libcpp/files.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/files.c,v
retrieving revision 1.10
diff -u -r1.10 files.c
--- libcpp/files.c 28 Apr 2005 02:38:59 -0000 1.10
+++ libcpp/files.c 24 May 2005 03:13:16 -0000
@@ -255,7 +255,7 @@
flen = strlen (path);
len = flen + sizeof (extension);
- pchname = xmalloc (len);
+ pchname = XNEWVEC (char, len);
memcpy (pchname, path, flen);
memcpy (pchname + flen, extension, sizeof (extension));
@@ -279,7 +279,7 @@
if (dlen + plen > len)
{
len += dlen + 64;
- pchname = xrealloc (pchname, len);
+ pchname = XRESIZEVEC (char, pchname, len);
}
memcpy (pchname + plen, d->d_name, dlen);
valid = validate_pch (pfile, file, pchname);
@@ -549,7 +549,7 @@
the majority of C source files. */
size = 8 * 1024;
- buf = xmalloc (size + 1);
+ buf = XNEWVEC (uchar, size + 1);
total = 0;
while ((count = read (file->fd, buf + total, size - total)) > 0)
{
@@ -560,7 +560,7 @@
if (regular)
break;
size *= 2;
- buf = xrealloc (buf, size + 1);
+ buf = XRESIZEVEC (uchar, buf, size + 1);
}
}
@@ -815,7 +815,7 @@
if (!file->dir_name)
{
size_t len = lbasename (file->path) - file->path;
- char *dir_name = xmalloc (len + 1);
+ char *dir_name = XNEWVEC (char, len + 1);
memcpy (dir_name, file->path, len);
dir_name[len] = '\0';
@@ -896,7 +896,7 @@
{
_cpp_file *file;
- file = xcalloc (1, sizeof (_cpp_file));
+ file = XCNEW (_cpp_file);
file->main_file = !pfile->buffer;
file->fd = -1;
file->dir = dir;
@@ -938,7 +938,7 @@
if (entry->start_dir == NULL)
return entry->u.dir;
- dir = xcalloc (1, sizeof (cpp_dir));
+ dir = XCNEW (cpp_dir);
dir->next = pfile->quote_include;
dir->name = (char *) dir_name;
dir->len = strlen (dir_name);
@@ -961,8 +961,8 @@
{
pfile->file_hash_entries_used = 0;
pfile->file_hash_entries_allocated = 127;
- pfile->file_hash_entries = xmalloc
- (pfile->file_hash_entries_allocated * sizeof (struct file_hash_entry));
+ pfile->file_hash_entries = XNEWVEC (struct file_hash_entry,
+ pfile->file_hash_entries_allocated);
}
/* Return a new file hash entry. */
@@ -983,8 +983,8 @@
{
struct file_hash_entry *entry;
- entry = htab_find_with_hash (pfile->file_hash, fname,
- htab_hash_string (fname));
+ entry = (struct file_hash_entry *)
+ htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
while (entry && (entry->start_dir == NULL || entry->u.file->err_no))
entry = entry->next;
@@ -1204,7 +1204,7 @@
dlen = dir->len;
flen = strlen (fname);
- path = xmalloc (dlen + 1 + flen + 1);
+ path = XNEWVEC (char, dlen + 1 + flen + 1);
memcpy (path, dir->name, dlen);
if (dlen && path[dlen - 1] != '/')
path[dlen++] = '/';
@@ -1222,7 +1222,7 @@
int len;
len = 20;
- set = alloc = xmalloc (len + 1);
+ set = alloc = XNEWVEC (char, len + 1);
if (! is_space (ch))
{
*set++ = ch;
@@ -1231,7 +1231,7 @@
if (set - alloc == len)
{
len *= 2;
- alloc = xrealloc (alloc, len + 1);
+ alloc = XRESIZEVEC (char, alloc, len + 1);
set = alloc + len / 2;
}
*set++ = ch;
@@ -1252,14 +1252,14 @@
size_t len, count = 0, room = 9;
len = dir->len;
- name = alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1);
+ name = (char *) alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1);
memcpy (name, dir->name, len);
if (len && name[len - 1] != '/')
name[len++] = '/';
strcpy (name + len, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
- dir->name_map = xmalloc (room * sizeof (char *));
+ dir->name_map = XNEWVEC (const char *, room);
/* Silently return NULL if we cannot open. */
if (f)
@@ -1276,7 +1276,7 @@
if (count + 2 > room)
{
room += 8;
- dir->name_map = xrealloc (dir->name_map, room * sizeof (char *));
+ dir->name_map = XRESIZEVEC (const char *, dir->name_map, room);
}
dir->name_map[count] = read_filename_string (ch, f);
@@ -1333,7 +1333,7 @@
return NULL;
len = dir->len + (p - fname + 1);
- new_dir = xmalloc (len + 1);
+ new_dir = XNEWVEC (char, len + 1);
memcpy (new_dir, dir->name, dir->len);
memcpy (new_dir + dir->len, fname, p - fname + 1);
new_dir[len] = '\0';
@@ -1426,6 +1426,16 @@
that's OK. The code does rely on having entries with the same size
next to each other. */
+struct pchf_entry {
+ /* The size of this file. This is used to save running a MD5 checksum
+ if the sizes don't match. */
+ off_t size;
+ /* The MD5 checksum of this file. */
+ unsigned char sum[16];
+ /* Is this file to be included only once? */
+ bool once_only;
+};
+
struct pchf_data {
/* Number of pchf_entry structures. */
size_t count;
@@ -1435,15 +1445,7 @@
the structure if we're processing a regular #include. */
bool have_once_only;
- struct pchf_entry {
- /* The size of this file. This is used to save running a MD5 checksum
- if the sizes don't match. */
- off_t size;
- /* The MD5 checksum of this file. */
- unsigned char sum[16];
- /* Is this file to be included only once? */
- bool once_only;
- } entries[1];
+ struct pchf_entry entries[1];
};
static struct pchf_data *pchf;
@@ -1471,7 +1473,7 @@
result_size = (sizeof (struct pchf_data)
+ sizeof (struct pchf_entry) * (count - 1));
- result = xcalloc (result_size, 1);
+ result = XCNEWVAR (struct pchf_data, result_size);
result->count = 0;
result->have_once_only = false;
@@ -1534,7 +1536,7 @@
!= 1)
return false;
- pchf = xmalloc (sizeof (struct pchf_data)
+ pchf = XNEWVAR (struct pchf_data, sizeof (struct pchf_data)
+ sizeof (struct pchf_entry) * (d.count - 1));
memcpy (pchf, &d, sizeof (struct pchf_data) - sizeof (struct pchf_entry));
if (fread (pchf->entries, sizeof (struct pchf_entry), d.count, f)
Index: libcpp/identifiers.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/identifiers.c,v
retrieving revision 1.1
diff -u -r1.1 identifiers.c
--- libcpp/identifiers.c 24 May 2004 10:50:44 -0000 1.1
+++ libcpp/identifiers.c 24 May 2005 03:13:16 -0000
@@ -37,7 +37,7 @@
{
cpp_hashnode *node;
- node = obstack_alloc (&table->pfile->hash_ob, sizeof (cpp_hashnode));
+ node = XOBNEW (&table->pfile->hash_ob, cpp_hashnode);
memset (node, 0, sizeof (cpp_hashnode));
return node;
}
Index: libcpp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/init.c,v
retrieving revision 1.8
diff -u -r1.8 init.c
--- libcpp/init.c 15 Mar 2005 00:36:32 -0000 1.8
+++ libcpp/init.c 24 May 2005 03:13:16 -0000
@@ -137,7 +137,7 @@
/* Initialize this instance of the library if it hasn't been already. */
init_library ();
- pfile = xcalloc (1, sizeof (cpp_reader));
+ pfile = XCNEW (cpp_reader);
cpp_set_lang (pfile, lang);
CPP_OPTION (pfile, warn_multichar) = 1;
@@ -357,7 +357,7 @@
cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
hp->type = NT_MACRO;
hp->flags |= NODE_BUILTIN | NODE_WARN;
- hp->value.builtin = b->value;
+ hp->value.builtin = (enum builtin_type) b->value;
}
if (CPP_OPTION (pfile, cplusplus))
@@ -545,7 +545,7 @@
if (pfile->cb.dir_change)
{
- char *debugdir = alloca (token->val.str.len - 3);
+ char *debugdir = (char *) alloca (token->val.str.len - 3);
memcpy (debugdir, (const char *) token->val.str.text + 1,
token->val.str.len - 4);
Index: libcpp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/lex.c,v
retrieving revision 1.9
diff -u -r1.9 lex.c
--- libcpp/lex.c 28 Mar 2005 06:55:47 -0000 1.9
+++ libcpp/lex.c 24 May 2005 03:13:16 -0000
@@ -85,8 +85,8 @@
if (buffer->notes_used == buffer->notes_cap)
{
buffer->notes_cap = buffer->notes_cap * 2 + 200;
- buffer->notes = xrealloc (buffer->notes,
- buffer->notes_cap * sizeof (_cpp_line_note));
+ buffer->notes = XRESIZEVEC (_cpp_line_note, buffer->notes,
+ buffer->notes_cap);
}
buffer->notes[buffer->notes_used].pos = pos;
@@ -439,7 +439,7 @@
{
/* Make sure that the token is printed using UCNs, even
if we'd otherwise happily print UTF-8. */
- unsigned char *buf = xmalloc (cpp_token_len (token));
+ unsigned char *buf = XNEWVEC (unsigned char, cpp_token_len (token));
size_t sz;
sz = cpp_spell_token (pfile, token, buf, false) - buf;
@@ -970,7 +970,7 @@
if (result->val.node->flags & NODE_OPERATOR)
{
result->flags |= NAMED_OP;
- result->type = result->val.node->directive_index;
+ result->type = (enum cpp_ttype) result->val.node->directive_index;
}
break;
@@ -1541,7 +1541,7 @@
len = MIN_BUFF_SIZE;
len = CPP_ALIGN (len);
- base = xmalloc (len + sizeof (_cpp_buff));
+ base = XNEWVEC (unsigned char, len + sizeof (_cpp_buff));
result = (_cpp_buff *) (base + len);
result->base = base;
result->cur = base;
Index: libcpp/line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/line-map.c,v
retrieving revision 1.2
diff -u -r1.2 line-map.c
--- libcpp/line-map.c 21 Apr 2005 17:08:27 -0000 1.2
+++ libcpp/line-map.c 24 May 2005 03:13:17 -0000
@@ -97,7 +97,7 @@
if (set->used == set->allocated)
{
set->allocated = 2 * set->allocated + 256;
- set->maps = xrealloc (set->maps, set->allocated * sizeof (struct line_map));
+ set->maps = XRESIZEVEC (struct line_map, set->maps, set->allocated);
}
map = &set->maps[set->used];
Index: libcpp/macro.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/macro.c,v
retrieving revision 1.12
diff -u -r1.12 macro.c
--- libcpp/macro.c 5 Apr 2005 20:07:05 -0000 1.12
+++ libcpp/macro.c 24 May 2005 03:13:17 -0000
@@ -273,7 +273,7 @@
buf = _cpp_builtin_macro_text (pfile, node);
len = ustrlen (buf);
- nbuf = alloca (len + 1);
+ nbuf = (char *) alloca (len + 1);
memcpy (nbuf, buf, len);
nbuf[len]='\n';
@@ -421,7 +421,7 @@
lhs = *plhs;
len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
- buf = alloca (len);
+ buf = (unsigned char *) alloca (len);
end = cpp_spell_token (pfile, lhs, buf, false);
/* Avoid comment headers, since they are still processed in stage 3.
@@ -1001,7 +1001,7 @@
/* Loop, reading in the arguments. */
capacity = 256;
- arg->expanded = xmalloc (capacity * sizeof (cpp_token *));
+ arg->expanded = XNEWVEC (const cpp_token *, capacity);
push_ptoken_context (pfile, NULL, NULL, arg->first, arg->count + 1);
for (;;)
@@ -1011,8 +1011,8 @@
if (arg->expanded_count + 1 >= capacity)
{
capacity *= 2;
- arg->expanded = xrealloc (arg->expanded,
- capacity * sizeof (cpp_token *));
+ arg->expanded = XRESIZEVEC (const cpp_token *, arg->expanded,
+ capacity);
}
token = cpp_get_token (pfile);
@@ -1272,7 +1272,8 @@
len = macro->paramc * sizeof (union _cpp_hashnode_value);
if (len > pfile->macro_buffer_len)
{
- pfile->macro_buffer = xrealloc (pfile->macro_buffer, len);
+ pfile->macro_buffer = XRESIZEVEC (unsigned char, pfile->macro_buffer,
+ len);
pfile->macro_buffer_len = len;
}
((union _cpp_hashnode_value *) pfile->macro_buffer)[macro->paramc - 1]
@@ -1419,8 +1420,9 @@
/* Success. Commit or allocate the parameter array. */
if (pfile->hash_table->alloc_subobject)
{
- cpp_hashnode **params = pfile->hash_table->alloc_subobject
- (sizeof (cpp_hashnode *) * macro->paramc);
+ cpp_hashnode **params =
+ (cpp_hashnode **) pfile->hash_table->alloc_subobject
+ (sizeof (cpp_hashnode *) * macro->paramc);
memcpy (params, macro->params,
sizeof (cpp_hashnode *) * macro->paramc);
macro->params = params;
@@ -1532,8 +1534,9 @@
/* Commit or allocate the memory. */
if (pfile->hash_table->alloc_subobject)
{
- cpp_token *tokns = pfile->hash_table->alloc_subobject (sizeof (cpp_token)
- * macro->count);
+ cpp_token *tokns =
+ (cpp_token *) pfile->hash_table->alloc_subobject (sizeof (cpp_token)
+ * macro->count);
memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count);
macro->exp.tokens = tokns;
}
@@ -1552,7 +1555,8 @@
bool ok;
if (pfile->hash_table->alloc_subobject)
- macro = pfile->hash_table->alloc_subobject (sizeof (cpp_macro));
+ macro = (cpp_macro *) pfile->hash_table->alloc_subobject
+ (sizeof (cpp_macro));
else
macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
macro->line = pfile->directive_line;
@@ -1722,7 +1726,8 @@
if (len > pfile->macro_buffer_len)
{
- pfile->macro_buffer = xrealloc (pfile->macro_buffer, len);
+ pfile->macro_buffer = XRESIZEVEC (unsigned char,
+ pfile->macro_buffer, len);
pfile->macro_buffer_len = len;
}
Index: libcpp/makedepend.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/makedepend.c,v
retrieving revision 1.3
diff -u -r1.3 makedepend.c
--- libcpp/makedepend.c 11 Oct 2004 05:29:17 -0000 1.3
+++ libcpp/makedepend.c 24 May 2005 03:13:17 -0000
@@ -47,7 +47,7 @@
static void
add_clm (const char *macro, bool is_undef)
{
- struct cmd_line_macro *clm = xmalloc (sizeof (struct cmd_line_macro));
+ struct cmd_line_macro *clm = XNEW (struct cmd_line_macro);
clm->next = cmd_line_macros;
clm->is_undef = is_undef;
clm->macro = macro;
@@ -57,7 +57,7 @@
static void
add_dir (char *name, bool sysp)
{
- cpp_dir *dir = xmalloc (sizeof (cpp_dir));
+ cpp_dir *dir = XNEW (cpp_dir);
dir->next = cmd_line_searchpath;
dir->name = name;
dir->sysp = sysp;
Index: libcpp/mkdeps.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/mkdeps.c,v
retrieving revision 1.2
diff -u -r1.2 mkdeps.c
--- libcpp/mkdeps.c 5 Jun 2004 20:57:58 -0000 1.2
+++ libcpp/mkdeps.c 24 May 2005 03:13:17 -0000
@@ -83,7 +83,7 @@
}
/* Now we know how big to make the buffer. */
- buffer = xmalloc (len + 1);
+ buffer = XNEWVEC (char, len + 1);
for (p = filename, dst = buffer; *p; p++, dst++)
{
@@ -151,7 +151,7 @@
struct deps *
deps_init (void)
{
- return xcalloc (sizeof (struct deps), 1);
+ return XCNEW (struct deps);
}
void
@@ -192,8 +192,7 @@
if (d->ntargets == d->targets_size)
{
d->targets_size = d->targets_size * 2 + 4;
- d->targetv = xrealloc (d->targetv,
- d->targets_size * sizeof (const char *));
+ d->targetv = XRESIZEVEC (const char *, d->targetv, d->targets_size);
}
t = apply_vpath (d, t);
@@ -223,7 +222,8 @@
# define TARGET_OBJECT_SUFFIX ".o"
#endif
const char *start = lbasename (tgt);
- char *o = alloca (strlen (start) + strlen (TARGET_OBJECT_SUFFIX) + 1);
+ char *o = (char *) alloca (strlen (start)
+ + strlen (TARGET_OBJECT_SUFFIX) + 1);
char *suffix;
strcpy (o, start);
@@ -245,7 +245,7 @@
if (d->ndeps == d->deps_size)
{
d->deps_size = d->deps_size * 2 + 8;
- d->depv = xrealloc (d->depv, d->deps_size * sizeof (const char *));
+ d->depv = XRESIZEVEC (const char *, d->depv, d->deps_size);
}
d->depv[d->ndeps++] = t;
}
@@ -261,7 +261,7 @@
{
for (p = elem; *p && *p != ':'; p++);
len = p - elem;
- copy = xmalloc (len + 1);
+ copy = XNEWVEC (char, len + 1);
memcpy (copy, elem, len);
copy[len] = '\0';
if (*p == ':')
@@ -270,9 +270,8 @@
if (d->nvpaths == d->vpaths_size)
{
d->vpaths_size = d->vpaths_size * 2 + 8;
- d->vpathv = xrealloc (d->vpathv,
- d->vpaths_size * sizeof (const char *));
- d->vpathlv = xrealloc (d->vpathlv, d->vpaths_size * sizeof (size_t));
+ d->vpathv = XRESIZEVEC (const char *, d->vpathv, d->vpaths_size);
+ d->vpathlv = XRESIZEVEC (size_t, d->vpathlv, d->vpaths_size);
}
d->vpathv[d->nvpaths] = copy;
d->vpathlv[d->nvpaths] = len;
@@ -382,7 +381,7 @@
unsigned int i, count;
size_t num_to_read;
size_t buf_size = 512;
- char *buf = xmalloc (buf_size);
+ char *buf = XNEWVEC (char, buf_size);
/* Number of dependences. */
if (fread (&count, 1, sizeof (count), fd) != sizeof (count))
@@ -397,7 +396,7 @@
if (buf_size < num_to_read + 1)
{
buf_size = num_to_read + 1 + 127;
- buf = xrealloc (buf, buf_size);
+ buf = XRESIZEVEC (char, buf, buf_size);
}
if (fread (buf, 1, num_to_read, fd) != num_to_read)
return -1;
Index: libcpp/pch.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/pch.c,v
retrieving revision 1.6
diff -u -r1.6 pch.c
--- libcpp/pch.c 14 Feb 2005 14:43:56 -0000 1.6
+++ libcpp/pch.c 24 May 2005 03:13:17 -0000
@@ -137,11 +137,11 @@
struct cpp_string *sp;
unsigned char *text;
- sp = xmalloc (sizeof (struct cpp_string));
+ sp = XNEW (struct cpp_string);
*slot = sp;
sp->len = NODE_LEN (hn);
- sp->text = text = xmalloc (NODE_LEN (hn));
+ sp->text = text = XNEWVEC (unsigned char, NODE_LEN (hn));
memcpy (text, NODE_NAME (hn), NODE_LEN (hn));
}
}
@@ -193,7 +193,7 @@
cpp_save_state (cpp_reader *r, FILE *f)
{
/* Save the list of non-void identifiers for the dependency checking. */
- r->savedstate = xmalloc (sizeof (struct cpp_savedstate));
+ r->savedstate = XNEW (struct cpp_savedstate);
r->savedstate->definedhash = htab_create (100, cpp_string_hash,
cpp_string_eq, NULL);
cpp_forall_identifiers (r, save_idents, r->savedstate);
@@ -226,7 +226,7 @@
news.len = NODE_LEN (hn);
news.text = NODE_NAME (hn);
- slot = htab_find (ss->definedhash, &news);
+ slot = (void **) htab_find (ss->definedhash, &news);
if (slot == NULL)
{
ss->hashsize += NODE_LEN (hn) + 1;
@@ -265,7 +265,7 @@
news.len = NODE_LEN (hn);
news.text = NODE_NAME (hn);
- slot = htab_find (ss->definedhash, &news);
+ slot = (void **) htab_find (ss->definedhash, &news);
if (slot == NULL)
{
ss->defs[ss->n_defs] = hn;
@@ -310,13 +310,13 @@
ss->n_defs = 0;
cpp_forall_identifiers (r, count_defs, ss);
- ss->defs = xmalloc (ss->n_defs * sizeof (cpp_hashnode *));
+ ss->defs = XNEWVEC (cpp_hashnode *, ss->n_defs);
ss->n_defs = 0;
cpp_forall_identifiers (r, write_defs, ss);
/* Sort the list, copy it into a buffer, and write it out. */
qsort (ss->defs, ss->n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
- definedstrs = ss->definedstrs = xmalloc (ss->hashsize);
+ definedstrs = ss->definedstrs = XNEWVEC (unsigned char, ss->hashsize);
for (i = 0; i < ss->n_defs; ++i)
{
size_t len = NODE_LEN (ss->defs[i]);
@@ -390,7 +390,7 @@
if (nl->n_defs == nl->asize)
{
nl->asize *= 2;
- nl->defs = xrealloc (nl->defs, nl->asize * sizeof (cpp_hashnode *));
+ nl->defs = XRESIZEVEC (cpp_hashnode *, nl->defs, nl->asize);
}
nl->defs[nl->n_defs] = hn;
@@ -418,7 +418,7 @@
{
struct macrodef_struct m;
size_t namebufsz = 256;
- unsigned char *namebuf = xmalloc (namebufsz);
+ unsigned char *namebuf = XNEWVEC (unsigned char, namebufsz);
unsigned char *undeftab = NULL;
struct ht_node_list nl = { 0, 0, 0 };
unsigned char *first, *last;
@@ -450,7 +450,7 @@
{
free (namebuf);
namebufsz = m.definition_length + 256;
- namebuf = xmalloc (namebufsz);
+ namebuf = XNEWVEC (unsigned char, namebufsz);
}
if ((size_t)read (fd, namebuf, m.definition_length)
@@ -488,14 +488,14 @@
/* Read in the list of identifiers that must not be defined.
Check that they really aren't. */
- undeftab = xmalloc (m.definition_length);
+ undeftab = XNEWVEC (unsigned char, m.definition_length);
if ((size_t) read (fd, undeftab, m.definition_length) != m.definition_length)
goto error;
/* Collect identifiers from the current hash table. */
nl.n_defs = 0;
nl.asize = 10;
- nl.defs = xmalloc (nl.asize * sizeof (cpp_hashnode *));
+ nl.defs = XNEWVEC (cpp_hashnode *, nl.asize);
cpp_forall_identifiers (r, &collect_ht_nodes, &nl);
qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
@@ -577,8 +577,7 @@
if (data->count == data->array_size)
{
data->array_size *= 2;
- data->defns = xrealloc (data->defns, (data->array_size
- * sizeof (uchar *)));
+ data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
}
switch (h->type)
@@ -592,7 +591,8 @@
const uchar * defn = cpp_macro_definition (r, h);
size_t defnlen = ustrlen (defn);
- data->defns[data->count] = xmemdup (defn, defnlen, defnlen + 2);
+ data->defns[data->count] = (uchar *) xmemdup (defn, defnlen,
+ defnlen + 2);
data->defns[data->count][defnlen] = '\n';
}
break;
@@ -611,10 +611,10 @@
void
cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
{
- struct save_macro_data *d = xmalloc (sizeof (struct save_macro_data));
+ struct save_macro_data *d = XNEW (struct save_macro_data);
d->array_size = 512;
- d->defns = xmalloc (d->array_size * sizeof (d->defns[0]));
+ d->defns = XNEWVEC (uchar *, d->array_size);
d->count = 0;
cpp_forall_identifiers (r, save_macros, d);
d->saved_pragmas = _cpp_save_pragma_names (r);
Index: libcpp/symtab.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/symtab.c,v
retrieving revision 1.4
diff -u -r1.4 symtab.c
--- libcpp/symtab.c 6 Sep 2004 13:22:48 -0000 1.4
+++ libcpp/symtab.c 24 May 2005 03:13:17 -0000
@@ -56,7 +56,7 @@
unsigned int nslots = 1 << order;
hash_table *table;
- table = xcalloc (1, sizeof (hash_table));
+ table = XCNEW (hash_table);
/* Strings need no alignment. */
_obstack_begin (&table->stack, 0, 0,
@@ -65,7 +65,7 @@
obstack_alignment_mask (&table->stack) = 0;
- table->entries = xcalloc (nslots, sizeof (hashnode));
+ table->entries = XCNEWVEC (hashnode, nslots);
table->entries_owned = true;
table->nslots = nslots;
return table;
@@ -161,7 +161,8 @@
HT_LEN (node) = (unsigned int) len;
node->hash_value = hash;
if (insert == HT_ALLOC)
- HT_STR (node) = obstack_copy0 (&table->stack, str, len);
+ HT_STR (node) = (const unsigned char *) obstack_copy0 (&table->stack,
+ str, len);
else
HT_STR (node) = str;
@@ -181,7 +182,7 @@
unsigned int size, sizemask;
size = table->nslots * 2;
- nentries = xcalloc (size, sizeof (hashnode));
+ nentries = XCNEWVEC (hashnode, size);
sizemask = size - 1;
p = table->entries;
Index: libcpp/system.h
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/system.h,v
retrieving revision 1.5
diff -u -r1.5 system.h
--- libcpp/system.h 19 Apr 2005 12:37:08 -0000 1.5
+++ libcpp/system.h 24 May 2005 03:13:17 -0000
@@ -342,10 +342,14 @@
#include "libiberty.h"
#include "safe-ctype.h"
-/* 1 if we have C99 designated initializers. */
+/* 1 if we have C99 designated initializers.
+
+ ??? C99 designated initializers are not supported by most C++
+ compilers, including G++. -- gdr, 2005-05-18 */
#if !defined(HAVE_DESIGNATED_INITIALIZERS)
#define HAVE_DESIGNATED_INITIALIZERS \
- ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
+ ((!defined(__cplusplus) && (GCC_VERSION >= 2007)) \
+ || (__STDC_VERSION__ >= 199901L))
#endif
/* Be conservative and only use enum bitfields with GCC.
@@ -379,7 +383,9 @@
#undef TRUE
#undef FALSE
+#ifndef __cplusplus
#define bool unsigned char
+#endif
#define true 1
#define false 0
Index: libcpp/traditional.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/traditional.c,v
retrieving revision 1.4
diff -u -r1.4 traditional.c
--- libcpp/traditional.c 14 Feb 2005 14:43:56 -0000 1.4
+++ libcpp/traditional.c 24 May 2005 03:13:17 -0000
@@ -107,7 +107,7 @@
size_t size = pfile->out.cur - pfile->out.base;
size_t new_size = (size + n) * 3 / 2;
- pfile->out.base = xrealloc (pfile->out.base, new_size);
+ pfile->out.base = XRESIZEVEC (unsigned char, pfile->out.base, new_size);
pfile->out.limit = pfile->out.base + new_size;
pfile->out.cur = pfile->out.base + size;
}
@@ -1069,7 +1069,7 @@
_cpp_expansions_different_trad (const cpp_macro *macro1,
const cpp_macro *macro2)
{
- uchar *p1 = xmalloc (macro1->count + macro2->count);
+ uchar *p1 = XNEWVEC (uchar, macro1->count + macro2->count);
uchar *p2 = p1 + macro1->count;
uchar quote1 = 0, quote2 = 0;
bool mismatch;
Index: libcpp/include/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/include/cpplib.h,v
retrieving revision 1.11
diff -u -r1.11 cpplib.h
--- libcpp/include/cpplib.h 15 Mar 2005 00:36:33 -0000 1.11
+++ libcpp/include/cpplib.h 24 May 2005 03:13:18 -0000
@@ -569,6 +569,19 @@
/* The common part of an identifier node shared amongst all 3 C front
ends. Also used to store CPP identifiers, which are a superset of
identifiers in the grammatical sense. */
+
+union _cpp_hashnode_value GTY(())
+{
+ /* If a macro. */
+ cpp_macro * GTY((tag ("NTV_MACRO"))) macro;
+ /* Answers to an assertion. */
+ struct answer * GTY ((tag ("NTV_ANSWER"))) answers;
+ /* Code for a builtin macro. */
+ enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin;
+ /* Macro argument index. */
+ unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index;
+};
+
struct cpp_hashnode GTY(())
{
struct ht_identifier ident;
@@ -580,17 +593,7 @@
ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */
unsigned char flags; /* CPP flags. */
- union _cpp_hashnode_value
- {
- /* If a macro. */
- cpp_macro * GTY((tag ("NTV_MACRO"))) macro;
- /* Answers to an assertion. */
- struct answer * GTY ((tag ("NTV_ANSWER"))) answers;
- /* Code for a builtin macro. */
- enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin;
- /* Macro argument index. */
- unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index;
- } GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value;
+ union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value;
};
/* Call this first to get a handle to pass to other functions.