aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog87
-rw-r--r--libcpp/charset.c24
-rw-r--r--libcpp/config.in8
-rwxr-xr-xlibcpp/configure140
-rw-r--r--libcpp/configure.ac3
-rw-r--r--libcpp/directives.c69
-rw-r--r--libcpp/expr.c8
-rw-r--r--libcpp/files.c60
-rw-r--r--libcpp/identifiers.c2
-rw-r--r--libcpp/include/cpplib.h25
-rw-r--r--libcpp/init.c6
-rw-r--r--libcpp/lex.c10
-rw-r--r--libcpp/line-map.c2
-rw-r--r--libcpp/macro.c29
-rw-r--r--libcpp/makedepend.c4
-rw-r--r--libcpp/mkdeps.c23
-rw-r--r--libcpp/pch.c34
-rw-r--r--libcpp/symtab.c9
-rw-r--r--libcpp/system.h10
-rw-r--r--libcpp/traditional.c4
20 files changed, 405 insertions, 152 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index c13a067..f4e8a5e 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,90 @@
+2005-05-28 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.
+
2005-05-12 Zack Weinberg <zack@codesourcery.com>
* directives.c (#sccs table entry): Mark IN_I, consistent with #ident.
diff --git a/libcpp/charset.c b/libcpp/charset.c
index ba53f63..f382d7f 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -486,7 +486,7 @@ conversion_loop (int (*const one_conversion)(iconv_t, const uchar **, size_t *,
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 @@ convert_no_conversion (iconv_t cd ATTRIBUTE_UNUSED,
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 @@ convert_using_iconv (iconv_t cd, const uchar *from, size_t flen,
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 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const char *from)
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 @@ cpp_host_to_exec_charset (cpp_reader *pfile, cppchar_t c)
/* 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 @@ emit_numeric_escape (cpp_reader *pfile, cppchar_t n,
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 @@ emit_numeric_escape (cpp_reader *pfile, cppchar_t n,
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 @@ cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count,
= 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 @@ cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count,
/* 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 @@ _cpp_interpret_identifier (cpp_reader *pfile, const uchar *id, size_t len)
{
/* 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 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
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 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
/* 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
diff --git a/libcpp/config.in b/libcpp/config.in
index a302492..2b05ba0 100644
--- a/libcpp/config.in
+++ b/libcpp/config.in
@@ -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
diff --git a/libcpp/configure b/libcpp/configure
index 6364745..d0c04d9 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -5077,6 +5077,76 @@ _ACEOF
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 @@ _ACEOF
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
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index b56a744..fe52964 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -50,7 +50,8 @@ define(libcpp_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked dnl
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
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 672415b..a768ea1 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -588,7 +588,7 @@ glue_header_name (cpp_reader *pfile)
/* 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 @@ glue_header_name (cpp_reader *pfile)
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 @@ parse_include (cpp_reader *pfile, int *pangle_brackets)
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 @@ insert_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain,
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 @@ save_registered_pragmas (struct pragma_entry *pe, char **sd)
{
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 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in)
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 @@ parse_assertion (cpp_reader *pfile, struct answer **answerp, int type)
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 @@ do_assert (cpp_reader *pfile)
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 @@ cpp_define (cpp_reader *pfile, const char *str)
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 @@ void
_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 @@ void
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 @@ handle_assertion (cpp_reader *pfile, const char *str, int type)
/* 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_buffer *
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.
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 4768918..73356a9 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -65,8 +65,8 @@ static unsigned int interpret_int_suffix (const uchar *, size_t);
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 @@ extra semantics need to be handled with operator-specific code. */
/* 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 @@ _cpp_expand_op_stack (cpp_reader *pfile)
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;
diff --git a/libcpp/files.c b/libcpp/files.c
index c0ce6d4..6cab34f 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -255,7 +255,7 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
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 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
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 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
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 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
if (regular)
break;
size *= 2;
- buf = xrealloc (buf, size + 1);
+ buf = XRESIZEVEC (uchar, buf, size + 1);
}
}
@@ -815,7 +815,7 @@ dir_name_of_file (_cpp_file *file)
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 @@ make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname)
{
_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 @@ make_cpp_dir (cpp_reader *pfile, const char *dir_name, int sysp)
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 @@ allocate_file_hash_entries (cpp_reader *pfile)
{
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 @@ cpp_included (cpp_reader *pfile, const char *fname)
{
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 @@ append_file_to_dir (const char *fname, cpp_dir *dir)
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 @@ read_filename_string (int ch, FILE *f)
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 @@ read_filename_string (int ch, FILE *f)
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 @@ read_name_map (cpp_dir *dir)
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 @@ read_name_map (cpp_dir *dir)
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 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)
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 @@ cpp_get_prev (cpp_buffer *b)
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 @@ struct pchf_data {
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 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
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 @@ _cpp_read_file_entries (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f)
!= 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)
diff --git a/libcpp/identifiers.c b/libcpp/identifiers.c
index a6b35b4..8ab3ce9 100644
--- a/libcpp/identifiers.c
+++ b/libcpp/identifiers.c
@@ -37,7 +37,7 @@ alloc_node (hash_table *table)
{
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;
}
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 321de40..3ec4c46 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -569,6 +569,19 @@ enum {
/* 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 @@ struct cpp_hashnode GTY(())
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.
diff --git a/libcpp/init.c b/libcpp/init.c
index 7ad5a73..56acd7a 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -137,7 +137,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
/* 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_init_builtins (cpp_reader *pfile, int hosted)
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 @@ read_original_directory (cpp_reader *pfile)
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);
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 58e559f..b38047e 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -85,8 +85,8 @@ add_line_note (cpp_buffer *buffer, const uchar *pos, unsigned int type)
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 @@ warn_about_normalization (cpp_reader *pfile,
{
/* 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 @@ _cpp_lex_direct (cpp_reader *pfile)
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 @@ new_buff (size_t len)
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;
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 1ace4c9..59a80ac 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -97,7 +97,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
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];
diff --git a/libcpp/macro.c b/libcpp/macro.c
index daa2bd3..05a8770 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -273,7 +273,7 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
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 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
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 @@ expand_arg (cpp_reader *pfile, macro_arg *arg)
/* 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 @@ expand_arg (cpp_reader *pfile, macro_arg *arg)
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 @@ _cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node)
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 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
/* 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 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
/* 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 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
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 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
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;
}
diff --git a/libcpp/makedepend.c b/libcpp/makedepend.c
index f28f969..7581c97 100644
--- a/libcpp/makedepend.c
+++ b/libcpp/makedepend.c
@@ -47,7 +47,7 @@ static cpp_dir *cmd_line_searchpath;
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 @@ add_clm (const char *macro, bool is_undef)
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;
diff --git a/libcpp/mkdeps.c b/libcpp/mkdeps.c
index 5ab8813..9042316 100644
--- a/libcpp/mkdeps.c
+++ b/libcpp/mkdeps.c
@@ -83,7 +83,7 @@ munge (const char *filename)
}
/* 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 @@ apply_vpath (struct deps *d, const char *t)
struct deps *
deps_init (void)
{
- return xcalloc (sizeof (struct deps), 1);
+ return XCNEW (struct deps);
}
void
@@ -192,8 +192,7 @@ deps_add_target (struct deps *d, const char *t, int quote)
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 @@ deps_add_default_target (struct deps *d, const char *tgt)
# 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 @@ deps_add_dep (struct deps *d, const char *t)
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 @@ deps_add_vpath (struct deps *d, const char *vpath)
{
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 @@ deps_add_vpath (struct deps *d, const char *vpath)
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 @@ deps_restore (struct deps *deps, FILE *fd, const char *self)
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 @@ deps_restore (struct deps *deps, FILE *fd, const char *self)
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;
diff --git a/libcpp/pch.c b/libcpp/pch.c
index 79900c3..28cafbc 100644
--- a/libcpp/pch.c
+++ b/libcpp/pch.c
@@ -137,11 +137,11 @@ save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
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 @@ int
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 @@ count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
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 @@ write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
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 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f)
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 @@ collect_ht_nodes (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn,
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 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
{
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 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
{
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 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
/* 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 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
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 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
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 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
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);
diff --git a/libcpp/symtab.c b/libcpp/symtab.c
index 471765c..8545010 100644
--- a/libcpp/symtab.c
+++ b/libcpp/symtab.c
@@ -56,7 +56,7 @@ ht_create (unsigned int order)
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 @@ ht_create (unsigned int order)
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_lookup_with_hash (hash_table *table, const unsigned char *str,
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 @@ ht_expand (hash_table *table)
unsigned int size, sizemask;
size = table->nslots * 2;
- nentries = xcalloc (size, sizeof (hashnode));
+ nentries = XCNEWVEC (hashnode, size);
sizemask = size - 1;
p = table->entries;
diff --git a/libcpp/system.h b/libcpp/system.h
index 98ac118..b27995b 100644
--- a/libcpp/system.h
+++ b/libcpp/system.h
@@ -342,10 +342,14 @@ extern void abort (void);
#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 @@ extern void abort (void);
#undef TRUE
#undef FALSE
+#ifndef __cplusplus
#define bool unsigned char
+#endif
#define true 1
#define false 0
diff --git a/libcpp/traditional.c b/libcpp/traditional.c
index 85be487..a20facb 100644
--- a/libcpp/traditional.c
+++ b/libcpp/traditional.c
@@ -107,7 +107,7 @@ check_output_buffer (cpp_reader *pfile, size_t n)
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 @@ bool
_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;