Commit 495c32d9 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-31972 Change parameter of make_sp_name*() from LEX_CSTRING to Lex_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.
parent b956a6a2
......@@ -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;
}
......@@ -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, '.')))
......@@ -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;
}
......@@ -9291,7 +9291,7 @@ 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);
}
......@@ -9299,7 +9299,7 @@ bool LEX::call_statement_start(THD *thd, const Lex_ident_sys_st *name)
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);
}
......
......@@ -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,
......
......@@ -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;
}
;
......@@ -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;
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment