Commit 4006e958 authored by pem@mysql.com's avatar pem@mysql.com

Bugfixes for the sp_head memroot stuff.

parent 9f14ae75
......@@ -147,12 +147,15 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
lex_start(thd, (uchar*)defstr, strlen(defstr));
if (yyparse(thd) || thd->is_fatal_error || thd->lex->sphead == NULL)
{
if (thd->lex->sphead)
LEX *newlex= thd->lex;
sp_head *sp= newlex->sphead;
if (sp)
{
if (oldlex != thd->lex)
thd->lex->sphead->restore_lex(thd);
delete thd->lex->sphead;
thd->lex= NULL;
if (oldlex != newlex)
sp->restore_lex(thd);
delete sp;
newlex->sphead= NULL;
}
ret= SP_PARSE_ERROR;
}
......
......@@ -119,18 +119,27 @@ sp_head::operator delete(void *ptr, size_t size)
DBUG_VOID_RETURN;
}
sp_head::sp_head(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid)
: Sql_alloc(), m_simple_case(FALSE), m_multi_query(FALSE)
sp_head::sp_head()
: Sql_alloc(), m_simple_case(FALSE), m_multi_query(FALSE), m_free_list(NULL)
{
DBUG_ENTER("sp_head::sp_head");
m_backpatch.empty();
m_lex.empty();
DBUG_VOID_RETURN;
}
void
sp_head::init(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid)
{
DBUG_ENTER("sp_head::init");
const char *dstr = (const char*)lex->buf;
DBUG_PRINT("info", ("name: %s", name->str));
DBUG_PRINT("info", ("name: %*s", name->length, name->str));
m_name.length= name->length;
m_name.str= name->str;
m_name.str= lex->thd->strmake(name->str, name->length);
m_defstr.length= lex->end_of_query - lex->buf;
m_defstr.str= lex->thd->strmake(dstr, m_defstr.length);
m_free_list= NULL;
m_comment.length= 0;
m_comment.str= 0;
......@@ -141,10 +150,8 @@ sp_head::sp_head(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid)
}
m_suid= suid;
m_pcont= lex->spcont;
lex->spcont= m_pcont= new sp_pcontext();
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
m_backpatch.empty();
m_lex.empty();
DBUG_VOID_RETURN;
}
......
......@@ -60,7 +60,11 @@ class sp_head : public Sql_alloc
static void
operator delete(void *ptr, size_t size);
sp_head(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid);
sp_head();
// Initialize after we have reset mem_root
void
init(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid);
int
create(THD *thd);
......
......@@ -931,24 +931,27 @@ create:
| CREATE PROCEDURE ident
{
LEX *lex= Lex;
sp_head *sp;
if (lex->sphead)
{
net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE");
YYABORT;
}
lex->spcont= new sp_pcontext();
lex->sphead= new sp_head(&$3, lex, 0, 0);
lex->sphead->m_type= TYPE_ENUM_PROCEDURE;
/* Order is important here: new - reset - init */
sp= new sp_head();
sp->reset_thd_mem_root(YYTHD);
sp->init(&$3, lex, 0, 0);
sp->m_type= TYPE_ENUM_PROCEDURE;
lex->sphead= sp;
/*
* We have to turn of CLIENT_MULTI_QUERIES while parsing a
* stored procedure, otherwise yylex will chop it into pieces
* at each ';'.
*/
lex->sphead->m_old_cmq=
YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
lex->sphead->reset_thd_mem_root(YYTHD);
}
'(' sp_pdparam_list ')'
{
......@@ -982,24 +985,27 @@ create_function_tail:
| '('
{
LEX *lex= Lex;
sp_head *sp;
if (lex->sphead)
{
net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION");
YYABORT;
}
lex->spcont= new sp_pcontext();
lex->sphead= new sp_head(&lex->udf.name, lex, 0, 0);
lex->sphead->m_type= TYPE_ENUM_FUNCTION;
/* Order is important here: new - reset - init */
sp= new sp_head();
sp->reset_thd_mem_root(YYTHD);
sp->init(&lex->udf.name, lex, 0, 0);
sp->m_type= TYPE_ENUM_FUNCTION;
lex->sphead= sp;
/*
* We have to turn of CLIENT_MULTI_QUERIES while parsing a
* stored procedure, otherwise yylex will chop it into pieces
* at each ';'.
*/
lex->sphead->m_old_cmq=
YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
lex->sphead->reset_thd_mem_root(YYTHD);
}
sp_fdparam_list ')'
{
......
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