Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19566

Remove Item::name related strlen() calls in constructors of some Item_string descendands

    Details

      Description

      The following classes use strlen() when handling name related parameters to constructors:

      • Item_string
      • Item_blob
      • Item_empty_string

      Examples:

        // Constructors with an externally provided item name
        Item_string(THD *thd, const char *name_par, const char *str, size_t length,
                    CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
         :Item_literal(thd)
        {
          str_value.set_or_copy_aligned(str, length, cs);
          fix_from_value(dv, Metadata(&str_value));
          set_name(thd, name_par,safe_strlen(name_par), system_charset_info);
        }
        Item_string(THD *thd, const char *name_par, const char *str, size_t length,
                    CHARSET_INFO *cs, Derivation dv, uint repertoire)
         :Item_literal(thd)
        {
          str_value.set_or_copy_aligned(str, length, cs);
          fix_from_value(dv, Metadata(&str_value, repertoire));
          set_name(thd, name_par, safe_strlen(name_par), system_charset_info);
        }
      

        Item_blob(THD *thd, const char *name_arg, uint length):
          Item_partition_func_safe_string(thd, name_arg, (uint) safe_strlen(name_arg),
                                          &my_charset_bin)
        { max_length= length; }
      

        Item_empty_string(THD *thd, const char *header,uint length,
                          CHARSET_INFO *cs= NULL):
          Item_partition_func_safe_string(thd, "", 0,
                                          cs ? cs : &my_charset_utf8_general_ci)
          {
            name.str=    header;
            name.length= strlen(name.str);
            max_length= length * collation.collation->mbmaxlen;
          }
      

      We should eventually get rid of all strlen().

      Under terms of this tasks we'll move strlen() calls to upper level:

      • change the mentioned constructors to accept LEX_CSTRING instead of a const char pointer
      • let the caller provide length.

      This task is needed to do some upcoming Type_handler related changes easier, e.g. decompose create_schema_table in sql_show.cc into implementations virtual in Type_handler.

      Additionally, we'll introduce a new version of Item::set_name() accepting LEX_CSTRING as a parameter:

      void set_name(THD *thd, const LEX_CSTRING &str, CHARSET_INFO *cs= system_charset_info)
      {
         set_name(thd, str.str, str.length, cs);
      }
      

      and reuse it in a few places, especially in sql_show.cc, which has a lot calls like this:

           field->set_name(thd, field_info->old_name,
                           strlen(field_info->old_name),
                           system_charset_info);
      

      Also, let's add methods to ST_FIELD_INFO:

        LEX_CSTRING get_name() const
        {
          return LEX_CSTRING({field_name, strlen(field_name)});
        }
        LEX_CSTRING get_old_name() const
        {
          return LEX_CSTRING({old_name, strlen(old_name)});
        }
      

      to reuse new set_name() easier.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: