Skip to content

Commit b42b416

Browse files
Remove unnecessary casts to uchar. The casts are stemming from
the lexer API which internally uses unsigned char variables to address its state map. The implementation of the lexer should be internal to the lexer, and not influence the rest of the code.
1 parent e56c6d2 commit b42b416

19 files changed

Lines changed: 73 additions & 86 deletions

sql/event_data_objects.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Event_parse_data::init_body(THD *thd)
168168
(long) body_begin, (long) thd->lex->ptr));
169169

170170
body.length= thd->lex->ptr - body_begin;
171-
const uchar *body_end= body_begin + body.length - 1;
171+
const char *body_end= body_begin + body.length - 1;
172172

173173
/* Trim nuls or close-comments ('*'+'/') or spaces at the end */
174174
while (body_begin < body_end)
@@ -1919,7 +1919,7 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
19191919
event_change_security_context(thd, definer_user, definer_host, dbname,
19201920
&save_ctx);
19211921
thd->lex= &lex;
1922-
mysql_init_query(thd, (uchar*) thd->query, thd->query_length);
1922+
mysql_init_query(thd, thd->query, thd->query_length);
19231923
if (MYSQLparse((void *)thd) || thd->is_fatal_error)
19241924
{
19251925
DBUG_PRINT("error", ("error during compile or thd->is_fatal_error: %d",

sql/event_data_objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Event_parse_data : public Sql_alloc
217217
*/
218218
bool do_not_create;
219219

220-
const uchar *body_begin;
220+
const char *body_begin;
221221

222222
LEX_STRING dbname;
223223
LEX_STRING name;

sql/ha_ndbcluster.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6339,7 +6339,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db,
63396339
LEX *old_lex= thd->lex, newlex;
63406340
thd->lex= &newlex;
63416341
newlex.current_select= NULL;
6342-
lex_start(thd, (const uchar*) "", 0);
6342+
lex_start(thd, "", 0);
63436343
int res= ha_create_table_from_engine(thd, db, table_name);
63446344
thd->lex= old_lex;
63456345
return res;

sql/mysql_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ bool is_update_query(enum enum_sql_command command);
841841
bool alloc_query(THD *thd, const char *packet, uint packet_length);
842842
void mysql_init_select(LEX *lex);
843843
void mysql_reset_thd_for_next_command(THD *thd);
844-
void mysql_init_query(THD *thd, uchar *buf, uint length);
844+
void mysql_init_query(THD *thd, const char *buf, uint length);
845845
bool mysql_new_select(LEX *lex, bool move_down);
846846
void create_select_for_variable(const char *var_name);
847847
void mysql_init_multi_delete(LEX *lex);

sql/partition_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class partition_info : public Sql_alloc
156156
char *part_func_string;
157157
char *subpart_func_string;
158158

159-
uchar *part_state;
159+
const char *part_state;
160160

161161
partition_element *curr_part_elem;
162162
partition_element *current_partition;

sql/sp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
384384
if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged)))
385385
goto end;
386386

387-
lex_start(thd, (uchar*)defstr.c_ptr(), defstr.length());
387+
lex_start(thd, defstr.c_ptr(), defstr.length());
388388

389389
thd->spcont= 0;
390390
if (MYSQLparse(thd) || thd->is_fatal_error || newlex.sphead == NULL)

sql/sp_head.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,14 @@ void
541541
sp_head::init_strings(THD *thd, LEX *lex)
542542
{
543543
DBUG_ENTER("sp_head::init_strings");
544-
const uchar *endp; /* Used to trim the end */
544+
const char *endp; /* Used to trim the end */
545545
/* During parsing, we must use thd->mem_root */
546546
MEM_ROOT *root= thd->mem_root;
547547

548548
if (m_param_begin && m_param_end)
549549
{
550550
m_params.length= m_param_end - m_param_begin;
551-
m_params.str= strmake_root(root,
552-
(char *)m_param_begin, m_params.length);
551+
m_params.str= strmake_root(root, m_param_begin, m_params.length);
553552
}
554553

555554
/* If ptr has overrun end_of_query then end_of_query is the end */
@@ -561,9 +560,9 @@ sp_head::init_strings(THD *thd, LEX *lex)
561560
endp= skip_rear_comments(m_body_begin, endp);
562561

563562
m_body.length= endp - m_body_begin;
564-
m_body.str= strmake_root(root, (char *)m_body_begin, m_body.length);
563+
m_body.str= strmake_root(root, m_body_begin, m_body.length);
565564
m_defstr.length= endp - lex->buf;
566-
m_defstr.str= strmake_root(root, (char *)lex->buf, m_defstr.length);
565+
m_defstr.str= strmake_root(root, lex->buf, m_defstr.length);
567566
DBUG_VOID_RETURN;
568567
}
569568

sql/sp_head.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class sp_head :private Query_arena
126126

127127
create_field m_return_field_def; /* This is used for FUNCTIONs only. */
128128

129-
const uchar *m_tmp_query; // Temporary pointer to sub query string
129+
const char *m_tmp_query; // Temporary pointer to sub query string
130130
st_sp_chistics *m_chistics;
131131
ulong m_sql_mode; // For SHOW CREATE and execution
132132
LEX_STRING m_qname; // db.name
@@ -174,7 +174,7 @@ class sp_head :private Query_arena
174174
*/
175175
HASH m_sroutines;
176176
// Pointers set during parsing
177-
const uchar *m_param_begin, *m_param_end, *m_body_begin;
177+
const char *m_param_begin, *m_param_end, *m_body_begin;
178178

179179
/*
180180
Security context for stored routine which should be run under

sql/sql_lex.cc

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
3333

3434
/* Macros to look like lex */
3535

36-
#define yyGet() *(lex->ptr++)
37-
#define yyGetLast() lex->ptr[-1]
38-
#define yyPeek() lex->ptr[0]
39-
#define yyPeek2() lex->ptr[1]
36+
#define yyGet() ((uchar) *(lex->ptr++))
37+
#define yyGetLast() ((uchar) lex->ptr[-1])
38+
#define yyPeek() ((uchar) lex->ptr[0])
39+
#define yyPeek2() ((uchar) lex->ptr[1])
4040
#define yyUnget() lex->ptr--
4141
#define yySkip() lex->ptr++
4242
#define yyLength() ((uint) (lex->ptr - lex->tok_start)-1)
@@ -127,7 +127,7 @@ st_parsing_options::reset()
127127
(We already do too much here)
128128
*/
129129

130-
void lex_start(THD *thd, const uchar *buf, uint length)
130+
void lex_start(THD *thd, const char *buf, uint length)
131131
{
132132
LEX *lex= thd->lex;
133133
DBUG_ENTER("lex_start");
@@ -238,9 +238,9 @@ void lex_end(LEX *lex)
238238

239239
static int find_keyword(LEX *lex, uint len, bool function)
240240
{
241-
const uchar *tok=lex->tok_start;
241+
const char *tok= lex->tok_start;
242242

243-
SYMBOL *symbol= get_hash_symbol((const char *)tok,len,function);
243+
SYMBOL *symbol= get_hash_symbol(tok, len, function);
244244
if (symbol)
245245
{
246246
lex->yylval->symbol.symbol=symbol;
@@ -305,16 +305,16 @@ static LEX_STRING get_token(LEX *lex,uint length)
305305
static LEX_STRING get_quoted_token(LEX *lex,uint length, char quote)
306306
{
307307
LEX_STRING tmp;
308-
const uchar *from, *end;
309-
uchar *to;
308+
const char *from, *end;
309+
char *to;
310310
yyUnget(); // ptr points now after last token char
311311
tmp.length=lex->yytoklen=length;
312312
tmp.str=(char*) lex->thd->alloc(tmp.length+1);
313-
for (from= lex->tok_start, to= (uchar*) tmp.str, end= to+length ;
313+
for (from= lex->tok_start, to= tmp.str, end= to+length ;
314314
to != end ;
315315
)
316316
{
317-
if ((*to++= *from++) == (uchar) quote)
317+
if ((*to++= *from++) == quote)
318318
from++; // Skip double quotes
319319
}
320320
*to= 0; // End null for safety
@@ -341,9 +341,7 @@ static char *get_text(LEX *lex)
341341
{
342342
int l;
343343
if (use_mb(cs) &&
344-
(l = my_ismbchar(cs,
345-
(const char *)lex->ptr-1,
346-
(const char *)lex->end_of_query))) {
344+
(l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query))) {
347345
lex->ptr += l-1;
348346
continue;
349347
}
@@ -368,12 +366,12 @@ static char *get_text(LEX *lex)
368366
yyUnget();
369367

370368
/* Found end. Unescape and return string */
371-
const uchar *str, *end;
372-
uchar *start;
369+
const char *str, *end;
370+
char *start;
373371

374372
str=lex->tok_start+1;
375373
end=lex->ptr-1;
376-
if (!(start=(uchar*) lex->thd->alloc((uint) (end-str)+1)))
374+
if (!(start= (char*) lex->thd->alloc((uint) (end-str)+1)))
377375
return (char*) ""; // Sql_alloc has set error flag
378376
if (!found_escape)
379377
{
@@ -383,15 +381,14 @@ static char *get_text(LEX *lex)
383381
}
384382
else
385383
{
386-
uchar *to;
384+
char *to;
387385

388386
for (to=start ; str != end ; str++)
389387
{
390388
#ifdef USE_MB
391389
int l;
392390
if (use_mb(cs) &&
393-
(l = my_ismbchar(cs,
394-
(const char *)str, (const char *)end))) {
391+
(l = my_ismbchar(cs, str, end))) {
395392
while (l--)
396393
*to++ = *str++;
397394
str--;
@@ -437,7 +434,7 @@ static char *get_text(LEX *lex)
437434
*to=0;
438435
lex->yytoklen=(uint) (to-start);
439436
}
440-
return (char*) start;
437+
return start;
441438
}
442439
}
443440
return 0; // unexpected end of query
@@ -556,7 +553,6 @@ int MYSQLlex(void *arg, void *yythd)
556553

557554
lex->yylval=yylval; // The global state
558555

559-
lex->tok_end_prev= lex->tok_end;
560556
lex->tok_start_prev= lex->tok_start;
561557

562558
lex->tok_start=lex->tok_end=lex->ptr;
@@ -640,16 +636,14 @@ int MYSQLlex(void *arg, void *yythd)
640636
break;
641637
}
642638
case MY_LEX_IDENT:
643-
const uchar *start;
639+
const char *start;
644640
#if defined(USE_MB) && defined(USE_MB_IDENT)
645641
if (use_mb(cs))
646642
{
647643
result_state= IDENT_QUOTED;
648644
if (my_mbcharlen(cs, yyGetLast()) > 1)
649645
{
650-
int l = my_ismbchar(cs,
651-
(const char *)lex->ptr-1,
652-
(const char *)lex->end_of_query);
646+
int l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query);
653647
if (l == 0) {
654648
state = MY_LEX_CHAR;
655649
continue;
@@ -661,9 +655,7 @@ int MYSQLlex(void *arg, void *yythd)
661655
if (my_mbcharlen(cs, c) > 1)
662656
{
663657
int l;
664-
if ((l = my_ismbchar(cs,
665-
(const char *)lex->ptr-1,
666-
(const char *)lex->end_of_query)) == 0)
658+
if ((l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query)) == 0)
667659
break;
668660
lex->ptr += l-1;
669661
}
@@ -786,9 +778,7 @@ int MYSQLlex(void *arg, void *yythd)
786778
if (my_mbcharlen(cs, c) > 1)
787779
{
788780
int l;
789-
if ((l = my_ismbchar(cs,
790-
(const char *)lex->ptr-1,
791-
(const char *)lex->end_of_query)) == 0)
781+
if ((l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query)) == 0)
792782
break;
793783
lex->ptr += l-1;
794784
}
@@ -1122,7 +1112,7 @@ int MYSQLlex(void *arg, void *yythd)
11221112
Pointer to the last non-comment symbol of the statement.
11231113
*/
11241114

1125-
const uchar *skip_rear_comments(const uchar *begin, const uchar *end)
1115+
const char *skip_rear_comments(const char *begin, const char *end)
11261116
{
11271117
while (begin < end && (end[-1] <= ' ' || end[-1] == '*' ||
11281118
end[-1] == '/' || end[-1] == ';'))

sql/sql_lex.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class st_select_lex_unit: public st_select_lex_node {
542542
void set_limit(st_select_lex *values);
543543
void set_thd(THD *thd_arg) { thd= thd_arg; }
544544

545-
friend void lex_start(THD *thd, const uchar *buf, uint length);
545+
friend void lex_start(THD *thd, const char *buf, uint length);
546546
friend int subselect_union_engine::exec();
547547

548548
List<Item> *get_unit_column_types();
@@ -743,7 +743,7 @@ class st_select_lex: public st_select_lex_node
743743
void cut_subtree() { slave= 0; }
744744
bool test_limit();
745745

746-
friend void lex_start(THD *thd, const uchar *buf, uint length);
746+
friend void lex_start(THD *thd, const char *buf, uint length);
747747
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
748748
void make_empty_select()
749749
{
@@ -996,11 +996,11 @@ typedef struct st_lex : public Query_tables_list
996996
SELECT_LEX *current_select;
997997
/* list of all SELECT_LEX */
998998
SELECT_LEX *all_selects_list;
999-
const uchar *buf; /* The beginning of string, used by SPs */
1000-
const uchar *ptr,*tok_start,*tok_end,*end_of_query;
999+
const char *buf; /* The beginning of string, used by SPs */
1000+
const char *ptr,*tok_start,*tok_end,*end_of_query;
10011001

1002-
/* The values of tok_start/tok_end as they were one call of MYSQLlex before */
1003-
const uchar *tok_start_prev, *tok_end_prev;
1002+
/* The value of tok_start as they were one call of MYSQLlex before */
1003+
const char *tok_start_prev;
10041004

10051005
char *length,*dec,*change;
10061006
LEX_STRING name;
@@ -1202,7 +1202,7 @@ typedef struct st_lex : public Query_tables_list
12021202
Pointers to part of LOAD DATA statement that should be rewritten
12031203
during replication ("LOCAL 'filename' REPLACE INTO" part).
12041204
*/
1205-
const uchar *fname_start, *fname_end;
1205+
const char *fname_start, *fname_end;
12061206

12071207
/*
12081208
Reference to a struct that contains information in various commands
@@ -1319,10 +1319,10 @@ struct st_lex_local: public st_lex
13191319

13201320
extern void lex_init(void);
13211321
extern void lex_free(void);
1322-
extern void lex_start(THD *thd, const uchar *buf, uint length);
1322+
extern void lex_start(THD *thd, const char *buf, uint length);
13231323
extern void lex_end(LEX *lex);
13241324
extern int MYSQLlex(void *arg, void *yythd);
1325-
extern const uchar *skip_rear_comments(const uchar *ubegin, const uchar *uend);
1325+
extern const char *skip_rear_comments(const char *ubegin, const char *uend);
13261326

13271327
extern bool is_lex_native_function(const LEX_STRING *name);
13281328

0 commit comments

Comments
 (0)