Skip to content

Commit

Permalink
MDEV-31972 Change parameter of make_sp_name*() from LEX_CSTRING to Le…
Browse files Browse the repository at this point in the history
…x_ident_sys_st

Changing LEX_CSTRING* parameters of LEX::make_sp_name() to Lex_ident_sys_st.

This makes the code clear because a value of Lex_ident_sys_st has
some guaranteed additional constraints over a base LEX_CSTRING:

- Its LEX_CSTRING::str is not NULL (sql_yacc.yy would abort otherwise)
- Its LEX_CSTRING::str is 0-terminated
- Its a valid utf8 string
- The string pointed by LEX_CSTRING::str was created on THD::mem_root

Also changing "pass by pointer" to "pass by reference",
as these parameters can never be NULL - they are Bison stack variables.
  • Loading branch information
abarkov committed Aug 21, 2023
1 parent b956a6a commit 495c32d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
28 changes: 14 additions & 14 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7346,13 +7346,13 @@ bool LEX::sp_block_finalize(THD *thd, const Lex_spblock_st spblock,
}


sp_name *LEX::make_sp_name(THD *thd, const LEX_CSTRING *name)
sp_name *LEX::make_sp_name(THD *thd, const Lex_ident_sys_st &name)
{
sp_name *res;
LEX_CSTRING db;
if (unlikely(check_routine_name(name)) ||
if (unlikely(check_routine_name(&name)) ||
unlikely(copy_db_to(&db)) ||
unlikely((!(res= new (thd->mem_root) sp_name(&db, name, false)))))
unlikely((!(res= new (thd->mem_root) sp_name(&db, &name, false)))))
return NULL;
return res;
}
Expand All @@ -7371,7 +7371,8 @@ sp_name *LEX::make_sp_name(THD *thd, const LEX_CSTRING *name)
b. package 'p1' + routine 'p1.p1'
m_name='p1.p1.p1' will always mean (a).
*/
sp_name *LEX::make_sp_name_package_routine(THD *thd, const LEX_CSTRING *name)
sp_name *LEX::make_sp_name_package_routine(THD *thd,
const Lex_ident_sys_st &name)
{
sp_name *res= make_sp_name(thd, name);
if (likely(res) && unlikely(strchr(res->m_name.str, '.')))
Expand All @@ -7383,21 +7384,20 @@ sp_name *LEX::make_sp_name_package_routine(THD *thd, const LEX_CSTRING *name)
}


sp_name *LEX::make_sp_name(THD *thd, const LEX_CSTRING *name1,
const LEX_CSTRING *name2)
sp_name *LEX::make_sp_name(THD *thd, const Lex_ident_sys_st &name1,
const Lex_ident_sys_st &name2)
{
DBUG_ASSERT(name1.str);
sp_name *res;
LEX_CSTRING norm_name1;
if (unlikely(!name1->str) ||
unlikely(!thd->make_lex_string(&norm_name1, name1->str,
name1->length)) ||
if (unlikely(!thd->make_lex_string(&norm_name1, name1.str, name1.length)) ||
unlikely(check_db_name((LEX_STRING *) &norm_name1)))
{
my_error(ER_WRONG_DB_NAME, MYF(0), name1->str);
my_error(ER_WRONG_DB_NAME, MYF(0), name1.str);
return NULL;
}
if (unlikely(check_routine_name(name2)) ||
unlikely(!(res= new (thd->mem_root) sp_name(&norm_name1, name2, true))))
if (unlikely(check_routine_name(&name2)) ||
unlikely(!(res= new (thd->mem_root) sp_name(&norm_name1, &name2, true))))
return NULL;
return res;
}
Expand Down Expand Up @@ -9291,15 +9291,15 @@ bool LEX::call_statement_start(THD *thd, sp_name *name)

bool LEX::call_statement_start(THD *thd, const Lex_ident_sys_st *name)
{
sp_name *spname= make_sp_name(thd, name);
sp_name *spname= make_sp_name(thd, *name);
return unlikely(!spname) || call_statement_start(thd, spname);
}


bool LEX::call_statement_start(THD *thd, const Lex_ident_sys_st *name1,
const Lex_ident_sys_st *name2)
{
sp_name *spname= make_sp_name(thd, name1, name2);
sp_name *spname= make_sp_name(thd, *name1, *name2);
return unlikely(!spname) || call_statement_start(thd, spname);
}

Expand Down
9 changes: 5 additions & 4 deletions sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -3908,10 +3908,11 @@ struct LEX: public Query_tables_list
Item *val);
bool set_user_variable(THD *thd, const LEX_CSTRING *name, Item *val);
void set_stmt_init();
sp_name *make_sp_name(THD *thd, const LEX_CSTRING *name);
sp_name *make_sp_name(THD *thd, const LEX_CSTRING *name1,
const LEX_CSTRING *name2);
sp_name *make_sp_name_package_routine(THD *thd, const LEX_CSTRING *name);
sp_name *make_sp_name(THD *thd, const Lex_ident_sys_st &name);
sp_name *make_sp_name(THD *thd, const Lex_ident_sys_st &name1,
const Lex_ident_sys_st &name2);
sp_name *make_sp_name_package_routine(THD *thd,
const Lex_ident_sys_st &name);
sp_head *make_sp_head(THD *thd, const sp_name *name, const Sp_handler *sph,
enum_sp_aggregate_type agg_type);
sp_head *make_sp_head_no_recursive(THD *thd, const sp_name *name,
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -3016,12 +3016,12 @@ sp_handler:
sp_name:
ident '.' ident
{
if (unlikely(!($$= Lex->make_sp_name(thd, &$1, &$3))))
if (unlikely(!($$= Lex->make_sp_name(thd, $1, $3))))
MYSQL_YYABORT;
}
| ident
{
if (unlikely(!($$= Lex->make_sp_name(thd, &$1))))
if (unlikely(!($$= Lex->make_sp_name(thd, $1))))
MYSQL_YYABORT;
}
;
Expand Down Expand Up @@ -19098,7 +19098,7 @@ package_specification_function:
{
DBUG_ASSERT($1->sphead->get_package());
$2->sql_command= SQLCOM_CREATE_FUNCTION;
sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
sp_name *spname= $1->make_sp_name_package_routine(thd, $3);
if (unlikely(!spname))
MYSQL_YYABORT;
thd->lex= $2;
Expand All @@ -19125,7 +19125,7 @@ package_specification_procedure:
{
DBUG_ASSERT($1->sphead->get_package());
$2->sql_command= SQLCOM_CREATE_PROCEDURE;
sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
sp_name *spname= $1->make_sp_name_package_routine(thd, $3);
if (unlikely(!spname))
MYSQL_YYABORT;
thd->lex= $2;
Expand Down

0 comments on commit 495c32d

Please sign in to comment.