This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 2/4] Constify struct stoken.ptr
- From: Keith Seitz <keiths at redhat dot com>
- To: "gdb-patches at sourceware dot org ml" <gdb-patches at sourceware dot org>
- Date: Mon, 30 Sep 2013 11:56:58 -0700
- Subject: [RFA 2/4] Constify struct stoken.ptr
- Authentication-results: sourceware.org; auth=none
Hi,
In this next patch, as I mentioned in the previous email on this series,
the temporary casting needed for struct stoken.ptr is removed
(stoken.ptr is made const).
Again, tested, regression-free, on x86_64 Fedora 18, native and gdbserver.
Keith
ChangeLog
2013-09-24 Keith Seitz <keiths@redhat.com>
* ada-exp.y (write_object_renaming): Update: struct stoken.ptr
is now const.
(block_lookup): Make 'raw_name' and 'name' const.
* ada-lex.l (processString): Update for struct stoken.ptr.
* c-exp.y (qualified_name : TYPENAME COLONCOLON '~' name): Likewise.
(operator_stoken): Likewise.
(lex_one_token): Remove temporary cast to char * for
'yylval.sval.ptr'.
* f-exp.y (yylex): Likewise.
* gdb-types.c (lookup_struct_elt_type): Make argument 'name' const.
* gdbtypes.h (lookup_struct_elt_type): Likewisee.
* go-exp.y (lex_one_token): Remove temporary cast to char * for
'yylval.sval.ptr'.
* jv-exp.y (QualifiedName): Update for struct stoken.ptr.
(yylex): Remove temporary cast to char * for 'yylval.sval.ptr'.
* linespec.c (struct ls_parser): Make 'stream' const.
(find_parameter_list_end): Make argument 'input' and local
variable 'p' const.
(linespec_lexer_lex_string): Make local variables 'start' and
'p' const.
Use skip_spaces_const instead of skip_spaces.
(linespec_lexer_peek_token): Make local variable 'saved_stream'
const.
(parse_linespec): Temporarily cast 'argptr' to const for
'parser->lexer.stream'.
* m2-exp.y (yylex): Remove temporary cast to char * for
'yylval.sval.ptr'.
* objc-lang.c (add_msglist): Make local variable 'p' const.
* p-exp.y (exp : exp '['): Update for struct stoken.ptr.
(exp : STRING): Make 'sp' const.
(parse_number): Make argument 'p' const.
* parser-defs.h (struct stoken): Make 'ptr' const.
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 877dfaf..5270461 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -136,7 +136,7 @@ static void write_name_assoc (struct stoken);
static void write_exp_op_with_string (enum exp_opcode, struct stoken);
-static struct block *block_lookup (struct block *, char *);
+static struct block *block_lookup (struct block *, const char *);
static LONGEST convert_char_literal (struct type *, LONGEST);
@@ -952,6 +952,8 @@ write_object_renaming (const struct block *orig_left_context,
{
struct stoken field_name;
const char *end;
+ char *buf;
+
renaming_expr += 1;
if (slice_state != SIMPLE_INDEX)
@@ -960,9 +962,10 @@ write_object_renaming (const struct block *orig_left_context,
if (end == NULL)
end = renaming_expr + strlen (renaming_expr);
field_name.length = end - renaming_expr;
- field_name.ptr = malloc (end - renaming_expr + 1);
- strncpy (field_name.ptr, renaming_expr, end - renaming_expr);
- field_name.ptr[end - renaming_expr] = '\000';
+ buf = malloc (end - renaming_expr + 1);
+ field_name.ptr = buf;
+ strncpy (buf, renaming_expr, end - renaming_expr);
+ buf[end - renaming_expr] = '\000';
renaming_expr = end;
write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
break;
@@ -980,9 +983,9 @@ write_object_renaming (const struct block *orig_left_context,
}
static struct block*
-block_lookup (struct block *context, char *raw_name)
+block_lookup (struct block *context, const char *raw_name)
{
- char *name;
+ const char *name;
struct ada_symbol_info *syms;
int nsyms;
struct symtab *symtab;
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 93df2fb..2f9e1b3 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -497,7 +497,8 @@ processString (const char *text, int len)
const char *lim = text + len;
struct stoken result;
- q = result.ptr = obstack_alloc (&temp_parse_space, len);
+ q = obstack_alloc (&temp_parse_space, len);
+ result.ptr = q;
p = text;
while (p < lim)
{
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index ea19178..3b2b42a 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -970,18 +970,20 @@ qualified_name: TYPENAME COLONCOLON name
{
struct type *type = $1.type;
struct stoken tmp_token;
+ char *buf;
+
CHECK_TYPEDEF (type);
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION
&& TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
error (_("`%s' is not defined as an aggregate type."),
TYPE_SAFE_NAME (type));
-
- tmp_token.ptr = (char*) alloca ($4.length + 2);
+ buf = alloca ($4.length + 2);
+ tmp_token.ptr = buf;
tmp_token.length = $4.length + 1;
- tmp_token.ptr[0] = '~';
- memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
- tmp_token.ptr[tmp_token.length] = 0;
+ buf[0] = '~';
+ memcpy (buf+1, $4.ptr, $4.length);
+ buf[tmp_token.length] = 0;
/* Check for valid destructor name. */
destructor_name_p (tmp_token.ptr, $1.type);
@@ -1651,13 +1653,16 @@ operator_stoken (const char *op)
{
static const char *operator_string = "operator";
struct stoken st = { NULL, 0 };
+ char *buf;
+
st.length = strlen (operator_string) + strlen (op);
- st.ptr = malloc (st.length + 1);
- strcpy (st.ptr, operator_string);
- strcat (st.ptr, op);
+ buf = malloc (st.length + 1);
+ strcpy (buf, operator_string);
+ strcat (buf, op);
+ st.ptr = buf;
/* The toplevel (c_parse) will free the memory allocated here. */
- make_cleanup (free, st.ptr);
+ make_cleanup (free, buf);
return st;
};
@@ -2738,7 +2743,7 @@ lex_one_token (void)
tryname:
- yylval.sval.ptr = (char *) tokstart;
+ yylval.sval.ptr = tokstart;
yylval.sval.length = namelen;
/* Catch specific keywords. */
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 9a82230..59c5e6c 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1159,7 +1159,7 @@ yylex (void)
return f77_keywords[i].token;
}
- yylval.sval.ptr = (char *) tokstart;
+ yylval.sval.ptr = tokstart;
yylval.sval.length = namelen;
if (*tokstart == '$')
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ea5ca21..6c809a4 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1353,7 +1353,7 @@ lookup_template_type (char *name, struct type *type,
If NAME is the name of a baseclass type, return that type. */
struct type *
-lookup_struct_elt_type (struct type *type, char *name, int noerr)
+lookup_struct_elt_type (struct type *type, const char *name, int noerr)
{
int i;
char *typename;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 0ca7a87..5e8d1e7 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1508,7 +1508,7 @@ extern const char *type_name_no_tag (const struct type *);
extern const char *type_name_no_tag_or_error (struct type *type);
-extern struct type *lookup_struct_elt_type (struct type *, char *, int);
+extern struct type *lookup_struct_elt_type (struct type *, const char *, int);
extern struct type *make_pointer_type (struct type *, struct type **);
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 166d380..01c382a 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -1295,7 +1295,7 @@ lex_one_token (void)
tryname:
- yylval.sval.ptr = (char *) tokstart;
+ yylval.sval.ptr = tokstart;
yylval.sval.length = namelen;
/* Catch specific keywords. */
diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y
index c69caf5..a9ad4d9 100644
--- a/gdb/jv-exp.y
+++ b/gdb/jv-exp.y
@@ -345,10 +345,13 @@ QualifiedName:
$$.ptr = $1.ptr; /* Optimization. */
else
{
- $$.ptr = (char *) malloc ($$.length + 1);
- make_cleanup (free, $$.ptr);
- sprintf ($$.ptr, "%.*s.%.*s",
+ char *buf;
+
+ buf = malloc ($$.length + 1);
+ make_cleanup (free, buf);
+ sprintf (buf, "%.*s.%.*s",
$1.length, $1.ptr, $3.length, $3.ptr);
+ $$.ptr = buf;
} }
;
@@ -1175,7 +1178,7 @@ yylex (void)
break;
}
- yylval.sval.ptr = (char *) tokstart;
+ yylval.sval.ptr = tokstart;
yylval.sval.length = namelen;
if (*tokstart == '$')
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8b7f3bd..96f1d07 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -281,7 +281,7 @@ struct ls_parser
char *saved_arg;
/* Head of the input stream. */
- char **stream;
+ const char **stream;
#define PARSER_STREAM(P) (*(P)->lexer.stream)
/* The current token. */
@@ -515,12 +515,12 @@ is_closing_quote_enclosed (const char *p)
This helper function assists with lexing string segments
which might contain valid (non-terminating) commas. */
-static char *
-find_parameter_list_end (char *input)
+static const char *
+find_parameter_list_end (const char *input)
{
char end_char, start_char;
int depth;
- char *p;
+ const char *p;
start_char = *input;
if (start_char == '(')
@@ -557,7 +557,7 @@ static linespec_token
linespec_lexer_lex_string (linespec_parser *parser)
{
linespec_token token;
- char *start = PARSER_STREAM (parser);
+ const char *start = PARSER_STREAM (parser);
token.type = LSTOKEN_STRING;
@@ -607,7 +607,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
}
else
{
- char *p;
+ const char *p;
/* Otherwise, only identifier characters are permitted.
Spaces are the exception. In general, we keep spaces,
@@ -621,7 +621,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
{
if (isspace (*PARSER_STREAM (parser)))
{
- p = skip_spaces (PARSER_STREAM (parser));
+ p = skip_spaces_const (PARSER_STREAM (parser));
/* When we get here we know we've found something followed by
a space (we skip over parens and templates below).
So if we find a keyword now, we know it is a keyword and not,
@@ -681,7 +681,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
else if (*PARSER_STREAM (parser) == '<'
|| *PARSER_STREAM (parser) == '(')
{
- char *p;
+ const char *p;
p = find_parameter_list_end (PARSER_STREAM (parser));
if (p != NULL)
@@ -733,7 +733,7 @@ linespec_lexer_lex_one (linespec_parser *parser)
if (parser->lexer.current.type == LSTOKEN_CONSUMED)
{
/* Skip any whitespace. */
- PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
+ PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
/* Check for a keyword, they end the linespec. */
keyword = NULL;
@@ -819,7 +819,7 @@ static linespec_token
linespec_lexer_peek_token (linespec_parser *parser)
{
linespec_token next;
- char *saved_stream = PARSER_STREAM (parser);
+ const char *saved_stream = PARSER_STREAM (parser);
linespec_token saved_token = parser->lexer.current;
next = linespec_lexer_consume_token (parser);
@@ -2175,7 +2175,7 @@ parse_linespec (linespec_parser *parser, char **argptr)
parser->keyword_ok = 0;
parser->lexer.saved_arg = *argptr;
- parser->lexer.stream = argptr;
+ parser->lexer.stream = (const char **) argptr;
file_exception.reason = 0;
/* Initialize the default symtab and line offset. */
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 47ea640..0002e45 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -907,7 +907,7 @@ yylex (void)
}
if(c != quote)
error (_("Unterminated string or character constant."));
- yylval.sval.ptr = (char *) (tokstart + 1);
+ yylval.sval.ptr = tokstart + 1;
yylval.sval.length = namelen - 1;
lexptr += namelen + 1;
@@ -987,7 +987,7 @@ yylex (void)
&& strncmp (tokstart, keytab[i].keyw, namelen) == 0)
return keytab[i].token;
- yylval.sval.ptr = (char *) tokstart;
+ yylval.sval.ptr = tokstart;
yylval.sval.length = namelen;
if (*tokstart == '$')
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 734fc5d..cf99a0f 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -426,7 +426,8 @@ start_msglist(void)
void
add_msglist(struct stoken *str, int addcolon)
{
- char *s, *p;
+ char *s;
+ const char *p;
int len, plen;
if (str == 0) /* Unnamed arg, or... */
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index e0abd07..ca25393 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -158,7 +158,7 @@ static char * uptok (char *, int);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
static struct type *current_type;
static struct internalvar *intvar;
@@ -352,9 +352,12 @@ exp : exp '['
if (arrayfieldindex)
{
struct stoken stringsval;
- stringsval.ptr = alloca (strlen (arrayname) + 1);
+ char *buf;
+
+ buf = alloca (strlen (arrayname) + 1);
+ stringsval.ptr = buf;
stringsval.length = strlen (arrayname);
- strcpy (stringsval.ptr, arrayname);
+ strcpy (buf, arrayname);
current_type = TYPE_FIELD_TYPE (current_type,
arrayfieldindex - 1);
write_exp_elt_opcode (STRUCTOP_STRUCT);
@@ -591,7 +594,8 @@ exp : STRING
the array upper bound is the string length.
There is no such thing in C as a completely empty
string. */
- char *sp = $1.ptr; int count = $1.length;
+ const char *sp = $1.ptr; int count = $1.length;
+
while (count-- > 0)
{
write_exp_elt_opcode (OP_LONG);
@@ -854,7 +858,7 @@ name_not_typename : NAME
/*** Needs some error checking for the float case ***/
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
{
/* FIXME: Shouldn't these be unsigned? We don't deal with negative values
here, and we do kind of silly things like cast to unsigned. */
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index aaefe3f..ed022ad 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -67,7 +67,7 @@ extern int arglist_len;
struct stoken
{
/* Pointer to first byte of char-string or first bit of bit-string. */
- char *ptr;
+ const char *ptr;
/* Length of string in bytes for char-string or bits for bit-string. */
int length;
};