~skinny.moey/drizzle/branch-rev

« back to all changes in this revision

Viewing changes to drizzled/module/loader.cc

Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
static int test_plugin_options(memory::Root *, module::Module *,
164
164
                               po::options_description &long_options);
165
165
static void unlock_variables(Session *session, struct system_variables *vars);
166
 
static void cleanup_variables(Session *session, struct system_variables *vars);
167
 
static void plugin_vars_free_values(sys_var *vars);
 
166
static void cleanup_variables(system_variables *vars);
 
167
static void plugin_vars_free_values(module::Module::Variables &vars);
168
168
 
169
169
/* declared in set_var.cc */
170
170
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
289
289
static void delete_module(module::Module *module)
290
290
{
291
291
  /* Free allocated strings before deleting the plugin. */
292
 
  plugin_vars_free_values(module->system_vars);
 
292
  plugin_vars_free_values(module->getSysVars());
293
293
  module->isInited= false;
294
 
  mysql_del_sys_var_chain(module->system_vars);
295
294
  delete module;
296
295
}
297
296
 
318
317
    set the plugin attribute of plugin's sys vars so they are pointing
319
318
    to the active plugin
320
319
  */
321
 
  if (module->system_vars)
 
320
  for (module::Module::Variables::iterator iter= module->getSysVars().begin();
 
321
       iter != module->getSysVars().end();
 
322
       ++iter)
322
323
  {
323
 
    sys_var_pluginvar *var= module->system_vars->cast_pluginvar();
324
 
    for (;;)
325
 
    {
326
 
      var->plugin= module;
327
 
      if (! var->getNext())
328
 
        break;
329
 
      var= var->getNext()->cast_pluginvar();
330
 
    }
 
324
    sys_var *current_var= *iter;
 
325
    current_var->cast_pluginvar()->plugin= module;
331
326
  }
332
327
}
333
328
 
557
552
    unlock_variables(NULL, &global_system_variables);
558
553
    unlock_variables(NULL, &max_system_variables);
559
554
 
560
 
    cleanup_variables(NULL, &global_system_variables);
561
 
    cleanup_variables(NULL, &max_system_variables);
 
555
    cleanup_variables(&global_system_variables);
 
556
    cleanup_variables(&max_system_variables);
562
557
 
563
558
    initialized= 0;
564
559
  }
796
791
    then the intern_plugin_lock did not raise an error, so we do it here.
797
792
  */
798
793
  if (pi && !var)
 
794
  {
799
795
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
796
    assert(false);
 
797
  }
800
798
  return(var);
801
799
}
802
800
 
1048
1046
void plugin_sessionvar_init(Session *session)
1049
1047
{
1050
1048
  session->variables.storage_engine= NULL;
1051
 
  cleanup_variables(session, &session->variables);
 
1049
  cleanup_variables(&session->variables);
1052
1050
 
1053
1051
  session->variables= global_system_variables;
1054
1052
  session->variables.storage_engine= NULL;
1077
1075
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1078
1076
  it's used on shutdown.
1079
1077
*/
1080
 
static void cleanup_variables(Session *session, struct system_variables *vars)
 
1078
static void cleanup_variables(system_variables *vars)
1081
1079
{
1082
 
  sys_var_pluginvar *pivar;
1083
 
  sys_var *var;
1084
 
  int flags;
1085
 
 
1086
 
  bookmark_unordered_map::iterator iter= bookmark_hash.begin();
1087
 
  for (; iter != bookmark_hash.end() ; ++iter)
1088
 
  {
1089
 
    const Bookmark &v= (*iter).second;
1090
 
    const string key_name((*iter).first);
1091
 
    if (v.version > vars->dynamic_variables_version ||
1092
 
        !(var= intern_find_sys_var(key_name.c_str(), key_name.size(), true)) ||
1093
 
        !(pivar= var->cast_pluginvar()) ||
1094
 
        v.type_code != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1095
 
      continue;
1096
 
 
1097
 
    flags= pivar->plugin_var->flags;
1098
 
 
1099
 
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1100
 
        flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1101
 
    {
1102
 
      char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1103
 
      free(*ptr);
1104
 
      *ptr= NULL;
1105
 
    }
1106
 
  }
1107
 
 
1108
1080
  assert(vars->storage_engine == NULL);
1109
1081
 
1110
1082
  free(vars->dynamic_variables_ptr);
1117
1089
void plugin_sessionvar_cleanup(Session *session)
1118
1090
{
1119
1091
  unlock_variables(session, &session->variables);
1120
 
  cleanup_variables(session, &session->variables);
 
1092
  cleanup_variables(&session->variables);
1121
1093
}
1122
1094
 
1123
1095
 
1132
1104
  @param[in]        vars        Chain of system variables of a plugin
1133
1105
*/
1134
1106
 
1135
 
static void plugin_vars_free_values(sys_var *vars)
 
1107
static void plugin_vars_free_values(module::Module::Variables &vars)
1136
1108
{
1137
1109
 
1138
 
  for (sys_var *var= vars; var; var= var->getNext())
 
1110
  for (module::Module::Variables::iterator iter= vars.begin();
 
1111
       iter != vars.end();
 
1112
       ++iter)
1139
1113
  {
1140
 
    sys_var_pluginvar *piv= var->cast_pluginvar();
 
1114
    sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1141
1115
    if (piv &&
1142
1116
        ((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1143
1117
        (piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1631
1605
                               module::Module *test_module,
1632
1606
                               po::options_description &long_options)
1633
1607
{
1634
 
  struct sys_var_chain chain= { NULL, NULL };
1635
1608
  drizzle_sys_var **opt;
1636
1609
  option *opts= NULL;
1637
1610
  int error;
1710
1683
      assert(v); /* check that an object was actually constructed */
1711
1684
 
1712
1685
      drizzle_add_plugin_sysvar(static_cast<sys_var_pluginvar *>(v));
1713
 
      /*
1714
 
        Add to the chain of variables.
1715
 
        Done like this for easier debugging so that the
1716
 
        pointer to v is not lost on optimized builds.
1717
 
      */
1718
 
      v->chain_sys_var(&chain);
1719
 
    }
1720
 
    if (chain.first)
1721
 
    {
1722
 
      chain.last->setNext(NULL);
1723
 
      if (mysql_add_sys_var_chain(chain.first, NULL))
 
1686
      try
 
1687
      {
 
1688
        add_sys_var_to_list(v);
 
1689
        test_module->addSysVar(v);
 
1690
      }
 
1691
      catch (...)
1724
1692
      {
1725
1693
        errmsg_printf(ERRMSG_LVL_ERROR,
1726
1694
                      _("Plugin '%s' has conflicting system variables"),
1727
1695
                      test_module->getName().c_str());
1728
1696
        goto err;
1729
1697
      }
1730
 
      test_module->system_vars= chain.first;
 
1698
 
1731
1699
    }
 
1700
 
1732
1701
    return(0);
1733
1702
  }
1734
1703