summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2019-07-18 03:15:55 +1000
committerNikita Malyavin <nikitamalyavin@gmail.com>2021-04-06 21:32:43 +0300
commitbfe08f36df339935a92a02ff98750f6ab9dffe47 (patch)
tree4ffcc19d800e3a0933c867f4e412b76a9c3635f3
parent01ab3db8c739ecc14491fc602a19a5f9daf5b98b (diff)
downloadmariadb-git-bb-10.3-nikita-old.tar.gz
add const qualifiers to sys_var::value_ptr functions and fix const castsbb-10.3-nikita-old
This is important since Sys_var_typelib and its descendants return pointers to constant symbols from *_value_ptr, which are situated in write-protected-memory. * functions const-qualified: - value_ptr - session_value_ptr - global_value_ptr - default_value_ptr - Sys_var_vers_asof::value_ptr - other minor private ones * remove C-style typecasts when it discards qualifiers
-rw-r--r--sql/item_func.cc16
-rw-r--r--sql/set_var.cc16
-rw-r--r--sql/set_var.h16
-rw-r--r--sql/sql_plugin.cc24
-rw-r--r--sql/sql_show.cc70
-rw-r--r--sql/sys_vars.cc36
-rw-r--r--sql/sys_vars.ic182
7 files changed, 197 insertions, 163 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index a6d9ecc1d2f..8f55e2c266b 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -5657,7 +5657,7 @@ void Item_func_get_system_var::update_null_value()
bool Item_func_get_system_var::fix_length_and_dec()
{
- char *cptr;
+ const char *cptr;
maybe_null= TRUE;
max_length= 0;
@@ -5691,9 +5691,12 @@ bool Item_func_get_system_var::fix_length_and_dec()
case SHOW_CHAR:
case SHOW_CHAR_PTR:
mysql_mutex_lock(&LOCK_global_system_variables);
- cptr= var->show_type() == SHOW_CHAR ?
- (char*) var->value_ptr(current_thd, var_type, &component) :
- *(char**) var->value_ptr(current_thd, var_type, &component);
+ cptr= var->show_type() == SHOW_CHAR ?
+ reinterpret_cast<const char*>(var->value_ptr(current_thd, var_type,
+ &component)) :
+ *reinterpret_cast<const char* const*>(var->value_ptr(current_thd,
+ var_type,
+ &component));
if (cptr)
max_length= (uint32)system_charset_info->cset->numchars(system_charset_info,
cptr,
@@ -5706,7 +5709,10 @@ bool Item_func_get_system_var::fix_length_and_dec()
case SHOW_LEX_STRING:
{
mysql_mutex_lock(&LOCK_global_system_variables);
- LEX_STRING *ls= ((LEX_STRING*)var->value_ptr(current_thd, var_type, &component));
+ const LEX_STRING *ls=
+ reinterpret_cast<const LEX_STRING*>(var->value_ptr(current_thd,
+ var_type,
+ &component));
max_length= (uint32)system_charset_info->cset->numchars(system_charset_info,
ls->str,
ls->str + ls->length);
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 58b6b392449..cc44dbe401b 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -233,12 +233,12 @@ bool sys_var::update(THD *thd, set_var *var)
}
}
-uchar *sys_var::session_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *sys_var::session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return session_var_ptr(thd);
}
-uchar *sys_var::global_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *sys_var::global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return global_var_ptr();
}
@@ -271,8 +271,8 @@ bool sys_var::check(THD *thd, set_var *var)
return false;
}
-uchar *sys_var::value_ptr(THD *thd, enum_var_type type,
- const LEX_CSTRING *base)
+const uchar *sys_var::value_ptr(THD *thd, enum_var_type type,
+ const LEX_CSTRING *base) const
{
DBUG_ASSERT(base);
if (type == OPT_GLOBAL || scope() == GLOBAL)
@@ -510,7 +510,7 @@ bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v)
return false;
}
-CHARSET_INFO *sys_var::charset(THD *thd)
+CHARSET_INFO *sys_var::charset(THD *thd) const
{
return is_os_charset ? thd->variables.character_set_filesystem :
system_charset_info;
@@ -1047,7 +1047,7 @@ int set_var_collation_client::update(THD *thd)
INFORMATION_SCHEMA.SYSTEM_VARIABLES
*****************************************************************************/
static void store_value_ptr(Field *field, sys_var *var, String *str,
- uchar *value_ptr)
+ const uchar *value_ptr)
{
field->set_notnull();
str= var->val_str_nolock(str, field->table->in_use, value_ptr);
@@ -1115,8 +1115,8 @@ int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond)
fields[3]->store(origin->str, origin->length, scs);
// DEFAULT_VALUE
- uchar *def= var->is_readonly() && var->option.id < 0
- ? 0 : var->default_value_ptr(thd);
+ const uchar *def= var->is_readonly() && var->option.id < 0
+ ? 0 : var->default_value_ptr(thd);
if (def)
store_value_ptr(fields[4], var, &strbuf, def);
diff --git a/sql/set_var.h b/sql/set_var.h
index 6e84c0bd09c..1c02cdcc6e5 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -112,7 +112,7 @@ public:
virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
bool check(THD *thd, set_var *var);
- uchar *value_ptr(THD *thd, enum_var_type type, const LEX_CSTRING *base);
+ const uchar *value_ptr(THD *thd, enum_var_type type, const LEX_CSTRING *base) const;
/**
Update the system variable with the default value from either
@@ -127,9 +127,9 @@ public:
String *val_str(String *str, THD *thd, enum_var_type type, const LEX_CSTRING *base);
double val_real(bool *is_null, THD *thd, enum_var_type type, const LEX_CSTRING *base);
- SHOW_TYPE show_type() { return show_val_type; }
+ SHOW_TYPE show_type() const { return show_val_type; }
int scope() const { return flags & SCOPE_MASK; }
- CHARSET_INFO *charset(THD *thd);
+ CHARSET_INFO *charset(THD *thd) const;
bool is_readonly() const { return flags & READONLY; }
/**
the following is only true for keycache variables,
@@ -208,7 +208,7 @@ public:
*/
virtual bool session_is_default(THD *thd) { return false; }
- virtual uchar *default_value_ptr(THD *thd)
+ virtual const uchar *default_value_ptr(THD *thd) const
{ return (uchar*)&option.def_value; }
private:
@@ -230,18 +230,18 @@ protected:
It must be of show_val_type type (my_bool for SHOW_MY_BOOL,
int for SHOW_INT, longlong for SHOW_LONGLONG, etc).
*/
- virtual uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base);
- virtual uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
+ virtual const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const;
+ virtual const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
/**
A pointer to a storage area of the variable, to the raw data.
Typically it's the same as session_value_ptr(), but it's different,
for example, for ENUM, that is printed as a string, but stored as a number.
*/
- uchar *session_var_ptr(THD *thd)
+ uchar *session_var_ptr(THD *thd) const
{ return ((uchar*)&(thd->variables)) + offset; }
- uchar *global_var_ptr()
+ uchar *global_var_ptr() const
{ return ((uchar*)&global_system_variables) + offset; }
void *max_var_ptr()
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index ffb7d747537..32ba1d1ea6a 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -293,14 +293,14 @@ public:
sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
st_plugin_int *p, st_mysql_sys_var *plugin_var_arg);
sys_var_pluginvar *cast_pluginvar() { return this; }
- uchar* real_value_ptr(THD *thd, enum_var_type type);
- TYPELIB* plugin_var_typelib(void);
- uchar* do_value_ptr(THD *thd, enum_var_type type, const LEX_CSTRING *base);
- uchar* session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ uchar* real_value_ptr(THD *thd, enum_var_type type) const;
+ TYPELIB* plugin_var_typelib(void) const;
+ const uchar* do_value_ptr(THD *thd, enum_var_type type, const LEX_CSTRING *base) const;
+ const uchar* session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return do_value_ptr(thd, OPT_SESSION, base); }
- uchar* global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar* global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return do_value_ptr(thd, OPT_GLOBAL, base); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return do_value_ptr(thd, OPT_DEFAULT, 0); }
bool do_check(THD *thd, set_var *var);
virtual void session_save_default(THD *thd, set_var *var) {}
@@ -3349,7 +3349,7 @@ sys_var_pluginvar::sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
plugin_opt_set_limits(&option, pv);
}
-uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
+uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type) const
{
if (type == OPT_DEFAULT)
{
@@ -3423,7 +3423,7 @@ bool sys_var_pluginvar::session_is_default(THD *thd)
}
-TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
+TYPELIB* sys_var_pluginvar::plugin_var_typelib(void) const
{
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
case PLUGIN_VAR_ENUM:
@@ -3441,12 +3441,10 @@ TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
}
-uchar* sys_var_pluginvar::do_value_ptr(THD *thd, enum_var_type type,
- const LEX_CSTRING *base)
+const uchar* sys_var_pluginvar::do_value_ptr(THD *thd, enum_var_type type,
+ const LEX_CSTRING *base) const
{
- uchar* result;
-
- result= real_value_ptr(thd, type);
+ const uchar* result= real_value_ptr(thd, type);
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 6b020f65c8c..cb7e8c242d0 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3555,6 +3555,28 @@ void remove_status_vars(SHOW_VAR *list)
}
}
+/**
+ A union holding a pointer to a type that can be referred by a status variable.
+ */
+union Any_pointer {
+ const void *as_void;
+ const uchar *as_uchar;
+ const char *as_char;
+ const char ** as_charptr;
+ const double *as_double;
+ const int * as_int;
+ const uint * as_uint;
+ const long *as_long;
+ const longlong *as_longlong;
+ const bool *as_bool;
+ const my_bool *as_my_bool;
+ const sys_var *as_sys_var;
+ const system_status_var *as_system_status_var;
+ const ha_rows *as_ha_rows;
+ const LEX_STRING *as_lex_cstring;
+ const SHOW_COMP_OPTION *as_show_comp_options;
+ intptr as_intptr;
+};
/**
@brief Returns the value of a system or a status variable.
@@ -3579,16 +3601,18 @@ const char* get_one_variable(THD *thd,
const CHARSET_INFO **charset, char *buff,
size_t *length)
{
- void *value= variable->value;
+ Any_pointer value, status_var_value;
+ value.as_void= variable->value;
+ status_var_value.as_system_status_var= status_var;
const char *pos= buff;
const char *end= buff;
if (show_type == SHOW_SYS)
{
- sys_var *var= (sys_var *) value;
+ const sys_var *var= value.as_sys_var;
show_type= var->show_type();
- value= var->value_ptr(thd, value_type, &null_clex_str);
+ value.as_uchar= var->value_ptr(thd, value_type, &null_clex_str);
*charset= var->charset(thd);
}
@@ -3598,66 +3622,65 @@ const char* get_one_variable(THD *thd,
*/
switch (show_type) {
case SHOW_DOUBLE_STATUS:
- value= ((char *) status_var + (intptr) value);
+ value.as_char= status_var_value.as_char + value.as_intptr;
/* fall through */
case SHOW_DOUBLE:
/* 6 is the default precision for '%f' in sprintf() */
- end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
+ end= buff + my_fcvt(*value.as_double, 6, buff, NULL);
break;
case SHOW_LONG_STATUS:
- value= ((char *) status_var + (intptr) value);
+ value.as_char= status_var_value.as_char + value.as_intptr;
/* fall through */
case SHOW_ULONG:
case SHOW_LONG_NOFLUSH: // the difference lies in refresh_status()
- end= int10_to_str(*(long*) value, buff, 10);
+ end= int10_to_str(*value.as_long, buff, 10);
break;
case SHOW_LONGLONG_STATUS:
- value= ((char *) status_var + (intptr) value);
+ value.as_char= status_var_value.as_char + value.as_intptr;
/* fall through */
case SHOW_ULONGLONG:
- end= longlong10_to_str(*(longlong*) value, buff, 10);
+ end= longlong10_to_str(*value.as_longlong, buff, 10);
break;
case SHOW_HA_ROWS:
- end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10);
+ end= longlong10_to_str((longlong) *value.as_ha_rows, buff, 10);
break;
case SHOW_BOOL:
- end= strmov(buff, *(bool*) value ? "ON" : "OFF");
+ end= strmov(buff, *value.as_bool ? "ON" : "OFF");
break;
case SHOW_MY_BOOL:
- end= strmov(buff, *(my_bool*) value ? "ON" : "OFF");
+ end= strmov(buff, *value.as_my_bool ? "ON" : "OFF");
break;
case SHOW_UINT32_STATUS:
- value= ((char *) status_var + (intptr) value);
+ value.as_char= status_var_value.as_char + value.as_intptr;
/* fall through */
case SHOW_UINT:
- end= int10_to_str((long) *(uint*) value, buff, 10);
+ end= int10_to_str((long) *value.as_uint, buff, 10);
break;
case SHOW_SINT:
- end= int10_to_str((long) *(int*) value, buff, -10);
+ end= int10_to_str((long) *value.as_int, buff, -10);
break;
case SHOW_SLONG:
- end= int10_to_str(*(long*) value, buff, -10);
+ end= int10_to_str(*value.as_long, buff, -10);
break;
case SHOW_SLONGLONG:
- end= longlong10_to_str(*(longlong*) value, buff, -10);
+ end= longlong10_to_str(*value.as_longlong, buff, -10);
break;
case SHOW_HAVE:
{
- SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
- pos= show_comp_option_name[(int) tmp];
+ pos= show_comp_option_name[(int) *value.as_show_comp_options];
end= strend(pos);
break;
}
case SHOW_CHAR:
{
- if (!(pos= (char*)value))
+ if (!(pos= value.as_char))
pos= "";
end= strend(pos);
break;
}
case SHOW_CHAR_PTR:
{
- if (!(pos= *(char**) value))
+ if (!(pos= *value.as_charptr))
pos= "";
end= strend(pos);
@@ -3665,11 +3688,10 @@ const char* get_one_variable(THD *thd,
}
case SHOW_LEX_STRING:
{
- LEX_STRING *ls=(LEX_STRING*)value;
- if (!(pos= ls->str))
+ if (!(pos= value.as_lex_cstring->str))
end= pos= "";
else
- end= pos + ls->length;
+ end= pos + value.as_lex_cstring->length;
break;
}
case SHOW_UNDEF:
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 554591cea4b..f873fd224fc 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -1702,8 +1702,9 @@ static Sys_var_gtid_binlog_pos Sys_gtid_binlog_pos(
READ_ONLY GLOBAL_VAR(opt_gtid_binlog_pos_dummy), NO_CMD_LINE);
-uchar *
-Sys_var_gtid_binlog_pos::global_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *
+Sys_var_gtid_binlog_pos::global_value_ptr(THD *thd,
+ const LEX_CSTRING *base) const
{
char buf[128];
String str(buf, sizeof(buf), system_charset_info);
@@ -1730,8 +1731,9 @@ static Sys_var_gtid_current_pos Sys_gtid_current_pos(
READ_ONLY GLOBAL_VAR(opt_gtid_current_pos_dummy), NO_CMD_LINE);
-uchar *
-Sys_var_gtid_current_pos::global_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *
+Sys_var_gtid_current_pos::global_value_ptr(THD *thd,
+ const LEX_CSTRING *base) const
{
String str;
char *p;
@@ -1811,8 +1813,9 @@ Sys_var_gtid_slave_pos::global_update(THD *thd, set_var *var)
}
-uchar *
-Sys_var_gtid_slave_pos::global_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *
+Sys_var_gtid_slave_pos::global_value_ptr(THD *thd,
+ const LEX_CSTRING *base) const
{
String str;
char *p;
@@ -1932,8 +1935,9 @@ Sys_var_gtid_binlog_state::global_update(THD *thd, set_var *var)
}
-uchar *
-Sys_var_gtid_binlog_state::global_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *
+Sys_var_gtid_binlog_state::global_value_ptr(THD *thd,
+ const LEX_CSTRING *base) const
{
char buf[512];
String str(buf, sizeof(buf), system_charset_info);
@@ -1967,8 +1971,8 @@ static Sys_var_last_gtid Sys_last_gtid(
export sys_var *Sys_last_gtid_ptr= &Sys_last_gtid; // for check changing
-uchar *
-Sys_var_last_gtid::session_value_ptr(THD *thd, const LEX_CSTRING *base)
+const uchar *
+Sys_var_last_gtid::session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
char buf[10+1+10+1+20+1];
String str(buf, sizeof(buf), system_charset_info);
@@ -2119,9 +2123,10 @@ Sys_var_slave_parallel_mode::global_update(THD *thd, set_var *var)
}
-uchar *
+const uchar *
Sys_var_slave_parallel_mode::global_value_ptr(THD *thd,
- const LEX_CSTRING *base_name)
+ const
+ LEX_CSTRING *base_name) const
{
Master_info *mi;
enum_slave_parallel_mode val=
@@ -4950,8 +4955,9 @@ bool Sys_var_rpl_filter::set_filter_value(const char *value, Master_info *mi)
return status;
}
-uchar *Sys_var_rpl_filter::global_value_ptr(THD *thd,
- const LEX_CSTRING *base_name)
+const uchar *
+Sys_var_rpl_filter::global_value_ptr(THD *thd,
+ const LEX_CSTRING *base_name) const
{
char buf[256];
String tmp(buf, sizeof(buf), &my_charset_bin);
@@ -5063,7 +5069,7 @@ static Sys_var_uint Sys_slave_net_timeout(
*/
ulonglong Sys_var_multi_source_ulonglong::
-get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset)
+get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset) const
{
Master_info *mi;
ulonglong res= 0; // Default value
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index bcdfaf5697b..5757186e6f2 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -223,7 +223,7 @@ public:
{ var->save_result.ulonglong_value= option.def_value; }
private:
T get_max_var() { return *((T*) max_var_ptr()); }
- uchar *default_value_ptr(THD *thd) { return (uchar*) &option.def_value; }
+ const uchar *default_value_ptr(THD *thd) const { return (uchar*) &option.def_value; }
};
typedef Sys_var_integer<int, GET_INT, SHOW_SINT> Sys_var_int;
@@ -234,25 +234,25 @@ typedef Sys_var_integer<ulonglong, GET_ULL, SHOW_ULONGLONG> Sys_var_ulonglong;
typedef Sys_var_integer<long, GET_LONG, SHOW_SLONG> Sys_var_long;
-template<> uchar *Sys_var_int::default_value_ptr(THD *thd)
+template<> const uchar *Sys_var_int::default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.int_value= (int)option.def_value;
return (uchar*) &thd->sys_var_tmp.int_value;
}
-template<> uchar *Sys_var_uint::default_value_ptr(THD *thd)
+template<> const uchar *Sys_var_uint::default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.uint_value= (uint)option.def_value;
return (uchar*) &thd->sys_var_tmp.uint_value;
}
-template<> uchar *Sys_var_long::default_value_ptr(THD *thd)
+template<> const uchar *Sys_var_long::default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.long_value= (long)option.def_value;
return (uchar*) &thd->sys_var_tmp.long_value;
}
-template<> uchar *Sys_var_ulong::default_value_ptr(THD *thd)
+template<> const uchar *Sys_var_ulong::default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.ulong_value= (ulong)option.def_value;
return (uchar*) &thd->sys_var_tmp.ulong_value;
@@ -382,13 +382,13 @@ public:
{ var->save_result.ulonglong_value= global_var(ulong); }
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
- uchar *valptr(THD *thd, ulong val)
- { return (uchar*)typelib.type_names[val]; }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *valptr(THD *thd, ulong val) const
+ { return reinterpret_cast<const uchar*>(typelib.type_names[val]); }
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, ulong)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(ulong)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, (ulong)option.def_value); }
ulong get_max_var() { return *((ulong *) max_var_ptr()); }
@@ -436,7 +436,7 @@ public:
{ var->save_result.ulonglong_value= (ulonglong)*(my_bool *)global_value_ptr(thd, 0); }
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.my_bool_value=(my_bool) option.def_value;
return (uchar*) &thd->sys_var_tmp.my_bool_value;
@@ -681,7 +681,7 @@ public:
void global_save_default(THD *thd, set_var *var)
{ DBUG_ASSERT(FALSE); }
protected:
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return thd->security_ctx->proxy_user[0] ?
(uchar *) &(thd->security_ctx->proxy_user[0]) : NULL;
@@ -697,7 +697,7 @@ public:
{}
protected:
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return (uchar*)thd->security_ctx->external_user;
}
@@ -741,7 +741,7 @@ public:
bool global_update(THD *thd, set_var *var);
protected:
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
bool set_filter_value(const char *value, Master_info *mi);
};
@@ -859,7 +859,7 @@ public:
{
DBUG_ASSERT(FALSE);
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(FALSE);
return NULL;
@@ -937,19 +937,19 @@ public:
var->save_result.string_value.str= ptr;
var->save_result.string_value.length= safe_strlen(ptr);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
char buf[256];
DBUG_EXPLAIN(buf, sizeof(buf));
return (uchar*) thd->strdup(buf);
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
char buf[256];
DBUG_EXPLAIN_INITIAL(buf, sizeof(buf));
return (uchar*) thd->strdup(buf);
}
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return (uchar*)""; }
};
#endif
@@ -1025,7 +1025,7 @@ public:
return keycache_update(thd, key_cache, offset, new_value);
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
KEY_CACHE *key_cache= get_key_cache(base);
if (!key_cache)
@@ -1210,7 +1210,7 @@ public:
lock, binlog_status_arg, on_check_func, on_update_func,
substitute)
{ }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
if (thd->user_connect && thd->user_connect->user_resources.user_conn)
return (uchar*) &(thd->user_connect->user_resources.user_conn);
@@ -1322,13 +1322,13 @@ public:
{ var->save_result.ulonglong_value= global_var(ulonglong); }
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
- uchar *valptr(THD *thd, ulonglong val)
+ const uchar *valptr(THD *thd, ulonglong val) const
{ return (uchar*)flagset_to_string(thd, 0, val, typelib.type_names); }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, ulonglong)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(ulonglong)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, option.def_value); }
};
@@ -1436,13 +1436,13 @@ public:
{ var->save_result.ulonglong_value= global_var(ulonglong); }
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
- uchar *valptr(THD *thd, ulonglong val)
- { return (uchar*)set_to_string(thd, 0, val, typelib.type_names); }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *valptr(THD *thd, ulonglong val) const
+ { return reinterpret_cast<const uchar*>(set_to_string(thd, 0, val, typelib.type_names)); }
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, ulonglong)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(ulonglong)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, option.def_value); }
ulonglong get_max_var() { return *((ulonglong*) max_var_ptr()); }
@@ -1539,7 +1539,7 @@ public:
plugin_ref plugin= global_var(plugin_ref);
var->save_result.plugin= plugin ? my_plugin_lock(thd, plugin) : 0;
}
- plugin_ref get_default(THD *thd)
+ plugin_ref get_default(THD *thd) const
{
char *default_value= *reinterpret_cast<char**>(option.def_value);
if (!default_value)
@@ -1561,16 +1561,16 @@ public:
var->save_result.plugin= get_default(thd);
}
- uchar *valptr(THD *thd, plugin_ref plugin)
+ uchar *valptr(THD *thd, plugin_ref plugin) const
{
return (uchar*)(plugin ? thd->strmake(plugin_name(plugin)->str,
plugin_name(plugin)->length) : 0);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, plugin_ref)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(plugin_ref)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, get_default(thd)); }
};
@@ -1657,7 +1657,7 @@ public:
plugin_ref* plugins= global_var(plugin_ref *);
var->save_result.plugins= plugins ? temp_copy_engine_list(thd, plugins) : 0;
}
- plugin_ref *get_default(THD *thd)
+ plugin_ref *get_default(THD *thd) const
{
char *default_value= *reinterpret_cast<char**>(option.def_value);
if (!default_value)
@@ -1671,15 +1671,15 @@ public:
var->save_result.plugins= get_default(thd);
}
- uchar *valptr(THD *thd, plugin_ref *plugins)
+ uchar *valptr(THD *thd, plugin_ref *plugins) const
{
- return (uchar*)pretty_print_engine_list(thd, plugins);
+ return reinterpret_cast<uchar*>(pretty_print_engine_list(thd, plugins));
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, plugin_ref*)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(plugin_ref*)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, get_default(thd)); }
};
@@ -1743,16 +1743,16 @@ public:
{
DBUG_ASSERT(FALSE);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return debug_sync_value_ptr(thd);
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(FALSE);
return 0;
}
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return (uchar*)""; }
};
#endif /* defined(ENABLED_DEBUG_SYNC) */
@@ -1828,16 +1828,16 @@ public:
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
- uchar *valptr(THD *thd, ulonglong val)
+ uchar *valptr(THD *thd, ulonglong val) const
{
thd->sys_var_tmp.my_bool_value= (reverse_semantics == !(val & bitmask));
return (uchar*) &thd->sys_var_tmp.my_bool_value;
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, ulonglong)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(ulonglong)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.my_bool_value= option.def_value != 0;
return (uchar*) &thd->sys_var_tmp.my_bool_value;
@@ -1896,17 +1896,17 @@ public:
{ var->value= 0; }
void global_save_default(THD *thd, set_var *var)
{ DBUG_ASSERT(FALSE); }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
thd->sys_var_tmp.ulonglong_value= read_func(thd);
return (uchar*) &thd->sys_var_tmp.ulonglong_value;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(FALSE);
return 0;
}
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.ulonglong_value= 0;
return (uchar*) &thd->sys_var_tmp.ulonglong_value;
@@ -1962,18 +1962,18 @@ public:
{ var->value= 0; }
void global_save_default(THD *thd, set_var *var)
{ DBUG_ASSERT(FALSE); }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
thd->sys_var_tmp.double_value= thd->start_time +
thd->start_time_sec_part/(double)TIME_SECOND_PART_FACTOR;
return (uchar*) &thd->sys_var_tmp.double_value;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(FALSE);
return 0;
}
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{
thd->sys_var_tmp.double_value= 0;
return (uchar*) &thd->sys_var_tmp.double_value;
@@ -2032,12 +2032,12 @@ public:
}
void session_save_default(THD *thd, set_var *var) { }
void global_save_default(THD *thd, set_var *var) { }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(FALSE);
return 0;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return (uchar*)show_comp_option_name[global_var(enum SHOW_COMP_OPTION)];
}
@@ -2107,13 +2107,13 @@ public:
void **default_value= reinterpret_cast<void**>(option.def_value);
var->save_result.ptr= *default_value;
}
- uchar *valptr(THD *thd, uchar *val)
+ uchar *valptr(THD *thd, uchar *val) const
{ return val ? *(uchar**)(val+name_offset) : 0; }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, session_var(thd, uchar*)); }
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(uchar*)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, *(uchar**)option.def_value); }
};
@@ -2183,9 +2183,9 @@ public:
var->save_result.time_zone=
*(Time_zone**)(intptr)option.def_value;
}
- uchar *valptr(THD *thd, Time_zone *val)
- { return (uchar *)(val->get_name()->ptr()); }
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *valptr(THD *thd, Time_zone *val) const
+ { return reinterpret_cast<const uchar*>(val->get_name()->ptr()); }
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
/*
This is an ugly fix for replication: we don't replicate properly queries
@@ -2198,9 +2198,9 @@ public:
thd->time_zone_used= 1;
return valptr(thd, session_var(thd, Time_zone *));
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return valptr(thd, global_var(Time_zone*)); }
- uchar *default_value_ptr(THD *thd)
+ const uchar *default_value_ptr(THD *thd) const
{ return valptr(thd, *(Time_zone**)option.def_value); }
};
@@ -2359,7 +2359,7 @@ public:
/* Use value given in variable declaration */
global_save_default(thd, var);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
ulonglong *tmp, res;
tmp= (ulonglong*) (((uchar*)&(thd->variables)) + offset);
@@ -2367,11 +2367,11 @@ public:
*tmp= res;
return (uchar*) tmp;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return session_value_ptr(thd, base);
}
- ulonglong get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset);
+ ulonglong get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset) const;
bool update_variable(THD *thd, Master_info *mi)
{
return update_multi_source_variable_func(this, thd, mi);
@@ -2419,12 +2419,12 @@ public:
{
DBUG_ASSERT(false);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(false);
return NULL;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
};
@@ -2468,12 +2468,12 @@ public:
{
DBUG_ASSERT(false);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(false);
return NULL;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
};
@@ -2508,13 +2508,13 @@ public:
/* Record the attempt to use default so we can error. */
var->value= 0;
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(false);
return NULL;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
- uchar *default_value_ptr(THD *thd)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
+ const uchar *default_value_ptr(THD *thd) const
{ return 0; }
};
@@ -2550,13 +2550,13 @@ public:
/* Record the attempt to use default so we can error. */
var->value= 0;
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(false);
return NULL;
}
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
- uchar *default_value_ptr(THD *thd)
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
+ const uchar *default_value_ptr(THD *thd) const
{ return 0; }
};
@@ -2600,8 +2600,8 @@ public:
{
DBUG_ASSERT(false);
}
- uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base);
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const;
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
DBUG_ASSERT(false);
return NULL;
@@ -2627,7 +2627,7 @@ public:
SYSVAR_ASSERT(scope() == GLOBAL);
}
bool global_update(THD *thd, set_var *var);
- uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base);
+ const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const;
};
@@ -2710,8 +2710,9 @@ public:
}
private:
- uchar *value_ptr(THD *thd, vers_asof_timestamp_t &val)
+ const uchar *value_ptr(THD *thd, vers_asof_timestamp_t &val) const
{
+ const char *value;
switch (val.type)
{
case SYSTEM_TIME_UNSPECIFIED:
@@ -2719,29 +2720,30 @@ private:
break;
case SYSTEM_TIME_AS_OF:
{
- uchar *buf= (uchar*) thd->alloc(MAX_DATE_STRING_REP_LENGTH);
+ char *buf= (char*) thd->alloc(MAX_DATE_STRING_REP_LENGTH);
MYSQL_TIME ltime;
thd->variables.time_zone->gmt_sec_to_TIME(&ltime, val.unix_time);
ltime.second_part= val.second_part;
- if (buf && !my_datetime_to_str(&ltime, (char*) buf, 6))
+ value= buf;
+ if (buf && !my_datetime_to_str(&ltime, buf, 6))
{
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, "NULL (wrong datetime)");
- return (uchar*) thd->strdup("Error: wrong datetime");
+ value= thd->strdup("Error: wrong datetime");
}
- return buf;
+ break;
}
default:
- break;
+ my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, "NULL (wrong range type)");
+ value= thd->strdup("Error: wrong range type");
}
- my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, "NULL (wrong range type)");
- return (uchar*) thd->strdup("Error: wrong range type");
+ return reinterpret_cast<const uchar *>(value);
}
public:
- virtual uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
+ virtual const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return value_ptr(thd, session_var(thd, vers_asof_timestamp_t)); }
- virtual uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
+ virtual const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{ return value_ptr(thd, global_var(vers_asof_timestamp_t)); }
};