Skip to content

Commit

Permalink
Change CHARSET_INFO character set and collaction names to LEX_CSTRING
Browse files Browse the repository at this point in the history
This change removed 68 explict strlen() calls from the code.

The following renames was done to ensure we don't use the old names
when merging code from earlier releases, as using the new variables
for print function could result in crashes:
- charset->csname renamed to charset->cs_name
- charset->name renamed to charset->coll_name

Almost everything where mechanical changes except:
- Changed to use the new Protocol::store(LEX_CSTRING..) when possible
- Changed to use field->store(LEX_CSTRING*, CHARSET_INFO*) when possible
- Changed to use String->append(LEX_CSTRING&) when possible

Other things:
- There where compiler issues with ensuring that all character set names
  points to the same string: gcc doesn't allow one to use integer constants
  when defining global structures (constant char * pointers works fine).
  To get around this, I declared defines for each character set name
  length.
  • Loading branch information
montywi authored and vuvova committed May 19, 2021
1 parent b0910dd commit a206658
Show file tree
Hide file tree
Showing 78 changed files with 1,019 additions and 1,022 deletions.
6 changes: 3 additions & 3 deletions client/mariadb-conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ class Conv: public String_copier, public Delimiter
fflush(stdout);
fprintf(stderr,
"Illegal %s byte sequence at position %d\n",
m_fromcs->csname,
m_fromcs->cs_name.str,
(uint) (well_formed_error_pos() - from));
}
else if (cannot_convert_error_pos())
{
fflush(stdout);
fprintf(stderr,
"Conversion from %s to %s failed at position %d\n",
m_fromcs->csname, m_tocs->csname,
m_fromcs->cs_name.str, m_tocs->cs_name.str,
(uint) (cannot_convert_error_pos() - from));
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ int main(int argc, char *argv[])
charset_info_to->mbminlen > 1)
{
fprintf(stderr, "--delimiter cannot be used with %s to %s conversion\n",
charset_info_from->csname, charset_info_to->csname);
charset_info_from->cs_name.str, charset_info_to->cs_name.str);
return 1;
}
if (conv.set_delimiter_unescape(opt.m_delimiter))
Expand Down
23 changes: 15 additions & 8 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3246,8 +3246,8 @@ com_charset(String *buffer __attribute__((unused)), char *line)
if (new_cs)
{
charset_info= new_cs;
mysql_set_character_set(&mysql, charset_info->csname);
default_charset= (char *)charset_info->csname;
mysql_set_character_set(&mysql, charset_info->cs_name.str);
default_charset= (char *)charset_info->cs_name.str;
put_info("Charset changed", INFO_INFO);
}
else put_info("Charset is not found", INFO_INFO);
Expand Down Expand Up @@ -4736,6 +4736,8 @@ static int
sql_real_connect(char *host,char *database,char *user,char *password,
uint silent)
{
const char *charset_name;

if (connected)
{
connected= 0;
Expand Down Expand Up @@ -4783,13 +4785,17 @@ sql_real_connect(char *host,char *database,char *user,char *password,
return -1; // Retryable
}

if (!(charset_info= get_charset_by_name(mysql.charset->name, MYF(MY_UTF8_IS_UTF8MB3))))
charset_name= IF_EMBEDDED(mysql.charset->coll_name.str,
mysql.charset->name);
charset_info= get_charset_by_name(charset_name, MYF(MY_UTF8_IS_UTF8MB3));
if (!charset_info)
{
put_info("Unknown default character set", INFO_ERROR);
char buff[128];
my_snprintf(buff, sizeof(buff)-1,
"Unknown default character set %s", charset_name);
put_info(buff, INFO_ERROR);
return 1;
}


connected=1;
#ifndef EMBEDDED_LIBRARY
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &debug_info_flag);
Expand Down Expand Up @@ -4928,8 +4934,9 @@ com_status(String *buffer __attribute__((unused)),
else
{
/* Probably pre-4.1 server */
tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->cs_name.str);
tee_fprintf(stdout, "Server characterset:\t%s\n",
mysql_character_set_name(&mysql));
}

#ifndef EMBEDDED_LIBRARY
Expand Down
10 changes: 5 additions & 5 deletions client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,8 @@ static int switch_db_collation(FILE *sql_file,
fprintf(sql_file,
"ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
(const char *) quoted_db_name,
(const char *) db_cl->csname,
(const char *) db_cl->name,
(const char *) db_cl->cs_name.str,
(const char *) db_cl->coll_name.str,
(const char *) delimiter);

*db_cl_altered= 1;
Expand Down Expand Up @@ -1678,8 +1678,8 @@ static int restore_db_collation(FILE *sql_file,
fprintf(sql_file,
"ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
(const char *) quoted_db_name,
(const char *) db_cl->csname,
(const char *) db_cl->name,
(const char *) db_cl->cs_name.str,
(const char *) db_cl->coll_name.str,
(const char *) delimiter);

return 0;
Expand Down Expand Up @@ -4120,7 +4120,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,

dynstr_append_checked(&query_string, " /*!50138 CHARACTER SET ");
dynstr_append_checked(&query_string, default_charset == mysql_universal_client_charset ?
my_charset_bin.name : /* backward compatibility */
my_charset_bin.coll_name.str : /* backward compatibility */
default_charset);
dynstr_append_checked(&query_string, " */");

Expand Down
4 changes: 2 additions & 2 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6010,7 +6010,7 @@ void do_connect(struct st_command *command)
if (opt_compress || con_compress)
mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_NAME,
csname?csname: charset_info->csname);
csname ? csname : charset_info->cs_name.str);
if (opt_charsets_dir)
mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_DIR,
opt_charsets_dir);
Expand Down Expand Up @@ -9259,7 +9259,7 @@ int main(int argc, char **argv)
if (opt_compress)
mysql_options(con->mysql,MYSQL_OPT_COMPRESS,NullS);
mysql_options(con->mysql, MYSQL_SET_CHARSET_NAME,
charset_info->csname);
charset_info->cs_name.str);
if (opt_charsets_dir)
mysql_options(con->mysql, MYSQL_SET_CHARSET_DIR,
opt_charsets_dir);
Expand Down
5 changes: 3 additions & 2 deletions include/m_ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define _m_ctype_h

#include <my_attribute.h>
#include <m_string.h>

enum loglevel {
ERROR_LEVEL= 0,
Expand Down Expand Up @@ -569,8 +570,8 @@ struct charset_info_st
uint primary_number;
uint binary_number;
uint state;
const char *csname;
const char *name;
LEX_CSTRING cs_name;
LEX_CSTRING coll_name;
const char *comment;
const char *tailoring;
const uchar *m_ctype;
Expand Down
2 changes: 1 addition & 1 deletion include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ extern void free_charsets(void);
extern char *get_charsets_dir(char *buf);
static inline my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2)
{
return (cs1->csname == cs2->csname);
return (cs1->cs_name.str == cs2->cs_name.str);
}
extern my_bool init_compiled_charsets(myf flags);
extern void add_compiled_collation(struct charset_info_st *cs);
Expand Down
6 changes: 3 additions & 3 deletions libmysqld/libmysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,15 +1114,15 @@ ulong STDCALL mysql_thread_id(MYSQL *mysql)

const char * STDCALL mysql_character_set_name(MYSQL *mysql)
{
return mysql->charset->csname;
return mysql->charset->cs_name.str;
}

void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *csinfo)
{
csinfo->number = mysql->charset->number;
csinfo->state = mysql->charset->state;
csinfo->csname = mysql->charset->csname;
csinfo->name = mysql->charset->name;
csinfo->csname = mysql->charset->cs_name.str;
csinfo->name = mysql->charset->coll_name.str;
csinfo->comment = mysql->charset->comment;
csinfo->mbminlen = mysql->charset->mbminlen;
csinfo->mbmaxlen = mysql->charset->mbmaxlen;
Expand Down
2 changes: 1 addition & 1 deletion mysys/charset-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ my_bool init_compiled_charsets(myf flags __attribute__((unused)))
#endif /* HAVE_CHARSET_utf32 */

/* Copy compiled charsets */
for (cs=compiled_charsets; cs->name; cs++)
for (cs=compiled_charsets; cs->coll_name.str; cs++)
add_compiled_extra_collation((struct charset_info_st *) cs);

return FALSE;
Expand Down

0 comments on commit a206658

Please sign in to comment.