MDEV-19863 Add const to TYPELIB pointers

This commit is contained in:
Alexander Barkov 2019-06-26 05:29:44 +04:00
parent 8d4c159b1b
commit 677133f1b3
15 changed files with 58 additions and 53 deletions

View File

@ -256,7 +256,7 @@ extern int find_type_with_warning(const char *x, TYPELIB *typelib,
extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags);
extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
extern const char *get_type(TYPELIB *typelib,unsigned int nr); extern const char *get_type(TYPELIB *typelib,unsigned int nr);
extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); extern TYPELIB *copy_typelib(MEM_ROOT *root, const TYPELIB *from);
extern TYPELIB sql_protocol_typelib; extern TYPELIB sql_protocol_typelib;
my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name, my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name,
my_ulonglong cur_set, my_ulonglong default_set, my_ulonglong cur_set, my_ulonglong default_set,

View File

@ -43,7 +43,7 @@ extern int find_type_with_warning(const char *x, TYPELIB *typelib,
extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags);
extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
extern const char *get_type(TYPELIB *typelib,unsigned int nr); extern const char *get_type(TYPELIB *typelib,unsigned int nr);
extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); extern TYPELIB *copy_typelib(MEM_ROOT *root, const TYPELIB *from);
extern TYPELIB sql_protocol_typelib; extern TYPELIB sql_protocol_typelib;

View File

@ -226,7 +226,7 @@ my_ulonglong find_typeset(char *x, TYPELIB *lib, int *err)
NULL otherwise NULL otherwise
*/ */
TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from) TYPELIB *copy_typelib(MEM_ROOT *root, const TYPELIB *from)
{ {
TYPELIB *to; TYPELIB *to;
uint i; uint i;

View File

@ -9462,7 +9462,8 @@ bool Field::eq_def(const Field *field) const
@return TRUE if the type names of t1 match those of t2. FALSE otherwise. @return TRUE if the type names of t1 match those of t2. FALSE otherwise.
*/ */
static bool compare_type_names(CHARSET_INFO *charset, TYPELIB *t1, TYPELIB *t2) static bool compare_type_names(CHARSET_INFO *charset, const TYPELIB *t1,
const TYPELIB *t2)
{ {
for (uint i= 0; i < t1->count; i++) for (uint i= 0; i < t1->count; i++)
if (my_strnncoll(charset, if (my_strnncoll(charset,
@ -9481,7 +9482,7 @@ static bool compare_type_names(CHARSET_INFO *charset, TYPELIB *t1, TYPELIB *t2)
bool Field_enum::eq_def(const Field *field) const bool Field_enum::eq_def(const Field *field) const
{ {
TYPELIB *values; const TYPELIB *values;
if (!Field::eq_def(field)) if (!Field::eq_def(field))
return FALSE; return FALSE;
@ -9507,7 +9508,7 @@ bool Field_enum::eq_def(const Field *field) const
uint Field_enum::is_equal(Create_field *new_field) uint Field_enum::is_equal(Create_field *new_field)
{ {
TYPELIB *values= new_field->interval; const TYPELIB *values= new_field->interval;
/* /*
The fields are compatible if they have the same flags, The fields are compatible if they have the same flags,
@ -10240,7 +10241,8 @@ bool Column_definition::create_interval_from_interval_list(MEM_ROOT *mem_root,
{ {
DBUG_ENTER("Column_definition::create_interval_from_interval_list"); DBUG_ENTER("Column_definition::create_interval_from_interval_list");
DBUG_ASSERT(!interval); DBUG_ASSERT(!interval);
if (!(interval= (TYPELIB*) alloc_root(mem_root, sizeof(TYPELIB)))) TYPELIB *tmpint;
if (!(interval= tmpint= (TYPELIB*) alloc_root(mem_root, sizeof(TYPELIB))))
DBUG_RETURN(true); // EOM DBUG_RETURN(true); // EOM
List_iterator<String> it(interval_list); List_iterator<String> it(interval_list);
@ -10254,17 +10256,17 @@ bool Column_definition::create_interval_from_interval_list(MEM_ROOT *mem_root,
DBUG_ASSERT(comma_length >= 0 && comma_length <= (int) sizeof(comma_buf)); DBUG_ASSERT(comma_length >= 0 && comma_length <= (int) sizeof(comma_buf));
if (!multi_alloc_root(mem_root, if (!multi_alloc_root(mem_root,
&interval->type_names, &tmpint->type_names,
sizeof(char*) * (interval_list.elements + 1), sizeof(char*) * (interval_list.elements + 1),
&interval->type_lengths, &tmpint->type_lengths,
sizeof(uint) * (interval_list.elements + 1), sizeof(uint) * (interval_list.elements + 1),
NullS)) NullS))
goto err; // EOM goto err; // EOM
interval->name= ""; tmpint->name= "";
interval->count= interval_list.elements; tmpint->count= interval_list.elements;
for (uint i= 0; i < interval->count; i++) for (uint i= 0; i < interval_list.elements; i++)
{ {
uint32 dummy; uint32 dummy;
String *tmp= it++; String *tmp= it++;
@ -10302,11 +10304,11 @@ bool Column_definition::create_interval_from_interval_list(MEM_ROOT *mem_root,
goto err; goto err;
} }
} }
interval->type_names[i]= value.str; tmpint->type_names[i]= value.str;
interval->type_lengths[i]= (uint)value.length; tmpint->type_lengths[i]= (uint)value.length;
} }
interval->type_names[interval->count]= 0; // End marker tmpint->type_names[interval_list.elements]= 0; // End marker
interval->type_lengths[interval->count]= 0; tmpint->type_lengths[interval_list.elements]= 0;
interval_list.empty(); // Don't need interval_list anymore interval_list.empty(); // Don't need interval_list anymore
DBUG_RETURN(false); DBUG_RETURN(false);
err: err:

View File

@ -1430,7 +1430,7 @@ public:
void copy_from_tmp(int offset); void copy_from_tmp(int offset);
uint fill_cache_field(struct st_cache_field *copy); uint fill_cache_field(struct st_cache_field *copy);
virtual bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); virtual bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate);
virtual TYPELIB *get_typelib() const { return NULL; } virtual const TYPELIB *get_typelib() const { return NULL; }
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
virtual CHARSET_INFO *charset_for_protocol(void) const virtual CHARSET_INFO *charset_for_protocol(void) const
{ return binary() ? &my_charset_bin : charset(); } { return binary() ? &my_charset_bin : charset(); }
@ -4313,12 +4313,12 @@ class Field_enum :public Field_str {
protected: protected:
uint packlength; uint packlength;
public: public:
TYPELIB *typelib; const TYPELIB *typelib;
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg,
uint packlength_arg, uint packlength_arg,
TYPELIB *typelib_arg, const TYPELIB *typelib_arg,
const DTCollation &collation) const DTCollation &collation)
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, collation), unireg_check_arg, field_name_arg, collation),
@ -4391,7 +4391,7 @@ public:
/* enum and set are sorted as integers */ /* enum and set are sorted as integers */
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
uint decimals() const { return 0; } uint decimals() const { return 0; }
TYPELIB *get_typelib() const { return typelib; } const TYPELIB *get_typelib() const { return typelib; }
virtual uchar *pack(uchar *to, const uchar *from, uint max_length); virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
virtual const uchar *unpack(uchar *to, const uchar *from, virtual const uchar *unpack(uchar *to, const uchar *from,
@ -4426,7 +4426,7 @@ public:
uchar null_bit_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg,
uint32 packlength_arg, uint32 packlength_arg,
TYPELIB *typelib_arg, const DTCollation &collation) const TYPELIB *typelib_arg, const DTCollation &collation)
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, unireg_check_arg, field_name_arg,
packlength_arg, packlength_arg,
@ -4687,7 +4687,7 @@ public:
*/ */
ulonglong length; ulonglong length;
Field::utype unireg_check; Field::utype unireg_check;
TYPELIB *interval; // Which interval to use const TYPELIB *interval; // Which interval to use
CHARSET_INFO *charset; CHARSET_INFO *charset;
uint32 srid; uint32 srid;
Field::geometry_type geom_type; Field::geometry_type geom_type;
@ -5170,7 +5170,7 @@ public:
LEX_CSTRING change; // If done with alter table LEX_CSTRING change; // If done with alter table
LEX_CSTRING after; // Put column after this one LEX_CSTRING after; // Put column after this one
Field *field; // For alter table Field *field; // For alter table
TYPELIB *save_interval; // Temporary copy for the above const TYPELIB *save_interval; // Temporary copy for the above
// Used only for UCS2 intervals // Used only for UCS2 intervals
/** structure with parsed options (for comparing fields in ALTER TABLE) */ /** structure with parsed options (for comparing fields in ALTER TABLE) */

View File

@ -1114,9 +1114,9 @@ public:
{ {
return type_handler()->max_display_length(this); return type_handler()->max_display_length(this);
} }
TYPELIB *get_typelib() const { return NULL; } const TYPELIB *get_typelib() const { return NULL; }
void set_maybe_null(bool maybe_null_arg) { maybe_null= maybe_null_arg; } void set_maybe_null(bool maybe_null_arg) { maybe_null= maybe_null_arg; }
void set_typelib(TYPELIB *typelib) void set_typelib(const TYPELIB *typelib)
{ {
// Non-field Items (e.g. hybrid functions) never have ENUM/SET types yet. // Non-field Items (e.g. hybrid functions) never have ENUM/SET types yet.
DBUG_ASSERT(0); DBUG_ASSERT(0);
@ -3352,7 +3352,7 @@ public:
const Tmp_field_param *param); const Tmp_field_param *param);
Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src,
const Tmp_field_param *param); const Tmp_field_param *param);
TYPELIB *get_typelib() const { return field->get_typelib(); } const TYPELIB *get_typelib() const { return field->get_typelib(); }
enum_monotonicity_info get_monotonicity_info() const enum_monotonicity_info get_monotonicity_info() const
{ {
return MONOTONIC_STRICT_INCREASING; return MONOTONIC_STRICT_INCREASING;
@ -5213,7 +5213,7 @@ public:
{ {
return ref ? (*ref)->real_item() : this; return ref ? (*ref)->real_item() : this;
} }
TYPELIB *get_typelib() const const TYPELIB *get_typelib() const
{ {
return ref ? (*ref)->get_typelib() : NULL; return ref ? (*ref)->get_typelib() : NULL;
} }
@ -6962,7 +6962,7 @@ class Item_type_holder: public Item,
public Type_geometry_attributes public Type_geometry_attributes
{ {
protected: protected:
TYPELIB *enum_set_typelib; const TYPELIB *enum_set_typelib;
public: public:
Item_type_holder(THD *thd, Item *item) Item_type_holder(THD *thd, Item *item)
:Item(thd, item), :Item(thd, item),
@ -6998,7 +6998,7 @@ public:
} }
enum Type type() const { return TYPE_HOLDER; } enum Type type() const { return TYPE_HOLDER; }
TYPELIB *get_typelib() const { return enum_set_typelib; } const TYPELIB *get_typelib() const { return enum_set_typelib; }
double val_real(); double val_real();
longlong val_int(); longlong val_int();
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);

View File

@ -1090,7 +1090,7 @@ protected:
} }
const Type_handler *type_handler() const const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); } { return Type_handler_hybrid_field_type::type_handler(); }
TYPELIB *get_typelib() const { return args[0]->get_typelib(); } const TYPELIB *get_typelib() const { return args[0]->get_typelib(); }
void update_field(); void update_field();
void min_max_update_str_field(); void min_max_update_str_field();
void min_max_update_real_field(); void min_max_update_real_field();

View File

@ -6832,7 +6832,7 @@ class Type_holder: public Sql_alloc,
public Type_all_attributes, public Type_all_attributes,
public Type_geometry_attributes public Type_geometry_attributes
{ {
TYPELIB *m_typelib; const TYPELIB *m_typelib;
bool m_maybe_null; bool m_maybe_null;
public: public:
Type_holder() Type_holder()
@ -6863,11 +6863,11 @@ public:
{ {
return Type_geometry_attributes::get_geometry_type(); return Type_geometry_attributes::get_geometry_type();
} }
void set_typelib(TYPELIB *typelib) void set_typelib(const TYPELIB *typelib)
{ {
m_typelib= typelib; m_typelib= typelib;
} }
TYPELIB *get_typelib() const const TYPELIB *get_typelib() const
{ {
return m_typelib; return m_typelib;
} }

View File

@ -2846,7 +2846,7 @@ static int sort_keys(KEY *a, KEY *b)
*/ */
bool check_duplicates_in_interval(const char *set_or_name, bool check_duplicates_in_interval(const char *set_or_name,
const char *name, TYPELIB *typelib, const char *name, const TYPELIB *typelib,
CHARSET_INFO *cs, unsigned int *dup_val_count) CHARSET_INFO *cs, unsigned int *dup_val_count)
{ {
TYPELIB tmp= *typelib; TYPELIB tmp= *typelib;

View File

@ -3402,7 +3402,7 @@ Field *Type_handler_enum::make_table_field(const LEX_CSTRING *name,
const Type_all_attributes &attr, const Type_all_attributes &attr,
TABLE *table) const TABLE *table) const
{ {
TYPELIB *typelib= attr.get_typelib(); const TYPELIB *typelib= attr.get_typelib();
DBUG_ASSERT(typelib); DBUG_ASSERT(typelib);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_enum(addr.ptr(), attr.max_length, Field_enum(addr.ptr(), attr.max_length,
@ -3419,7 +3419,7 @@ Field *Type_handler_set::make_table_field(const LEX_CSTRING *name,
TABLE *table) const TABLE *table) const
{ {
TYPELIB *typelib= attr.get_typelib(); const TYPELIB *typelib= attr.get_typelib();
DBUG_ASSERT(typelib); DBUG_ASSERT(typelib);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_set(addr.ptr(), attr.max_length, Field_set(addr.ptr(), attr.max_length,
@ -4091,10 +4091,10 @@ bool Type_handler_typelib::
Type_all_attributes *func, Type_all_attributes *func,
Item **items, uint nitems) const Item **items, uint nitems) const
{ {
TYPELIB *typelib= NULL; const TYPELIB *typelib= NULL;
for (uint i= 0; i < nitems; i++) for (uint i= 0; i < nitems; i++)
{ {
TYPELIB *typelib2; const TYPELIB *typelib2;
if ((typelib2= items[i]->get_typelib())) if ((typelib2= items[i]->get_typelib()))
{ {
if (typelib) if (typelib)

View File

@ -2971,8 +2971,8 @@ public:
*/ */
virtual uint uint_geometry_type() const= 0; virtual uint uint_geometry_type() const= 0;
virtual void set_geometry_type(uint type)= 0; virtual void set_geometry_type(uint type)= 0;
virtual TYPELIB *get_typelib() const= 0; virtual const TYPELIB *get_typelib() const= 0;
virtual void set_typelib(TYPELIB *typelib)= 0; virtual void set_typelib(const TYPELIB *typelib)= 0;
}; };

View File

@ -45,7 +45,8 @@
static const char field_separator=','; static const char field_separator=',';
ulonglong find_set(TYPELIB *lib, const char *str, size_t length, CHARSET_INFO *cs, ulonglong find_set(const TYPELIB *lib,
const char *str, size_t length, CHARSET_INFO *cs,
char **err_pos, uint *err_len, bool *set_warning) char **err_pos, uint *err_len, bool *set_warning)
{ {
CHARSET_INFO *strip= cs ? cs : &my_charset_latin1; CHARSET_INFO *strip= cs ? cs : &my_charset_latin1;

View File

@ -18,7 +18,8 @@
typedef struct st_typelib TYPELIB; typedef struct st_typelib TYPELIB;
ulonglong find_set(TYPELIB *lib, const char *x, size_t length, CHARSET_INFO *cs, ulonglong find_set(const TYPELIB *lib,
const char *x, size_t length, CHARSET_INFO *cs,
char **err_pos, uint *err_len, bool *set_warning); char **err_pos, uint *err_len, bool *set_warning);
ulonglong find_set_from_flags(TYPELIB *lib, uint default_name, ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
ulonglong cur_set, ulonglong default_set, ulonglong cur_set, ulonglong default_set,

View File

@ -9372,7 +9372,7 @@ bool TR_table::check(bool error)
} }
Field_enum *iso_level= static_cast<Field_enum *>(table->field[FLD_ISO_LEVEL]); Field_enum *iso_level= static_cast<Field_enum *>(table->field[FLD_ISO_LEVEL]);
st_typelib *typelib= iso_level->typelib; const st_typelib *typelib= iso_level->typelib;
if (typelib->count != 4) if (typelib->count != 4)
goto wrong_enum; goto wrong_enum;

View File

@ -722,6 +722,7 @@ static bool pack_header(THD *thd, uchar *forminfo,
if (field->charset->mbminlen > 1) if (field->charset->mbminlen > 1)
{ {
TYPELIB *tmpint;
/* /*
Escape UCS2 intervals using HEX notation to avoid Escape UCS2 intervals using HEX notation to avoid
problems with delimiters between enum elements. problems with delimiters between enum elements.
@ -731,14 +732,15 @@ static bool pack_header(THD *thd, uchar *forminfo,
The HEX representation is created from this copy. The HEX representation is created from this copy.
*/ */
field->save_interval= field->interval; field->save_interval= field->interval;
field->interval= (TYPELIB*) thd->alloc(sizeof(TYPELIB)); field->interval= tmpint= (TYPELIB*) thd->alloc(sizeof(TYPELIB));
*field->interval= *field->save_interval; *tmpint= *field->save_interval;
field->interval->type_names= tmpint->type_names=
(const char **) thd->alloc(sizeof(char*) * (const char **) thd->alloc(sizeof(char*) *
(field->interval->count+1)); (field->interval->count+1));
field->interval->type_names[field->interval->count]= 0; tmpint->type_lengths=
field->interval->type_lengths=
(uint *) thd->alloc(sizeof(uint) * field->interval->count); (uint *) thd->alloc(sizeof(uint) * field->interval->count);
tmpint->type_names[field->interval->count]= 0;
tmpint->type_lengths[field->interval->count]= 0;
for (uint pos= 0; pos < field->interval->count; pos++) for (uint pos= 0; pos < field->interval->count; pos++)
{ {
@ -747,9 +749,8 @@ static bool pack_header(THD *thd, uchar *forminfo,
size_t hex_length; size_t hex_length;
length= field->save_interval->type_lengths[pos]; length= field->save_interval->type_lengths[pos];
hex_length= length * 2; hex_length= length * 2;
field->interval->type_lengths[pos]= (uint)hex_length; tmpint->type_lengths[pos]= (uint) hex_length;
field->interval->type_names[pos]= dst= tmpint->type_names[pos]= dst= (char*) thd->alloc(hex_length + 1);
(char*) thd->alloc(hex_length + 1);
octet2hex(dst, src, length); octet2hex(dst, src, length);
} }
} }
@ -813,7 +814,7 @@ static uint get_interval_id(uint *int_count,List<Create_field> &create_fields,
{ {
List_iterator<Create_field> it(create_fields); List_iterator<Create_field> it(create_fields);
Create_field *field; Create_field *field;
TYPELIB *interval=last_field->interval; const TYPELIB *interval= last_field->interval;
while ((field=it++) != last_field) while ((field=it++) != last_field)
{ {