List:Internals« Previous MessageNext Message »
From:svoj Date:August 26 2005 1:18pm
Subject:bk commit into 5.0 tree (svoj:1.1896)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of svoj. When svoj does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1896 05/08/26 18:17:58 svoj@stripped +5 -0
  WL#2763 - MySQL plugin interface: step 1
  Avoid strlen call in plugin related routines.

  sql/sql_yacc.yy
    1.412 05/08/26 18:17:54 svoj@stripped +4 -4
    plugin_find returns now internal plugin structure.

  sql/sql_plugin.h
    1.3 05/08/26 18:17:54 svoj@stripped +17 -1
    Move st_plugin_dl and st_plugin_int declarations into sql_plugin.h
    plugin_find returns internal plugin structure now.

  sql/sql_plugin.cc
    1.5 05/08/26 18:17:54 svoj@stripped +64 -75
    Move st_plugin_dl and st_plugin_int declarations into sql_plugin.h
    Avoid strlen call in plugin related routines.

  sql/sql_class.h
    1.252 05/08/26 18:17:53 svoj@stripped +2 -2
    Key class accepts st_plugin_int instead of st_plugin now.

  include/plugin.h
    1.4 05/08/26 18:17:53 svoj@stripped +1 -1
    name isn't constant anymore - needed for LEX_STRING assignment.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	svoj
# Host:	svoj-laptop.mysql.com
# Root:	/home/svoj/devel/mysql/CNET/mysql-5.0

--- 1.251/sql/sql_class.h	2005-08-20 23:24:23 +05:00
+++ 1.252/sql/sql_class.h	2005-08-26 18:17:53 +05:00
@@ -407,11 +407,11 @@
   List<key_part_spec> columns;
   const char *name;
   bool generated;
-  struct st_plugin *parser;
+  struct st_plugin_int *parser;
 
   Key(enum Keytype type_par, const char *name_arg, enum ha_key_alg alg_par,
       bool generated_arg, List<key_part_spec> &cols,
-      struct st_plugin *parser_arg= (struct st_plugin*)0)
+      struct st_plugin_int *parser_arg= (struct st_plugin_int*)0)
     :type(type_par), algorithm(alg_par), columns(cols), name(name_arg),
     generated(generated_arg), parser(parser_arg)
   {}

--- 1.411/sql/sql_yacc.yy	2005-08-20 23:24:23 +05:00
+++ 1.412/sql/sql_yacc.yy	2005-08-26 18:17:54 +05:00
@@ -106,7 +106,7 @@
   struct { int vars, conds, hndlrs, curs; } spblock;
   sp_name *spname;
   struct st_lex *lex;
-  struct st_plugin *plugin;
+  struct st_plugin_int *plugin;
 }
 
 %{
@@ -2822,12 +2822,12 @@
 	;
 
 opt_fulltext_parser:
-        /* empty */               { $$= (struct st_plugin*)0; }
+        /* empty */               { $$= (struct st_plugin_int*)0; }
 	| WITH PARSER_SYM IDENT_sys
           {
 #ifdef HAVE_DLOPEN
-            struct st_plugin *plugin;
-            if ((plugin= plugin_find($3.str, PLUGIN_TYPE_FULLTEXT_PARSER)))
+            struct st_plugin_int *plugin;
+            if ((plugin= plugin_find(&$3, PLUGIN_TYPE_FULLTEXT_PARSER)))
               $$= plugin;
             else
             {

--- 1.3/include/plugin.h	2005-08-22 17:39:35 +05:00
+++ 1.4/include/plugin.h	2005-08-26 18:17:53 +05:00
@@ -31,7 +31,7 @@
 {
   int type;
   void *info;
-  const char *name;
+  char *name;
   const char *author;
   const char *descr;
 };

--- 1.4/sql/sql_plugin.cc	2005-08-22 17:39:36 +05:00
+++ 1.5/sql/sql_plugin.cc	2005-08-26 18:17:54 +05:00
@@ -23,30 +23,13 @@
 static const char *plugin_declarations_sym= "_plugin_declarations_";
 static int min_plugin_interface_version= 0x0000;
 
-struct st_plugin_dl
-{
-  char *dl;
-  void *handle;
-  struct st_plugin *plugins;
-  int version;
-  uint ref_count;
-};
-
-
-struct st_plugin_int
-{
-  struct st_plugin *plugin;
-  struct st_plugin_dl *plugin_dl;
-};
-
-
 static DYNAMIC_ARRAY plugin_dl_array;
 static DYNAMIC_ARRAY plugin_array;
 static rw_lock_t THR_LOCK_plugin;
 static bool initialized= 0;
 
 
-static struct st_plugin_dl *plugin_dl_find (const char *dl)
+static struct st_plugin_dl *plugin_dl_find (LEX_STRING *dl)
 {
   uint i;
   DBUG_ENTER("plugin_dl_find");
@@ -54,39 +37,37 @@
   {
     struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
                                               struct st_plugin_dl *);
-    if (! tmp->dl)
-      continue;
-    if (! my_strnncoll(files_charset_info,
-                       (const uchar *)dl, strlen(dl),
-                       (const uchar *)tmp->dl, strlen(tmp->dl)))
+    if (tmp->ref_count &&
+        ! my_strnncoll(files_charset_info,
+                       (const uchar *)dl->str, dl->length,
+                       (const uchar *)tmp->dl.str, tmp->dl.length))
       DBUG_RETURN(tmp);
   }
   DBUG_RETURN(0);
 }
 
 
-static st_plugin_dl *plugin_dl_add (const char *dl)
+static st_plugin_dl *plugin_dl_add (LEX_STRING *dl)
 {
   char dlpath[FN_REFLEN];
-  uint plugin_dir_len, dl_len;
+  uint plugin_dir_len;
   struct st_plugin_dl *tmp, plugin_dl;
   void *sym;
   DBUG_ENTER("plugin_dl_add");
   DBUG_ASSERT(opt_plugin_dir);
   plugin_dir_len= strlen(opt_plugin_dir);
-  dl_len= strlen(dl);
   /*
     Ensure that the dll doesn't have a path.
     This is done to ensure that only approved libraries from the
     plugin directory are used (to make this even remotely secure).
     TODO: fix false positives for japanese windows
   */
-  if (strchr(dl, '/') ||
-      IF_WIN(strchr(dl, '\\'), 0) ||
-      dl_len > NAME_LEN ||
-      plugin_dir_len + dl_len + 1 >= FN_REFLEN)
+  if (strchr(dl->str, '/') ||
+      IF_WIN(strchr(dl->str, '\\'), 0) ||
+      dl->length > NAME_LEN ||
+      plugin_dir_len + dl->length + 1 >= FN_REFLEN)
   {
-    sql_print_error("Cannot open plugin with path '%.64s'", dl);
+    sql_print_error("Cannot open plugin with path '%.64s'", dl->str);
     DBUG_RETURN(0);
   }
   /* If this dll is already loaded just increase ref_count. */
@@ -96,7 +77,7 @@
     DBUG_RETURN(tmp);
   }
   /* Compile dll path */
-  strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl, NullS);
+  strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS);
   plugin_dl.ref_count= 1;
   /* Open new dll handle */
   if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
@@ -130,17 +111,18 @@
   }
   plugin_dl.plugins= (struct st_plugin *)sym;
   /* Duplicate dll name */
-  if (!(plugin_dl.dl= my_strdup(dl, MYF(0))))
+  if (!(plugin_dl.dl.str= my_strdup(dl->str, MYF(0))))
   {
     dlclose(plugin_dl.handle);
-    sql_print_error(ER(ER_OUTOFMEMORY), dl_len + 1);
+    sql_print_error(ER(ER_OUTOFMEMORY), dl->length + 1);
     DBUG_RETURN(0);
   }
+  plugin_dl.dl.length= dl->length;
   /* Add this dll to array */
   if (insert_dynamic(&plugin_dl_array, (gptr)&plugin_dl))
   {
     dlclose(plugin_dl.handle);
-    my_free(plugin_dl.dl, MYF(0));
+    my_free(plugin_dl.dl.str, MYF(0));
     sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
     DBUG_RETURN(0);
   }
@@ -149,7 +131,7 @@
 }
 
 
-static void plugin_dl_del (const char *dl)
+static void plugin_dl_del (LEX_STRING *dl)
 {
   uint i;
   DBUG_ENTER("plugin_dl_del");
@@ -157,24 +139,26 @@
   {
     struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
                                               struct st_plugin_dl *);
-    if (my_strnncoll(files_charset_info,
-                     (const uchar *)dl, strlen(dl),
-                     (const uchar *)tmp->dl, strlen(tmp->dl)))
-      continue;
-    /* Do not remove this element, unless no other plugin uses this dll. */
-    if (! --tmp->ref_count)
+    if (tmp->ref_count &&
+        ! my_strnncoll(files_charset_info,
+                       (const uchar *)dl->str, dl->length,
+                       (const uchar *)tmp->dl.str, tmp->dl.length))
     {
-      dlclose(tmp->handle);
-      my_free(tmp->dl, MYF(0));
-      bzero(tmp, sizeof(struct st_plugin_dl));
+      /* Do not remove this element, unless no other plugin uses this dll. */
+      if (! --tmp->ref_count)
+      {
+        dlclose(tmp->handle);
+        my_free(tmp->dl.str, MYF(0));
+        bzero(tmp, sizeof(struct st_plugin_dl));
+      }
+      break;
     }
-    break;
   }
   DBUG_VOID_RETURN;
 }
 
 
-struct st_plugin *plugin_find (const char *name, int type)
+struct st_plugin_int *plugin_find (LEX_STRING *name, int type)
 {
   uint i;
   DBUG_ENTER("plugin_find");
@@ -187,12 +171,11 @@
                                                struct st_plugin_int *);
     if ((type < 0 || type == tmp->plugin->type) &&
         ! my_strnncoll(system_charset_info,
-                       (const uchar *)name, strlen(name),
-                       (const uchar *)tmp->plugin->name,
-                       strlen(tmp->plugin->name)))
+                       (const uchar *)name->str, name->length,
+                       (const uchar *)tmp->name.str, tmp->name.length))
     {
       rw_unlock(&THR_LOCK_plugin);
-      DBUG_RETURN(tmp->plugin);
+      DBUG_RETURN(tmp);
     }
   }
   rw_unlock(&THR_LOCK_plugin);
@@ -200,7 +183,7 @@
 }
 
 
-static my_bool plugin_add (const char *name, const char *dl)
+static my_bool plugin_add (LEX_STRING *name, LEX_STRING *dl)
 {
   struct st_plugin_int tmp;
   struct st_plugin *plugin;
@@ -212,22 +195,26 @@
   /* Find plugin by name */
   for (plugin= tmp.plugin_dl->plugins; plugin->type; plugin++)
   {
-    if (my_strnncoll(system_charset_info,
-                     (const uchar *)name, strlen(name),
-                     (const uchar *)plugin->name,
-                     strlen(plugin->name)))
-      continue;
-    tmp.plugin= plugin;
-    if (insert_dynamic(&plugin_array, (gptr)&tmp))
-      break;
-    DBUG_RETURN(FALSE);
+    uint name_len= strlen(plugin->name);
+    if (! my_strnncoll(system_charset_info,
+                       (const uchar *)name->str, name->length,
+                       (const uchar *)plugin->name,
+                       name_len))
+    {
+      tmp.plugin= plugin;
+      tmp.name.str= plugin->name;
+      tmp.name.length= name_len;
+      if (insert_dynamic(&plugin_array, (gptr)&tmp))
+        break;
+      DBUG_RETURN(FALSE);
+    }
   }
   plugin_dl_del(dl);
   DBUG_RETURN(TRUE);
 }
 
 
-static void plugin_del (const char *name)
+static void plugin_del (LEX_STRING *name)
 {
   uint i;
   DBUG_ENTER("plugin_del");
@@ -235,15 +222,14 @@
   {
     struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
                                                struct st_plugin_int *);
-    if (my_strnncoll(system_charset_info,
-                     (const uchar *)name, strlen(name),
-                     (const uchar *)tmp->plugin->name,
-                     strlen(tmp->plugin->name)))
-
-      continue;
-    plugin_dl_del(tmp->plugin_dl->dl);
-    delete_dynamic_element(&plugin_array, i);
-    break;
+    if (! my_strnncoll(system_charset_info,
+                       (const uchar *)name->str, name->length,
+                       (const uchar *)tmp->name.str, tmp->name.length))
+    {
+      plugin_dl_del(&tmp->plugin_dl->dl);
+      delete_dynamic_element(&plugin_array, i);
+      break;
+    }
   }
   DBUG_VOID_RETURN;
 }
@@ -293,9 +279,12 @@
   while (!(error= read_record_info.read_record(&read_record_info)))
   {
     DBUG_PRINT("info", ("init plugin record"));
-    const char *name= get_field(&mem, table->field[0]);
-    char *dl= get_field(&mem, table->field[1]);
-    if (plugin_add(name, dl))
+    LEX_STRING name, dl;
+    name.str= get_field(&mem, table->field[0]);
+    name.length= strlen(name.str);
+    dl.str= get_field(&mem, table->field[1]);
+    dl.length= strlen(dl.str);
+    if (plugin_add(&name, &dl))
       DBUG_PRINT("warning", ("Couldn't load plugin named '%s' with soname '%s'.", name, dl));
   }
   if (error > 0)
@@ -322,7 +311,7 @@
     struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
                                               struct st_plugin_dl *);
     dlclose(tmp->handle);
-    my_free(tmp->dl, MYF(0));
+    my_free(tmp->dl.str, MYF(0));
   }
   delete_dynamic(&plugin_dl_array);
   if (initialized)

--- 1.2/sql/sql_plugin.h	2005-08-22 17:39:36 +05:00
+++ 1.3/sql/sql_plugin.h	2005-08-26 18:17:54 +05:00
@@ -17,8 +17,24 @@
 #if !defined(_plugin_h) && defined(HAVE_DLOPEN)
 #define _plugin_h
 #include <plugin.h>
+struct st_plugin_dl
+{
+  LEX_STRING dl;
+  void *handle;
+  struct st_plugin *plugins;
+  int version;
+  uint ref_count;
+};
+
+struct st_plugin_int
+{
+  LEX_STRING name;
+  struct st_plugin *plugin;
+  struct st_plugin_dl *plugin_dl;
+};
+
 extern char *opt_plugin_dir;
 extern void plugin_init(void);
 extern void plugin_free(void);
-extern st_plugin *plugin_find(const char *name, int type);
+extern st_plugin_int *plugin_find(LEX_STRING *name, int type);
 #endif
Thread
bk commit into 5.0 tree (svoj:1.1896)svoj26 Aug