summaryrefslogtreecommitdiff
path: root/sql/sp_pcontext.h
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-04-23 19:39:57 +0300
committerMonty <monty@mariadb.org>2017-04-23 22:35:46 +0300
commit5a759d31f766087d5e135e1d3d3d987693bc9b88 (patch)
tree93c7359e8b211e269bfa73e5f595f34b9dca575a /sql/sp_pcontext.h
parentcba84469eb96481568a9f4ddf3f2989c49c9294c (diff)
downloadmariadb-git-5a759d31f766087d5e135e1d3d3d987693bc9b88.tar.gz
Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch: - Removed a lot of calls to strlen(), especially for field_string - Strings generated by parser are now const strings, less chance of accidently changing a string - Removed a lot of calls with LEX_STRING as parameter (changed to pointer) - More uniform code - Item::name_length was not kept up to date. Now fixed - Several bugs found and fixed (Access to null pointers, access of freed memory, wrong arguments to printf like functions) - Removed a lot of casts from (const char*) to (char*) Changes: - This caused some ABI changes - lex_string_set now uses LEX_CSTRING - Some fucntions are now taking const char* instead of char* - Create_field::change and after changed to LEX_CSTRING - handler::connect_string, comment and engine_name() changed to LEX_CSTRING - Checked printf() related calls to find bugs. Found and fixed several errors in old code. - A lot of changes from LEX_STRING to LEX_CSTRING, especially related to parsing and events. - Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING* - Some changes for char* to const char* - Added printf argument checking for my_snprintf() - Introduced null_clex_str, star_clex_string, temp_lex_str to simplify code - Added item_empty_name and item_used_name to be able to distingush between items that was given an empty name and items that was not given a name This is used in sql_yacc.yy to know when to give an item a name. - select table_name."*' is not anymore same as table_name.* - removed not used function Item::rename() - Added comparision of item->name_length before some calls to my_strcasecmp() to speed up comparison - Moved Item_sp_variable::make_field() from item.h to item.cc - Some minimal code changes to avoid copying to const char * - Fixed wrong error message in wsrep_mysql_parse() - Fixed wrong code in find_field_in_natural_join() where real_item() was set when it shouldn't - ER_ERROR_ON_RENAME was used with extra arguments. - Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already give the error. TODO: - Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c - Change code to not modify LEX_CSTRING for database name (as part of lower_case_table_names)
Diffstat (limited to 'sql/sp_pcontext.h')
-rw-r--r--sql/sp_pcontext.h86
1 files changed, 43 insertions, 43 deletions
diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h
index c6c8084fee2..841ea8526a5 100644
--- a/sql/sp_pcontext.h
+++ b/sql/sp_pcontext.h
@@ -41,7 +41,7 @@ public:
};
/// Name of the SP-variable.
- LEX_STRING name;
+ LEX_CSTRING name;
/// Mode of the SP-variable.
enum_mode mode;
@@ -65,11 +65,11 @@ public:
const Type_handler *type_handler() const { return field_def.type_handler(); }
public:
- sp_variable(LEX_STRING _name, uint _offset)
+ sp_variable(const LEX_CSTRING *name_arg, uint offset_arg)
:Sql_alloc(),
- name(_name),
+ name(*name_arg),
mode(MODE_IN),
- offset(_offset),
+ offset(offset_arg),
default_value(NULL)
{ }
/*
@@ -83,8 +83,8 @@ public:
with the given name, or a non-null pointer otherwise.
row_field_offset[0] is set only when the method returns !NULL.
*/
- const Spvar_definition *find_row_field(const LEX_STRING &var_name,
- const LEX_STRING &field_name,
+ const Spvar_definition *find_row_field(const LEX_CSTRING *var_name,
+ const LEX_CSTRING *field_name,
uint *row_field_offset);
};
@@ -117,7 +117,7 @@ public:
};
/// Name of the label.
- LEX_STRING name;
+ LEX_CSTRING name;
/// Instruction pointer of the label.
uint ip;
@@ -129,10 +129,10 @@ public:
class sp_pcontext *ctx;
public:
- sp_label(const LEX_STRING _name,
+ sp_label(const LEX_CSTRING *_name,
uint _ip, enum_type _type, sp_pcontext *_ctx)
:Sql_alloc(),
- name(_name),
+ name(*_name),
ip(_ip),
type(_type),
ctx(_ctx)
@@ -243,29 +243,29 @@ class sp_condition : public Sql_alloc
{
public:
/// Name of the condition.
- LEX_STRING name;
+ LEX_CSTRING name;
/// Value of the condition.
sp_condition_value *value;
public:
- sp_condition(const LEX_STRING _name, sp_condition_value *_value)
+ sp_condition(const LEX_CSTRING *name_arg, sp_condition_value *value_arg)
:Sql_alloc(),
- name(_name),
- value(_value)
+ name(*name_arg),
+ value(value_arg)
{ }
sp_condition(const char *name_arg, size_t name_length_arg,
sp_condition_value *value_arg)
:value(value_arg)
{
- name.str= (char *) name_arg;
+ name.str= name_arg;
name.length= name_length_arg;
}
- bool eq_name(const LEX_STRING str) const
+ bool eq_name(const LEX_CSTRING *str) const
{
return my_strnncoll(system_charset_info,
(const uchar *) name.str, name.length,
- (const uchar *) str.str, str.length) == 0;
+ (const uchar *) str->str, str->length) == 0;
}
};
@@ -288,14 +288,14 @@ public:
Note, m_param_context can be not NULL, but have no variables.
This is also means a cursor with no parameters (similar to NULL).
*/
-class sp_pcursor: public LEX_STRING
+class sp_pcursor: public LEX_CSTRING
{
class sp_pcontext *m_param_context; // Formal parameters
class sp_lex_cursor *m_lex; // The cursor statement LEX
public:
- sp_pcursor(const LEX_STRING &name, class sp_pcontext *param_ctx,
+ sp_pcursor(const LEX_CSTRING *name, class sp_pcontext *param_ctx,
class sp_lex_cursor *lex)
- :LEX_STRING(name), m_param_context(param_ctx), m_lex(lex)
+ :LEX_CSTRING(*name), m_param_context(param_ctx), m_lex(lex)
{ }
class sp_pcontext *param_context() const { return m_param_context; }
class sp_lex_cursor *lex() const { return m_lex; }
@@ -462,7 +462,7 @@ public:
/// @param name Name of the SP-variable.
///
/// @return instance of newly added SP-variable.
- sp_variable *add_variable(THD *thd, LEX_STRING name);
+ sp_variable *add_variable(THD *thd, const LEX_CSTRING *name);
/// Retrieve full type information about SP-variables in this parsing
/// context and its children.
@@ -481,7 +481,7 @@ public:
/// @param current_scope_only A flag if we search only in current scope.
///
/// @return instance of found SP-variable, or NULL if not found.
- sp_variable *find_variable(LEX_STRING name, bool current_scope_only) const;
+ sp_variable *find_variable(const LEX_CSTRING *name, bool current_scope_only) const;
/// Find SP-variable by the offset in the root parsing context.
///
@@ -524,28 +524,28 @@ public:
// Labels.
/////////////////////////////////////////////////////////////////////////
- sp_label *push_label(THD *thd, const LEX_STRING name, uint ip,
+ sp_label *push_label(THD *thd, const LEX_CSTRING *name, uint ip,
sp_label::enum_type type, List<sp_label> * list);
- sp_label *push_label(THD *thd, LEX_STRING name, uint ip,
- sp_label::enum_type type)
+ sp_label *push_label(THD *thd, const LEX_CSTRING *name, uint ip,
+ sp_label::enum_type type)
{ return push_label(thd, name, ip, type, &m_labels); }
- sp_label *push_goto_label(THD *thd, LEX_STRING name, uint ip,
- sp_label::enum_type type)
+ sp_label *push_goto_label(THD *thd, const LEX_CSTRING *name, uint ip,
+ sp_label::enum_type type)
{ return push_label(thd, name, ip, type, &m_goto_labels); }
- sp_label *push_label(THD *thd, const LEX_STRING name, uint ip)
+ sp_label *push_label(THD *thd, const LEX_CSTRING *name, uint ip)
{ return push_label(thd, name, ip, sp_label::IMPLICIT); }
- sp_label *push_goto_label(THD *thd, const LEX_STRING name, uint ip)
+ sp_label *push_goto_label(THD *thd, const LEX_CSTRING *name, uint ip)
{ return push_goto_label(thd, name, ip, sp_label::GOTO); }
- sp_label *find_label(const LEX_STRING name);
+ sp_label *find_label(const LEX_CSTRING *name);
- sp_label *find_goto_label(const LEX_STRING name, bool recusive);
+ sp_label *find_goto_label(const LEX_CSTRING *name, bool recusive);
- sp_label *find_goto_label(const LEX_STRING name)
+ sp_label *find_goto_label(const LEX_CSTRING *name)
{ return find_goto_label(name, true); }
sp_label *find_label_current_loop_start();
@@ -568,12 +568,12 @@ public:
sp_label *pop_label()
{ return m_labels.pop(); }
- bool block_label_declare(LEX_STRING label)
+ bool block_label_declare(LEX_CSTRING *label)
{
sp_label *lab= find_label(label);
if (lab)
{
- my_error(ER_SP_LABEL_REDEFINE, MYF(0), label.str);
+ my_error(ER_SP_LABEL_REDEFINE, MYF(0), label->str);
return true;
}
return false;
@@ -583,15 +583,15 @@ public:
// Conditions.
/////////////////////////////////////////////////////////////////////////
- bool add_condition(THD *thd, const LEX_STRING name,
+ bool add_condition(THD *thd, const LEX_CSTRING *name,
sp_condition_value *value);
/// See comment for find_variable() above.
- sp_condition_value *find_condition(const LEX_STRING name,
+ sp_condition_value *find_condition(const LEX_CSTRING *name,
bool current_scope_only) const;
sp_condition_value *
- find_declared_or_predefined_condition(const LEX_STRING name) const
+ find_declared_or_predefined_condition(const LEX_CSTRING *name) const
{
sp_condition_value *p= find_condition(name, false);
if (p)
@@ -599,12 +599,12 @@ public:
return find_predefined_condition(name);
}
- bool declare_condition(THD *thd, const LEX_STRING name,
+ bool declare_condition(THD *thd, const LEX_CSTRING *name,
sp_condition_value *val)
{
if (find_condition(name, true))
{
- my_error(ER_SP_DUP_COND, MYF(0), name.str);
+ my_error(ER_SP_DUP_COND, MYF(0), name->str);
return true;
}
return add_condition(thd, name, val);
@@ -646,21 +646,21 @@ public:
// Cursors.
/////////////////////////////////////////////////////////////////////////
- bool add_cursor(const LEX_STRING name, sp_pcontext *param_ctx,
+ bool add_cursor(const LEX_CSTRING *name, sp_pcontext *param_ctx,
class sp_lex_cursor *lex);
/// See comment for find_variable() above.
- const sp_pcursor *find_cursor(const LEX_STRING name,
+ const sp_pcursor *find_cursor(const LEX_CSTRING *name,
uint *poff, bool current_scope_only) const;
- const sp_pcursor *find_cursor_with_error(const LEX_STRING name,
+ const sp_pcursor *find_cursor_with_error(const LEX_CSTRING *name,
uint *poff,
bool current_scope_only) const
{
const sp_pcursor *pcursor= find_cursor(name, poff, current_scope_only);
if (!pcursor)
{
- my_error(ER_SP_CURSOR_MISMATCH, MYF(0), name.str);
+ my_error(ER_SP_CURSOR_MISMATCH, MYF(0), name->str);
return NULL;
}
return pcursor;
@@ -704,7 +704,7 @@ private:
sp_pcontext(const sp_pcontext &);
void operator=(sp_pcontext &);
- sp_condition_value *find_predefined_condition(const LEX_STRING name) const;
+ sp_condition_value *find_predefined_condition(const LEX_CSTRING *name) const;
private:
/// m_max_var_index -- number of variables (including all types of arguments)