PATCH cpplib code cleanup v3
Jeff Garzik
garzik@havoc.gtf.org
Tue Sep 7 12:47:00 GMT 1999
This is the next iteration of the cpplib code cleanup patch. Changes
from the previous patch are:
o removes changes applied by Kaveh G.
o adds xmemdup to save some code
o uses xcalloc to save some code
o takes into account comments from Zack W. on previous patch
1999-09-07 Jeff Garzik <jgarzik@pobox.com>
cpplib code cleanup version 3
* cppalloc.c (xmemdup): New function.
(xstrdup): Use xmemdup.
* cppexp.c: Clarify module header, removing reference to CCCP.
(cpp_parse_expr): Use xmemdup.
* cppfiles.c (include_hash): Replace explicit mem zero w/ xcalloc().
(redundant_include_p): Const-ify 'ilist' arg and associated 'l'
iterator.
(find_include_file): s/bcopy/memcpy/.
(read_name_map): Replace xmalloc+strcpy with xmemdup.
(remap_filename): s/bcopy/memcpy/.
(find_position): Const-ify 'limit' arg.
(initialize_input_buffer): Const-ify 'st' arg.
Zero pipe buffer with xcalloc for safety.
(deps_output): s/bcopy/memcpy/.
* cpphash.c (cpp_install): Likewise. Also zero hashnode for safety.
(collect_expansion): Use xcalloc to zero struct.
s/bcopy/memcpy/.
(macroexpand): Likewise.
(dump_definition): Const-ify local var 'r'.
s/unsigned char/U_CHAR/.
* cppinit.c (path_include): Const-ify 'list' arg and associated
'p' and 'q' iterators.
Use xstrdup instead of xmalloc+string build.
Use xmemdup instead of xmalloc+memcpy.
(base_name): Un-const-ify 'fname' arg. s/rindex/strrchr/.
(cpp_options_init): s/bzero/memset/.
(cpp_reader_init): Likewise. Also remove unused get_token ref.
(initialize_dependency_output): Replace xmalloc+memcpy with xmemdup.
Clear deps_buffer with xcalloc.
s/rindex/strrchr/.
(cpp_start_read): Replace xmalloc+memcpy with xmemdup.
Zero 'ih_fake' with xcalloc instead of manually.
(cpp_handle_option): Use s/xmalloc/xcalloc/ for safety and to eliminate
manual initialization.
s/xmalloc+memcpy/xmemdup/.
* cpplib.c (null_underflow): Remove, unused.
(check_macro_name): s/bcopy/memcpy/.
(do_define): Likewise.
(cpp_push_buffer): Correct order of xcalloc args.
Remove init of unused 'underflow' member.
(cpp_buf_line_and_col): Const-ify 'pbuf' arg.
(do_include): s/unsigned char/U_CHAR/.
(do_undef): s/bcopy/memcpy/.
(do_pragma): Likewise.
(do_xifdef): Replace xmalloc+bcopy with xmemdup.
(consider_directive_while_skipping): xcalloc for safety.
(cpp_get_token): s/bcopy/memcpy/. s/unsigned char/U_CHAR/.
(cpp_unassert): s/unsigned char/U_CHAR/.
* cpplib.h: Update/correct prototypes to reflect reality.
(parse_underflow_t): Remove unused type.
(struct cpp_buffer): s/unsigned char/U_CHAR/.
Remove unused 'underflow' member.
(struct cpp_reader): s/unsigned char/U_CHAR/.
Remove unused 'get_token' member.
(struct macrodef): s/unsigned char/U_CHAR/.
(struct definition): Likewise.
(is_idstart, is_idchar, is_hor_space, is_space, trigraph_table):
s/unsigned char/U_CHAR/.
(struct if_stack): Format comments. s/unsigned char/U_CHAR/.
Index: cppalloc.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cppalloc.c,v
retrieving revision 1.16
diff -u -r1.16 cppalloc.c
--- cppalloc.c 1999/09/07 05:47:40 1.16
+++ cppalloc.c 1999/09/07 19:40:24
@@ -70,12 +70,23 @@
return ptr;
}
+PTR
+xmemdup (input, copy_size, alloc_size)
+ const PTR input;
+ size_t copy_size;
+ size_t alloc_size;
+{
+ PTR output = calloc (1, alloc_size);
+ if (output == NULL)
+ memory_full ();
+ memcpy (output, input, copy_size);
+ return output;
+}
+
char *
xstrdup (input)
const char *input;
{
- unsigned size = strlen (input);
- char *output = xmalloc (size + 1);
- strcpy (output, input);
- return output;
+ size_t size = strlen (input) + 1;
+ return (char *) xmemdup (input, size, size);
}
Index: cppexp.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cppexp.c,v
retrieving revision 1.25
diff -u -r1.25 cppexp.c
--- cppexp.c 1999/09/07 15:41:24 1.25
+++ cppexp.c 1999/09/07 19:40:25
@@ -1,4 +1,4 @@
-/* Parse C expressions for CCCP.
+/* Parse C pre-processor expressions for cpplib.
Copyright (C) 1987, 92, 94, 95, 97, 98, 1999 Free Software Foundation.
This program is free software; you can redistribute it and/or modify it
@@ -1028,10 +1028,7 @@
if (stack != init_stack)
new_stack = (struct operation *) xrealloc (stack, new_size);
else
- {
- new_stack = (struct operation *) xmalloc (new_size);
- bcopy ((char *) stack, (char *) new_stack, old_size);
- }
+ new_stack = (struct operation *) xmemdup (stack, old_size, new_size);
stack = new_stack;
top = (struct operation *) ((char *) new_stack + old_size);
limit = (struct operation *) ((char *) new_stack + new_size);
Index: cppfiles.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cppfiles.c,v
retrieving revision 1.26
diff -u -r1.26 cppfiles.c
--- cppfiles.c 1999/09/07 15:41:24 1.26
+++ cppfiles.c 1999/09/07 19:40:27
@@ -35,7 +35,7 @@
static struct include_hash *redundant_include_p
PROTO ((cpp_reader *,
struct include_hash *,
- struct file_name_list *));
+ const struct file_name_list *));
static struct file_name_map *read_name_map PROTO ((cpp_reader *,
const char *));
static char *read_filename_string PROTO ((int, FILE *));
@@ -46,7 +46,7 @@
static struct file_name_list *actual_directory PROTO ((cpp_reader *,
const char *));
static void initialize_input_buffer PROTO ((cpp_reader *, int,
- struct stat *));
+ const struct stat *));
static int file_cleanup PROTO ((cpp_buffer *, cpp_reader *));
static void find_position PROTO ((U_CHAR *, U_CHAR *,
unsigned long *,
@@ -222,12 +222,7 @@
if (!add)
return 0;
- l = (struct include_hash *) xmalloc (sizeof (struct include_hash));
- l->next = NULL;
- l->next_this_file = NULL;
- l->foundhere = NULL;
- l->buf = NULL;
- l->limit = NULL;
+ l = (struct include_hash *) xcalloc (1, sizeof (struct include_hash));
if (m)
m->next = l;
else
@@ -262,9 +257,9 @@
redundant_include_p (pfile, ihash, ilist)
cpp_reader *pfile;
struct include_hash *ihash;
- struct file_name_list *ilist;
+ const struct file_name_list *ilist;
{
- struct file_name_list *l;
+ const struct file_name_list *l;
struct include_hash *i;
if (! ihash->foundhere)
@@ -372,7 +367,7 @@
for (l = search_start; l; l = l->next)
{
- bcopy (l->name, name, l->nlen);
+ memcpy (name, l->name, l->nlen);
name[l->nlen] = '/';
strcpy (&name[l->nlen+1], fname);
simplify_pathname (name);
@@ -519,8 +514,8 @@
ptr->map_to = to;
else
{
- ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
- strcpy (ptr->map_to, dirname);
+ ptr->map_to = xmemdup (dirname, strlen (dirname) + 1,
+ dirlen + strlen (to) + 2);
ptr->map_to[dirlen] = '/';
strcpy (ptr->map_to + dirlen + 1, to);
free (to);
@@ -588,7 +583,7 @@
else
{
char * newdir = (char *) alloca (p - name + 1);
- bcopy (name, newdir, p - name);
+ memcpy (newdir, name, p - name);
newdir[p - name] = '\0';
dir = newdir;
from = p + 1;
@@ -773,8 +768,8 @@
/* Determine the current line and column. Used only by read_and_prescan. */
static void
find_position (start, limit, linep, colp)
- U_CHAR *start;
- U_CHAR *limit;
+ const U_CHAR *start;
+ const U_CHAR *limit;
unsigned long *linep;
unsigned long *colp;
{
@@ -1095,7 +1090,7 @@
initialize_input_buffer (pfile, fd, st)
cpp_reader *pfile;
int fd;
- struct stat *st;
+ const struct stat *st;
{
long pipe_buf;
U_CHAR *tmp;
@@ -1142,7 +1137,7 @@
the case there's a potential trigraph or end-of-line digraph at
the end of a block. */
- tmp = (U_CHAR *) xmalloc (pipe_buf + 2 + 2);
+ tmp = (U_CHAR *) xcalloc (1, pipe_buf + 2 + 2);
pfile->input_buffer = tmp;
pfile->input_buffer_len = pipe_buf;
}
@@ -1185,13 +1180,13 @@
if (cr)
{
- bcopy (" \\\n ", &pfile->deps_buffer[pfile->deps_size], 5);
+ memcpy (&pfile->deps_buffer[pfile->deps_size], " \\\n ", 5);
pfile->deps_size += 5;
}
if (spacer == ' ' && pfile->deps_column > 0)
pfile->deps_buffer[pfile->deps_size++] = ' ';
- bcopy (string, &pfile->deps_buffer[pfile->deps_size], size);
+ memcpy (&pfile->deps_buffer[pfile->deps_size], string, size);
pfile->deps_size += size;
pfile->deps_column += size;
if (spacer == ':')
Index: cpphash.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpphash.c,v
retrieving revision 1.25
diff -u -r1.25 cpphash.c
--- cpphash.c 1999/09/07 15:41:25 1.25
+++ cpphash.c 1999/09/07 19:40:29
@@ -233,7 +233,7 @@
hash = hashf (name, len, HASHSIZE);
i = sizeof (HASHNODE) + len + 1;
- hp = (HASHNODE *) xmalloc (i);
+ hp = (HASHNODE *) xcalloc (1, i);
bucket = hash;
hp->bucket_hdr = &pfile->hashtab[bucket];
hp->next = pfile->hashtab[bucket];
@@ -245,7 +245,7 @@
hp->length = len;
hp->value.cpval = value;
hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
- bcopy (name, hp->name, len);
+ memcpy (hp->name, name, len);
hp->name[len] = 0;
return hp;
}
@@ -503,10 +503,8 @@
/* make a pat node for this arg and append it
to the end of the pat list */
tpat = (struct reflist *)
- xmalloc (sizeof (struct reflist));
- tpat->next = NULL;
+ xcalloc (1, sizeof (struct reflist));
tpat->raw_before = concat == id_beg;
- tpat->raw_after = 0;
tpat->rest_args = arg->rest_args;
tpat->stringify = (CPP_TRADITIONAL (pfile)
? expected_delimiter != '\0'
@@ -720,7 +718,7 @@
int i = 0;
for (temp = arg_ptrs; temp; temp = temp->next)
{
- bcopy (temp->name, &defn->args.argnames[i], temp->length);
+ memcpy (&defn->args.argnames[i], temp->name, temp->length);
i += temp->length;
if (temp->next != 0)
{
@@ -1068,7 +1066,7 @@
xbuf_len = CPP_WRITTEN (pfile) - old_written;
xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
CPP_SET_WRITTEN (pfile, old_written);
- bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
+ memcpy (xbuf, CPP_PWRITTEN (pfile), xbuf_len + 1);
push_macro_expansion (pfile, xbuf, xbuf_len, hp);
CPP_BUFFER (pfile)->has_escapes = 1;
return;
@@ -1336,8 +1334,8 @@
if (ap->stringify != 0)
{
- bcopy (ARG_BASE + arg->stringified,
- xbuf + totlen, arg->stringified_length);
+ memcpy (xbuf + totlen, ARG_BASE + arg->stringified,
+ arg->stringified_length);
totlen += arg->stringified_length;
}
else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
@@ -1385,7 +1383,7 @@
if (p1[0] == '\r' && p1[1] == '-')
p1 += 2;
- bcopy (p1, xbuf + totlen, l1 - p1);
+ memcpy (xbuf + totlen, p1, l1 - p1);
totlen += l1 - p1;
}
else
@@ -1399,7 +1397,7 @@
xbuf[totlen++] = ' ';
}
- bcopy (expanded, xbuf + totlen, arg->expand_length);
+ memcpy (xbuf + totlen, expanded, arg->expand_length);
totlen += arg->expand_length;
if (!ap->raw_after && totlen > 0 && offset < defn->length
@@ -1679,12 +1677,11 @@
}
else
{
- struct reflist *r;
- unsigned char *argnames = (unsigned char *) xstrdup (defn->args.argnames);
- unsigned char **argv = (unsigned char **) alloca (defn->nargs *
- sizeof(char *));
+ const struct reflist *r;
+ U_CHAR *argnames = (U_CHAR *) xstrdup (defn->args.argnames);
+ U_CHAR **argv = (U_CHAR **) alloca (defn->nargs * sizeof(U_CHAR *));
int *argl = (int *) alloca (defn->nargs * sizeof(int));
- unsigned char *x;
+ U_CHAR *x;
int i;
/* First extract the argument list. */
Index: cppinit.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cppinit.c,v
retrieving revision 1.18
diff -u -r1.18 cppinit.c
--- cppinit.c 1999/09/07 15:41:25 1.18
+++ cppinit.c 1999/09/07 19:40:31
@@ -198,7 +198,7 @@
static void print_help PARAMS ((void));
static void path_include PARAMS ((cpp_reader *,
struct cpp_pending *,
- char *, int));
+ const char *, int));
static void initialize_builtins PARAMS ((cpp_reader *));
static void append_include_chain PARAMS ((cpp_reader *,
struct cpp_pending *,
@@ -386,10 +386,11 @@
path_include (pfile, pend, list, path)
cpp_reader *pfile;
struct cpp_pending *pend;
- char *list;
+ const char *list;
int path;
{
- char *p, *q, *name;
+ const char *p, *q;
+ char *name;
p = list;
@@ -401,15 +402,12 @@
if (q == p)
{
/* An empty name in the path stands for the current directory. */
- name = (char *) xmalloc (2);
- name[0] = '.';
- name[1] = 0;
+ name = xstrdup(".");
}
else
{
/* Otherwise use the directory that is named. */
- name = (char *) xmalloc (q - p + 1);
- memcpy (name, p, q - p);
+ name = (char *) xmemdup (p, q - p, q - p + 1);
name[q - p] = 0;
}
@@ -429,19 +427,19 @@
DOS and VMS paths on those systems. */
static char *
base_name (fname)
- const char *fname;
+ char *fname;
{
- char *s = (char *)fname;
+ char *s = fname;
char *p;
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
if (ISALPHA (s[0]) && s[1] == ':') s += 2;
- if ((p = rindex (s, '\\'))) s = p + 1;
+ if ((p = strrchr (s, '\\'))) s = p + 1;
#elif defined VMS
- if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
- if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
- if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
+ if ((p = strrchr (s, ':'))) s = p + 1; /* Skip device. */
+ if ((p = strrchr (s, ']'))) s = p + 1; /* Skip directory. */
+ if ((p = strrchr (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
#endif
- if ((p = rindex (s, '/'))) s = p + 1;
+ if ((p = strrchr (s, '/'))) s = p + 1;
return s;
}
@@ -522,7 +520,7 @@
cpp_options_init (opts)
cpp_options *opts;
{
- bzero ((char *) opts, sizeof (struct cpp_options));
+ memset (opts, 0, sizeof (struct cpp_options));
opts->dollars_in_ident = 1;
opts->cplusplus_comments = 1;
@@ -537,10 +535,7 @@
cpp_reader_init (pfile)
cpp_reader *pfile;
{
- bzero ((char *) pfile, sizeof (cpp_reader));
-#if 0
- pfile->get_token = cpp_get_token;
-#endif
+ memset (pfile, 0, sizeof (cpp_reader));
pfile->token_buffer_size = 200;
pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
@@ -698,8 +693,7 @@
if (s)
{
opts->deps_target = s + 1;
- output_file = (char *) xmalloc (s - spec + 1);
- memcpy (output_file, spec, s - spec);
+ output_file = (char *) xmemdup (spec, s - spec, s - spec + 1);
output_file[s - spec] = 0;
}
else
@@ -714,8 +708,7 @@
/* Print the expected object file name as the target of this Make-rule. */
pfile->deps_allocated_size = 200;
- pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
- pfile->deps_buffer[0] = 0;
+ pfile->deps_buffer = (char *) xcalloc (1, pfile->deps_allocated_size);
pfile->deps_size = 0;
pfile->deps_column = 0;
@@ -739,7 +732,7 @@
/* Output P, but remove known suffixes. */
q = p + len;
/* Point to the filename suffix. */
- r = rindex (p, '.');
+ r = strrchr (p, '.');
/* Compare against the known suffixes. */
for (x = 0; known_suffixes[x]; x++)
{
@@ -920,8 +913,8 @@
/* Yes; change prefix and add to search list. */
int flen = strlen (p->fname);
int this_len = specd_len + flen - default_len;
- char *str = (char *) xmalloc (this_len + 1);
- memcpy (str, specd_prefix, specd_len);
+ char *str = (char *) xmemdup (specd_prefix, specd_len,
+ this_len + 1);
memcpy (str + specd_len,
p->fname + default_len,
flen - default_len + 1);
@@ -986,14 +979,10 @@
/* Must call finclude() on the main input before processing
-include switches; otherwise the -included text winds up
after the main input. */
- ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
- ih_fake->next = 0;
- ih_fake->next_this_file = 0;
+ ih_fake = (struct include_hash *) xcalloc (1, sizeof (struct include_hash));
ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
ih_fake->name = fname;
- ih_fake->control_macro = 0;
ih_fake->buf = (char *)-1;
- ih_fake->limit = 0;
if (!finclude (pfile, f, ih_fake))
return 0;
if (opts->preprocessed)
@@ -1024,14 +1013,10 @@
return 0;
ih_fake = (struct include_hash *)
- xmalloc (sizeof (struct include_hash));
- ih_fake->next = 0;
- ih_fake->next_this_file = 0;
+ xcalloc (1, sizeof (struct include_hash));
ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
ih_fake->name = p->arg;
- ih_fake->control_macro = 0;
ih_fake->buf = (char *)-1;
- ih_fake->limit = 0;
if (finclude (pfile, fd, ih_fake))
{
if (CPP_PRINT_DEPS (pfile))
@@ -1063,14 +1048,10 @@
return 0;
ih_fake = (struct include_hash *)
- xmalloc (sizeof (struct include_hash));
- ih_fake->next = 0;
- ih_fake->next_this_file = 0;
+ xcalloc (1, sizeof (struct include_hash));
ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
ih_fake->name = p->arg;
- ih_fake->control_macro = 0;
ih_fake->buf = (char *)-1;
- ih_fake->limit = 0;
if (finclude (pfile, fd, ih_fake))
{
if (CPP_PRINT_DEPS (pfile))
@@ -1242,7 +1223,7 @@
else
{
struct pending_option *o = (struct pending_option *)
- xmalloc (sizeof (struct pending_option));
+ xcalloc (1, sizeof (struct pending_option));
o->arg = argv[++i];
/* This list has to be built in reverse order so that
@@ -1259,9 +1240,8 @@
else
{
struct pending_option *o = (struct pending_option *)
- xmalloc (sizeof (struct pending_option));
+ xcalloc (1, sizeof (struct pending_option));
o->arg = argv[++i];
- o->next = NULL;
APPEND (opts->pending, imacros, o);
}
@@ -1279,14 +1259,14 @@
if (opts->include_prefix != 0)
{
- fname = xmalloc (opts->include_prefix_len + len + 1);
- memcpy (fname, opts->include_prefix, opts->include_prefix_len);
+ fname = xmemdup (opts->include_prefix, opts->include_prefix_len,
+ opts->include_prefix_len + len + 1);
memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
}
else
{
- fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
- memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
+ fname = xmemdup (GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9,
+ sizeof GCC_INCLUDE_DIR - 8 + len);
memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
}
@@ -1305,14 +1285,14 @@
if (opts->include_prefix != 0)
{
- fname = xmalloc (opts->include_prefix_len + len + 1);
- memcpy (fname, opts->include_prefix, opts->include_prefix_len);
+ fname = xmemdup (opts->include_prefix, opts->include_prefix_len,
+ opts->include_prefix_len + len + 1);
memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
}
else
{
- fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
- memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
+ fname = xmemdup (GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9,
+ sizeof GCC_INCLUDE_DIR - 8 + len);
memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
}
@@ -1565,7 +1545,7 @@
case 'D':
{
struct pending_option *o = (struct pending_option *)
- xmalloc (sizeof (struct pending_option));
+ xcalloc (1, sizeof (struct pending_option));
if (argv[i][2] != 0)
o->arg = argv[i] + 2;
else if (i + 1 == argc)
@@ -1576,8 +1556,6 @@
else
o->arg = argv[++i];
- o->next = NULL;
- o->undef = 0;
APPEND (opts->pending, define, o);
}
break;
@@ -1599,11 +1577,9 @@
if (strcmp (p, "-"))
{
struct pending_option *o = (struct pending_option *)
- xmalloc (sizeof (struct pending_option));
+ xcalloc (1, sizeof (struct pending_option));
o->arg = p;
- o->next = NULL;
- o->undef = 0;
APPEND (opts->pending, assert, o);
}
else
@@ -1639,7 +1615,7 @@
case 'U':
{
struct pending_option *o = (struct pending_option *)
- xmalloc (sizeof (struct pending_option));
+ xcalloc (1, sizeof (struct pending_option));
if (argv[i][2] != 0)
o->arg = argv[i] + 2;
@@ -1651,7 +1627,6 @@
else
o->arg = argv[++i];
- o->next = NULL;
o->undef = 1;
APPEND (opts->pending, define, o);
}
Index: cpplib.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpplib.c,v
retrieving revision 1.90
diff -u -r1.90 cpplib.c
--- cpplib.c 1999/09/07 15:41:25 1.90
+++ cpplib.c 1999/09/07 19:40:34
@@ -86,7 +86,6 @@
static int do_assert PARAMS ((cpp_reader *, const struct directive *));
static int do_unassert PARAMS ((cpp_reader *, const struct directive *));
static int do_warning PARAMS ((cpp_reader *, const struct directive *));
-static enum cpp_token null_underflow PARAMS ((cpp_reader *));
static int null_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static int skip_comment PARAMS ((cpp_reader *, int));
static int copy_comment PARAMS ((cpp_reader *, int));
@@ -239,13 +238,6 @@
}
-static enum cpp_token
-null_underflow (pfile)
- cpp_reader *pfile ATTRIBUTE_UNUSED;
-{
- return CPP_EOF;
-}
-
static int
null_cleanup (pbuf, pfile)
cpp_buffer *pbuf ATTRIBUTE_UNUSED;
@@ -613,7 +605,7 @@
|| (! strncmp (symname, "defined", 7) && sym_length == 7)) {
U_CHAR *msg; /* what pain... */
msg = (U_CHAR *) alloca (sym_length + 1);
- bcopy (symname, msg, sym_length);
+ memcpy (msg, symname, sym_length);
msg[sym_length] = 0;
cpp_error (pfile,
(assertion
@@ -646,7 +638,7 @@
buf = pfile->token_buffer + here;
end = CPP_PWRITTEN (pfile);
macro = (U_CHAR *) alloca (end - buf + 1);
- bcopy (buf, macro, end - buf + 1);
+ memcpy (macro, buf, end - buf + 1);
end = macro + (end - buf);
CPP_SET_WRITTEN (pfile, here);
@@ -718,11 +710,10 @@
return NULL;
}
- new = (cpp_buffer *) xcalloc (sizeof (cpp_buffer), 1);
+ new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer));
new->if_stack = pfile->if_stack;
new->cleanup = null_cleanup;
- new->underflow = null_underflow;
new->buf = new->cur = buffer;
new->alimit = new->rlimit = buffer + length;
new->prev = buf;
@@ -839,7 +830,7 @@
void
cpp_buf_line_and_col (pbuf, linep, colp)
- register cpp_buffer *pbuf;
+ const cpp_buffer *pbuf;
long *linep, *colp;
{
if (pbuf)
@@ -996,7 +987,7 @@
int angle_brackets = 0; /* 0 for "...", 1 for <...> */
int before; /* included before? */
long flen;
- unsigned char *ftok;
+ U_CHAR *ftok;
cpp_buffer *fp;
enum cpp_token token;
@@ -1058,7 +1049,7 @@
}
flen = CPP_WRITTEN (pfile) - old_written;
- ftok = (unsigned char *) alloca (flen + 1);
+ ftok = (U_CHAR *) alloca (flen + 1);
memcpy (ftok, pfile->token_buffer + old_written, flen);
ftok[flen] = '\0';
@@ -1405,7 +1396,7 @@
/* Copy out the token so we can pop the token buffer. */
name = (U_CHAR *) alloca (limit - buf + 1);
- bcopy(buf, name, limit - buf);
+ memcpy (name, buf, limit - buf);
name[limit - buf] = '\0';
token = get_directive_token (pfile);
@@ -1570,7 +1561,7 @@
p = (U_CHAR *) index (fname, '\"');
fcopy = (U_CHAR *) alloca (p - fname + 1);
- bcopy (fname, fcopy, p - fname);
+ memcpy (fcopy, fname, p - fname);
fcopy[p-fname] = '\0';
ptr = include_hash (pfile, fcopy, 0);
@@ -1803,10 +1794,8 @@
HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
if (start_of_file && !skip)
- {
- control_macro = (U_CHAR *) xmalloc (ident_length + 1);
- bcopy (ident, control_macro, ident_length + 1);
- }
+ control_macro = (U_CHAR *) xmemdup (ident, ident_length + 1,
+ ident_length + 1);
}
else
{
@@ -1906,7 +1895,7 @@
case T_IF:
case T_IFDEF:
case T_IFNDEF:
- temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
+ temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp->next = pfile->if_stack;
pfile->if_stack = temp;
temp->fname = CPP_BUFFER(pfile)->nominal_fname;
@@ -2233,14 +2222,14 @@
if (lintcmd != NULL) {
/* I believe it is always safe to emit this newline: */
obp[-1] = '\n';
- bcopy ("#pragma lint ", (char *) obp, 13);
+ memcpy (obp, "#pragma lint ", 13);
obp += 13;
- bcopy (lintcmd, (char *) obp, cmdlen);
+ memcpy (obp, lintcmd, cmdlen);
obp += cmdlen;
if (arglen != 0) {
*(obp++) = ' ';
- bcopy (argbp, (char *) obp, arglen);
+ memcpy (obp, argbp, arglen);
obp += arglen;
}
@@ -2506,7 +2495,7 @@
letter:
{
HASHNODE *hp;
- unsigned char *ident;
+ U_CHAR *ident;
int before_name_written = CPP_WRITTEN (pfile);
int ident_len;
parse_name (pfile, c);
@@ -2937,12 +2926,12 @@
(char *)base->value.aschain, -1);
base->value.aschain = this;
- pfile->limit = (unsigned char *) sym; /* Pop */
+ pfile->limit = (U_CHAR *) sym; /* Pop */
return 0;
error:
skip_rest_of_line (pfile);
- pfile->limit = (unsigned char *) sym; /* Pop */
+ pfile->limit = (U_CHAR *) sym; /* Pop */
return 0;
}
@@ -3007,11 +2996,11 @@
delete_macro (base); /* Last answer for this predicate deleted. */
}
- pfile->limit = (unsigned char *) sym; /* Pop */
+ pfile->limit = (U_CHAR *) sym; /* Pop */
return 0;
error:
skip_rest_of_line (pfile);
- pfile->limit = (unsigned char *) sym; /* Pop */
+ pfile->limit = (U_CHAR *) sym; /* Pop */
return 0;
}
@@ -3019,7 +3008,7 @@
void
cpp_unassert (pfile, str)
cpp_reader *pfile;
- unsigned char *str;
+ U_CHAR *str;
{
if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
{
Index: cpplib.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpplib.h,v
retrieving revision 1.40
diff -u -r1.40 cpplib.h
--- cpplib.h 1999/09/07 15:41:26 1.40
+++ cpplib.h 1999/09/07 19:40:36
@@ -69,7 +69,6 @@
CPP_POP
};
-typedef enum cpp_token (*parse_underflow_t) PARAMS((cpp_reader *));
typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *));
extern void parse_set_mark PARAMS ((cpp_reader *));
@@ -87,11 +86,11 @@
struct cpp_buffer
{
- unsigned char *cur; /* current position */
- unsigned char *rlimit; /* end of valid data */
- unsigned char *buf; /* entire buffer */
- unsigned char *alimit; /* end of allocated buffer */
- unsigned char *line_base; /* start of current line */
+ U_CHAR *cur; /* current position */
+ U_CHAR *rlimit; /* end of valid data */
+ U_CHAR *buf; /* entire buffer */
+ U_CHAR *alimit; /* end of allocated buffer */
+ U_CHAR *line_base; /* start of current line */
struct cpp_buffer *prev;
@@ -111,7 +110,6 @@
long lineno; /* Line number at CPP_LINE_BASE. */
long colno; /* Column number at CPP_LINE_BASE. */
long mark; /* Saved position for lengthy backtrack. */
- parse_underflow_t underflow;
parse_cleanup_t cleanup;
void *data;
@@ -154,16 +152,15 @@
struct cpp_reader
{
- parse_underflow_t get_token;
cpp_buffer *buffer;
cpp_options *opts;
/* A buffer used for both for cpp_get_token's output, and also internally. */
- unsigned char *token_buffer;
+ U_CHAR *token_buffer;
/* Allocated size of token_buffer. CPP_RESERVE allocates space. */
unsigned int token_buffer_size;
/* End of the written part of token_buffer. */
- unsigned char *limit;
+ U_CHAR *limit;
/* Error counter for exit code */
int errors;
@@ -608,7 +605,7 @@
struct macrodef
{
struct definition *defn;
- unsigned char *symnam;
+ U_CHAR *symnam;
int symlen;
};
@@ -639,7 +636,7 @@
int length; /* length of expansion string */
int predefined; /* True if the macro was builtin or */
/* came from the command line */
- unsigned char *expansion;
+ U_CHAR *expansion;
int line; /* Line number of definition */
const char *file; /* File of definition */
char rest_args; /* Nonzero if last arg. absorbs the rest */
@@ -659,7 +656,7 @@
with comma-space between them.
The only use of this is that we warn on redefinition
if this differs between the old and new definitions. */
- unsigned char *argnames;
+ U_CHAR *argnames;
} args;
};
@@ -670,11 +667,11 @@
#ifndef FAKE_CONST
#define FAKE_CONST const
#endif
-extern FAKE_CONST unsigned char is_idstart[256];
-extern FAKE_CONST unsigned char is_idchar[256];
-extern FAKE_CONST unsigned char is_hor_space[256];
-extern FAKE_CONST unsigned char is_space[256];
-extern FAKE_CONST unsigned char trigraph_table[256];
+extern FAKE_CONST U_CHAR is_idstart[256];
+extern FAKE_CONST U_CHAR is_idchar[256];
+extern FAKE_CONST U_CHAR is_hor_space[256];
+extern FAKE_CONST U_CHAR is_space[256];
+extern FAKE_CONST U_CHAR trigraph_table[256];
#undef FAKE_CONST
/* Stack of conditionals currently in progress
@@ -682,22 +679,22 @@
struct if_stack {
struct if_stack *next; /* for chaining to the next stack frame */
- char *fname; /* copied from input when frame is made */
+ char *fname; /* copied from input when frame is made */
int lineno; /* similarly */
int if_succeeded; /* true if a leg of this if-group
- has been passed through rescan */
- unsigned char *control_macro; /* For #ifndef at start of file,
- this is the macro name tested. */
+ has been passed through rescan */
+ U_CHAR *control_macro; /* For #ifndef at start of file,
+ this is the macro name tested. */
enum node_type type; /* type of last directive seen in this group */
};
typedef struct if_stack IF_STACK_FRAME;
-extern void cpp_buf_line_and_col PARAMS((cpp_buffer *, long *, long *));
+extern void cpp_buf_line_and_col PARAMS((const cpp_buffer *, long *, long *));
extern cpp_buffer* cpp_file_buffer PARAMS((cpp_reader *));
-extern void cpp_define PARAMS ((cpp_reader *, unsigned char *));
-extern void cpp_assert PARAMS ((cpp_reader *, unsigned char *));
-extern void cpp_undef PARAMS ((cpp_reader *, unsigned char *));
-extern void cpp_unassert PARAMS ((cpp_reader *, unsigned char *));
+extern void cpp_define PARAMS ((cpp_reader *, U_CHAR *));
+extern void cpp_assert PARAMS ((cpp_reader *, U_CHAR *));
+extern void cpp_undef PARAMS ((cpp_reader *, U_CHAR *));
+extern void cpp_unassert PARAMS ((cpp_reader *, U_CHAR *));
extern void cpp_error PVPROTO ((cpp_reader *, const char *, ...))
ATTRIBUTE_PRINTF_2;
@@ -721,11 +718,10 @@
extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
extern HOST_WIDEST_INT cpp_parse_escape PARAMS ((cpp_reader *, char **, HOST_WIDEST_INT));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
- unsigned char *, long));
+ U_CHAR *, long));
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
-extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *, const unsigned char *,
- int, int));
+extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *, const U_CHAR *, int, int));
extern void cpp_reader_init PARAMS ((cpp_reader *));
extern void cpp_options_init PARAMS ((cpp_options *));
extern int cpp_start_read PARAMS ((cpp_reader *, char *));
@@ -750,10 +746,8 @@
ATTRIBUTE_PRINTF_2;
extern void cpp_message PVPROTO ((cpp_reader *, int, const char *, ...))
ATTRIBUTE_PRINTF_3;
-extern void cpp_pfatal_with_name PROTO ((cpp_reader *, const char *))
- ATTRIBUTE_NORETURN;
-extern void cpp_file_line_for_message PROTO ((cpp_reader *, const char *,
- int, int));
+extern void cpp_pfatal_with_name PROTO ((cpp_reader *, const char *)) ATTRIBUTE_NORETURN;
+extern void cpp_file_line_for_message PROTO ((cpp_reader *, const char *, int, int));
extern void cpp_print_containing_files PROTO ((cpp_reader *));
extern void cpp_notice PVPROTO ((const char *msgid, ...)) ATTRIBUTE_PRINTF_1;
@@ -766,9 +760,12 @@
int *));
extern int finclude PROTO ((cpp_reader *, int,
struct include_hash *));
-extern void deps_output PROTO ((cpp_reader *,
- const char *, int));
+extern void deps_output PROTO ((cpp_reader *, const char *, int));
extern struct include_hash *include_hash PROTO ((cpp_reader *, const char *, int));
+
+/* In cppalloc.c */
+extern PTR xmemdup PROTO ((const PTR input, size_t copy_size,
+ size_t alloc_size));
#ifndef INCLUDE_LEN_FUDGE
#define INCLUDE_LEN_FUDGE 0
More information about the Gcc-patches
mailing list