* sb.h (sb_max_power_two): Delete.
(struct sb): Delete "item" and "pot". Make "len" a size_t. Add "max".
(sb_element): Delete.
(sb_add_char, sb_add_buffer, sb_skip_comma, sb_skip_write): Update
prototypes.
* sb.c (string_count, free_list): Delete.
(sb_build, sb_kill, sb_check): Rewrite.
(scrub_from_sb, sb_add_char, sb_add_string, sb_add_buffer,
sb_skip_white, sb_skip_comma): Replace assorted int params,
vars and return types with size_t.
* input-scrub.c: Likewise.
* macro.c: Likewise.
* macro.h: Likewise.
* as.c: Likewise.
* as.h: Likewise.
* input-file.h: Likewise.
* input-file.c: Likewise.
* read.c: Likewise.
* app.c: ..or ptrdiff_t.
* input-file.c (input_file_get): Use ferror.
(input_file_give_next_buffer): Use input_file_get.
+2012-06-07 Alan Modra <amodra@gmail.com>
+
+ PR gas/14201
+ * sb.h (sb_max_power_two): Delete.
+ (struct sb): Delete "item" and "pot". Make "len" a size_t. Add "max".
+ (sb_element): Delete.
+ (sb_add_char, sb_add_buffer, sb_skip_comma, sb_skip_write): Update
+ prototypes.
+ * sb.c (string_count, free_list): Delete.
+ (sb_build, sb_kill, sb_check): Rewrite.
+ (scrub_from_sb, sb_add_char, sb_add_string, sb_add_buffer,
+ sb_skip_white, sb_skip_comma): Replace assorted int params,
+ vars and return types with size_t.
+ * input-scrub.c: Likewise.
+ * macro.c: Likewise.
+ * macro.h: Likewise.
+ * as.c: Likewise.
+ * as.h: Likewise.
+ * input-file.h: Likewise.
+ * input-file.c: Likewise.
+ * read.c: Likewise.
+ * app.c: ..or ptrdiff_t.
+ * input-file.c (input_file_get): Use ferror.
+ (input_file_give_next_buffer): Use input_file_get.
+
2012-05-29 Roland McGrath <mcgrathr@google.com>
* read.c [HANDLE_BUNDLE] (bundle_lock_depth): New variable.
/* This is the Assembler Pre-Processor
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
+ 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2012
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
static char out_buf[20];
static int add_newlines;
static char *saved_input;
-static int saved_input_len;
+static size_t saved_input_len;
static char input_buffer[32 * 1024];
static const char *mri_state;
static char mri_last_ch;
char out_buf[sizeof (out_buf)];
int add_newlines;
char * saved_input;
- int saved_input_len;
+ size_t saved_input_len;
#ifdef TC_M68K
int scrub_m68k_mri;
#endif
saved_input = NULL;
else
{
- gas_assert (saved->saved_input_len <= (int) (sizeof input_buffer));
+ gas_assert (saved->saved_input_len <= sizeof (input_buffer));
memcpy (input_buffer, saved->saved_input, saved->saved_input_len);
saved_input = input_buffer;
saved_input_len = saved->saved_input_len;
machine, and saves its state so that it may return at any point.
This is the way the old code used to work. */
-int
-do_scrub_chars (int (*get) (char *, int), char *tostart, int tolen)
+size_t
+do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
{
char *to = tostart;
char *toend = tostart + tolen;
char *from;
char *fromend;
- int fromlen;
+ size_t fromlen;
register int ch, ch2 = 0;
/* Character that started the string we're working on. */
static char quotechar;
GET and PUT macros. */
{
char *s;
- int len;
+ ptrdiff_t len;
for (s = from; s < fromend; s++)
{
)
{
char *s;
- int len;
+ ptrdiff_t len;
for (s = from; s < fromend; s++)
{
/* The interface between the macro code and gas expression handling. */
-static int
-macro_expr (const char *emsg, int idx, sb *in, int *val)
+static size_t
+macro_expr (const char *emsg, size_t idx, sb *in, offsetT *val)
{
char *hold;
expressionS ex;
if (ex.X_op != O_constant)
as_bad ("%s", emsg);
- *val = (int) ex.X_add_number;
+ *val = ex.X_add_number;
return idx;
}
void input_scrub_insert_file (char *);
char * input_scrub_new_file (char *);
char * input_scrub_next_buffer (char **bufp);
-int do_scrub_chars (int (*get) (char *, int), char *, int);
+size_t do_scrub_chars (size_t (*get) (char *, size_t), char *, size_t);
int gen_to_words (LITTLENUM_TYPE *, int, long);
int had_err (void);
int ignore_input (void);
/* input_file.c - Deal with Input Files -
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001,
- 2002, 2003, 2005, 2006, 2007, 2009
+ 2002, 2003, 2005, 2006, 2007, 2009, 2012
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
#include "input-file.h"
#include "safe-ctype.h"
-static int input_file_get (char *, int);
-
/* This variable is non-zero if the file currently being read should be
preprocessed by app. It is zero if the file can be read straight in. */
int preprocess = 0;
}
/* Return BUFFER_SIZE. */
-unsigned int
+size_t
input_file_buffer_size (void)
{
return (BUFFER_SIZE);
/* This function is passed to do_scrub_chars. */
-static int
-input_file_get (char *buf, int buflen)
+static size_t
+input_file_get (char *buf, size_t buflen)
{
- int size;
+ size_t size;
if (feof (f_in))
return 0;
size = fread (buf, sizeof (char), buflen, f_in);
- if (size < 0)
- {
- as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
- size = 0;
- }
+ if (ferror (f_in))
+ as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
return size;
}
input_file_give_next_buffer (char *where /* Where to place 1st character of new buffer. */)
{
char *return_value; /* -> Last char of what we read, + 1. */
- int size;
+ size_t size;
if (f_in == (FILE *) 0)
return 0;
if (preprocess)
size = do_scrub_chars (input_file_get, where, BUFFER_SIZE);
else
- {
- if (feof (f_in))
- size = 0;
- else
- size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
- }
+ size = input_file_get (where, BUFFER_SIZE);
- if (size < 0)
- {
- as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
- size = 0;
- }
if (size)
return_value = where + size;
else
/* input_file.h header for input-file.c
- Copyright 1987, 1992, 1993, 2000, 2003, 2005, 2006, 2007
+ Copyright 1987, 1992, 1993, 2000, 2003, 2005, 2006, 2007, 2012
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
char *input_file_give_next_buffer (char *where);
char *input_file_push (void);
-unsigned int input_file_buffer_size (void);
+size_t input_file_buffer_size (void);
void input_file_begin (void);
void input_file_close (void);
void input_file_end (void);
/* input_scrub.c - Break up input buffers into whole numbers of lines.
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
static unsigned int buffer_length;
/* The index into an sb structure we are reading from. -1 if none. */
-static int sb_index = -1;
+static size_t sb_index = -1;
/* If we are reading from an sb structure, this is it. */
static sb from_sb;
char * partial_where;
int partial_size;
char save_source[AFTER_SIZE];
- unsigned int buffer_length;
+ size_t buffer_length;
char * physical_input_file;
char * logical_input_file;
unsigned int physical_input_line;
int logical_input_line;
- int sb_index;
+ size_t sb_index;
sb from_sb;
int from_sb_is_expansion; /* Should we do a conditional check? */
struct input_save * next_saved_file; /* Chain of input_saves. */
{
register char *limit; /*->just after last char of buffer. */
- if (sb_index >= 0)
+ if (sb_index != (size_t) -1)
{
if (sb_index >= from_sb.len)
{
sb_kill (&from_sb);
- if (from_sb_is_expansion
- )
+ if (from_sb_is_expansion)
{
cond_finish_check (macro_nest);
#ifdef md_macro_end
void
bump_line_counters (void)
{
- if (sb_index < 0)
+ if (sb_index == (size_t) -1)
{
++physical_input_line;
if (logical_input_line >= 0)
/* macro.c - macro support for gas
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006, 2007, 2008, 2011 Free Software Foundation, Inc.
+ 2004, 2005, 2006, 2007, 2008, 2011, 2012 Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
sac@cygnus.com
/* Function to use to parse an expression. */
-static int (*macro_expr) (const char *, int, sb *, int *);
+static size_t (*macro_expr) (const char *, size_t, sb *, offsetT *);
/* Number of macro expansions that have been done. */
void
macro_init (int alternate, int mri, int strip_at,
- int (*exp) (const char *, int, sb *, int *))
+ size_t (*exp) (const char *, size_t, sb *, offsetT *))
{
macro_hash = hash_new ();
macro_defined = 0;
int
buffer_and_nest (const char *from, const char *to, sb *ptr,
- int (*get_line) (sb *))
+ size_t (*get_line) (sb *))
{
- int from_len;
- int to_len = strlen (to);
+ size_t from_len;
+ size_t to_len = strlen (to);
int depth = 1;
- int line_start = ptr->len;
-
- int more = get_line (ptr);
+ size_t line_start = ptr->len;
+ size_t more = get_line (ptr);
if (to_len == 4 && strcasecmp (to, "ENDR") == 0)
{
while (more)
{
/* Try to find the first pseudo op on the line. */
- int i = line_start;
+ size_t i = line_start;
bfd_boolean had_colon = FALSE;
/* With normal syntax we can suck what we want till we get
/* Pick up a token. */
-static int
-get_token (int idx, sb *in, sb *name)
+static size_t
+get_token (size_t idx, sb *in, sb *name)
{
if (idx < in->len
&& is_name_beginner (in->ptr[idx]))
/* Pick up a string. */
-static int
-getstring (int idx, sb *in, sb *acc)
+static size_t
+getstring (size_t idx, sb *in, sb *acc)
{
while (idx < in->len
&& (in->ptr[idx] == '"'
(string) -> return (string-including-whitespaces)
xyx<whitespace> -> return xyz. */
-static int
-get_any_string (int idx, sb *in, sb *out)
+static size_t
+get_any_string (size_t idx, sb *in, sb *out)
{
sb_reset (out);
idx = sb_skip_white (idx, in);
}
else if (in->ptr[idx] == '%' && macro_alternate)
{
- int val;
+ offsetT val;
char buf[20];
/* Turns the next expression into a string. */
idx + 1,
in,
&val);
- sprintf (buf, "%d", val);
+ sprintf (buf, "%" BFD_VMA_FMT "d", val);
sb_add_string (out, buf);
}
else if (in->ptr[idx] == '"'
/* Pick up the formal parameters of a macro definition. */
-static int
-do_formals (macro_entry *macro, int idx, sb *in)
+static size_t
+do_formals (macro_entry *macro, size_t idx, sb *in)
{
formal_entry **p = ¯o->formals;
const char *name;
while (idx < in->len)
{
formal_entry *formal = new_formal ();
- int cidx;
+ size_t cidx;
idx = get_token (idx, in, &formal->name);
if (formal->name.len == 0)
the macro which was defined. */
const char *
-define_macro (int idx, sb *in, sb *label,
- int (*get_line) (sb *),
+define_macro (size_t idx, sb *in, sb *label,
+ size_t (*get_line) (sb *),
char *file, unsigned int line,
const char **namep)
{
}
else
{
- int cidx;
+ size_t cidx;
idx = get_token (idx, in, &name);
macro->name = sb_terminate (&name);
/* Scan a token, and then skip KIND. */
-static int
-get_apost_token (int idx, sb *in, sb *name, int kind)
+static size_t
+get_apost_token (size_t idx, sb *in, sb *name, int kind)
{
idx = get_token (idx, in, name);
if (idx < in->len
/* Substitute the actual value for a formal parameter. */
-static int
-sub_actual (int start, sb *in, sb *t, struct hash_control *formal_hash,
+static size_t
+sub_actual (size_t start, sb *in, sb *t, struct hash_control *formal_hash,
int kind, sb *out, int copyifnotthere)
{
- int src;
+ size_t src;
formal_entry *ptr;
src = get_apost_token (start, in, t, kind);
struct hash_control *formal_hash, const macro_entry *macro)
{
sb t;
- int src = 0, inquote = 0, macro_line = 0;
+ size_t src = 0;
+ int inquote = 0, macro_line = 0;
formal_entry *loclist = NULL;
const char *err = NULL;
body. */
static const char *
-macro_expand (int idx, sb *in, macro_entry *m, sb *out)
+macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
{
sb t;
formal_entry *ptr;
idx = sb_skip_white (idx, in);
while (idx < in->len)
{
- int scan;
+ size_t scan;
/* Look and see if it's a positional or keyword arg. */
scan = idx;
success, or an error message otherwise. */
const char *
-expand_irp (int irpc, int idx, sb *in, sb *out, int (*get_line) (sb *))
+expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
{
sb sub;
formal_entry f;
{
if (in->ptr[idx] == '"')
{
- int nxt;
+ size_t nxt;
if (irpc)
in_quotes = ! in_quotes;
/* macro.h - header file for macro support for gas
Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006,
- 2007 Free Software Foundation, Inc.
+ 2007, 2012 Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
sac@cygnus.com
extern struct hash_control *macro_hash;
-extern int buffer_and_nest (const char *, const char *, sb *, int (*) (sb *));
-extern void macro_init
- (int, int, int, int (*) (const char *, int, sb *, int *));
+extern int buffer_and_nest (const char *, const char *, sb *,
+ size_t (*) (sb *));
+extern void macro_init (int, int, int,
+ size_t (*) (const char *, size_t, sb *, offsetT *));
extern void macro_set_alternate (int);
extern void macro_mri_mode (int);
-extern const char *define_macro
- (int, sb *, sb *, int (*) (sb *), char *, unsigned int, const char **);
+extern const char *define_macro (size_t, sb *, sb *, size_t (*) (sb *),
+ char *, unsigned int, const char **);
extern int check_macro (const char *, sb *, const char **, macro_entry **);
extern void delete_macro (const char *);
-extern const char *expand_irp (int, int, sb *, sb *, int (*) (sb *));
+extern const char *expand_irp (int, size_t, sb *, sb *, size_t (*) (sb *));
#endif
static int hex_float (int, char *);
static segT get_known_segmented_expression (expressionS * expP);
static void pobegin (void);
-static int get_non_macro_line_sb (sb *);
+static size_t get_non_macro_line_sb (sb *);
static void generate_file_debug (void);
static char *_find_end_of_line (char *, int, int, int);
\f
static char *scrub_string;
static char *scrub_string_end;
-static int
-scrub_from_string (char *buf, int buflen)
+static size_t
+scrub_from_string (char *buf, size_t buflen)
{
- int copy;
+ size_t copy;
copy = scrub_string_end - scrub_string;
if (copy > buflen)
new_tmp = new_buf;
for (;;)
{
- int space;
- int size;
+ size_t space;
+ size_t size;
space = (new_buf + new_length) - new_tmp;
size = do_scrub_chars (scrub_from_string, new_tmp, space);
return *input_line_pointer++;
}
-static int
+static size_t
get_non_macro_line_sb (sb *line)
{
return get_line_sb (line, 0);
}
-static int
+static size_t
get_macro_line_sb (sb *line)
{
return get_line_sb (line, 1);
/* sb.c - string buffer manipulation routines
- Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2009
+ Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2009, 2012
Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
use foo->ptr[*];
sb_kill (&foo); */
-static int dsize = 5;
-static void sb_check (sb *, int);
-
-/* Statistics of sb structures. */
-static int string_count[sb_max_power_two];
-
-/* Free list of sb structures. */
-static struct
-{
- sb_element *size[sb_max_power_two];
-} free_list;
+static size_t dsize = 32;
+static void sb_check (sb *, size_t);
/* Initializes an sb. */
static void
-sb_build (sb *ptr, int size)
+sb_build (sb *ptr, size_t size)
{
- /* See if we can find one to allocate. */
- sb_element *e;
-
- gas_assert (size < sb_max_power_two);
-
- e = free_list.size[size];
- if (!e)
- {
- /* Nothing there, allocate one and stick into the free list. */
- e = (sb_element *) xmalloc (sizeof (sb_element) + (1 << size));
- e->next = free_list.size[size];
- e->size = 1 << size;
- free_list.size[size] = e;
- string_count[size]++;
- }
-
- /* Remove from free list. */
- free_list.size[size] = e->next;
-
- /* Copy into callers world. */
- ptr->ptr = e->data;
- ptr->pot = size;
+ ptr->ptr = xmalloc (size + 1);
+ ptr->max = size;
ptr->len = 0;
- ptr->item = e;
}
void
void
sb_kill (sb *ptr)
{
- /* Return item to free list. */
- ptr->item->next = free_list.size[ptr->pot];
- free_list.size[ptr->pot] = ptr->item;
+ free (ptr->ptr);
}
/* Add the sb at s to the end of the sb at ptr. */
static sb *sb_to_scrub;
static char *scrub_position;
-static int
-scrub_from_sb (char *buf, int buflen)
+static size_t
+scrub_from_sb (char *buf, size_t buflen)
{
- int copy;
+ size_t copy;
copy = sb_to_scrub->len - (scrub_position - sb_to_scrub->ptr);
if (copy > buflen)
copy = buflen;
and grow it if it doesn't. */
static void
-sb_check (sb *ptr, int len)
+sb_check (sb *ptr, size_t len)
{
- if (ptr->len + len >= 1 << ptr->pot)
+ size_t max = ptr->max;
+
+ while (ptr->len + len >= max)
+ {
+ max <<= 1;
+ if (max == 0)
+ as_fatal ("string buffer overflow");
+ }
+ if (max != ptr->max)
{
- sb tmp;
- int pot = ptr->pot;
-
- while (ptr->len + len >= 1 << pot)
- pot++;
- sb_build (&tmp, pot);
- sb_add_sb (&tmp, ptr);
- sb_kill (ptr);
- *ptr = tmp;
+ ptr->max = max;
+ ptr->ptr = xrealloc (ptr->ptr, max + 1);
}
}
/* Add character c to the end of the sb at ptr. */
void
-sb_add_char (sb *ptr, int c)
+sb_add_char (sb *ptr, size_t c)
{
sb_check (ptr, 1);
ptr->ptr[ptr->len++] = c;
void
sb_add_string (sb *ptr, const char *s)
{
- int len = strlen (s);
+ size_t len = strlen (s);
sb_check (ptr, len);
memcpy (ptr->ptr + ptr->len, s, len);
ptr->len += len;
/* Add string at s of length len to sb at ptr */
void
-sb_add_buffer (sb *ptr, const char *s, int len)
+sb_add_buffer (sb *ptr, const char *s, size_t len)
{
sb_check (ptr, len);
memcpy (ptr->ptr + ptr->len, s, len);
/* Start at the index idx into the string in sb at ptr and skip
whitespace. return the index of the first non whitespace character. */
-int
-sb_skip_white (int idx, sb *ptr)
+size_t
+sb_skip_white (size_t idx, sb *ptr)
{
while (idx < ptr->len
&& (ptr->ptr[idx] == ' '
a comma and any following whitespace. returns the index of the
next character. */
-int
-sb_skip_comma (int idx, sb *ptr)
+size_t
+sb_skip_comma (size_t idx, sb *ptr)
{
while (idx < ptr->len
&& (ptr->ptr[idx] == ' '
/* sb.h - header file for string buffer manipulation routines
- Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007
+ Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2012
Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
Obstacks provide all the functionality needed, but are too
complicated, hence the sb.
- An sb is allocated by the caller, and is initialized to point to an
- sb_element. sb_elements are kept on a free lists, and used when
- needed, replaced onto the free list when unused. */
-
-#define sb_max_power_two 30 /* Don't allow strings more than
- 2^sb_max_power_two long. */
+ An sb is allocated by the caller. */
typedef struct sb
{
char *ptr; /* Points to the current block. */
- int len; /* How much is used. */
- int pot; /* The maximum length is 1<<pot. */
- struct le *item;
+ size_t len; /* How much is used. */
+ size_t max; /* The maximum length. */
}
sb;
-/* Structure of the free list object of a string block. */
-
-typedef struct le
-{
- struct le *next;
- int size;
- char data[1];
-}
-sb_element;
-
extern void sb_new (sb *);
extern void sb_kill (sb *);
extern void sb_add_sb (sb *, sb *);
extern void sb_scrub_and_add_sb (sb *, sb *);
extern void sb_reset (sb *);
-extern void sb_add_char (sb *, int);
+extern void sb_add_char (sb *, size_t);
extern void sb_add_string (sb *, const char *);
-extern void sb_add_buffer (sb *, const char *, int);
+extern void sb_add_buffer (sb *, const char *, size_t);
extern char *sb_terminate (sb *);
-extern int sb_skip_white (int, sb *);
-extern int sb_skip_comma (int, sb *);
+extern size_t sb_skip_white (size_t, sb *);
+extern size_t sb_skip_comma (size_t, sb *);
/* Actually in input-scrub.c. */
extern void input_scrub_include_sb (sb *, char *, int);