~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_udf.cc

Merged from jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* This implements 'user defined functions' */
17
17
#include <drizzled/server_includes.h>
18
 
#include <drizzled/gettext.h>
19
18
 
20
19
static bool udf_startup= false; /* We do not lock because startup is single threaded */
21
20
static MEM_ROOT mem;
22
21
static HASH udf_hash;
23
22
 
24
 
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
 
23
extern "C" uchar* get_hash_key(const uchar *buff, size_t *length,
25
24
                               bool not_used __attribute__((unused)))
26
25
{
27
26
  udf_func *udf= (udf_func*) buff;
28
27
  *length= (uint) udf->name.length;
29
 
  return (unsigned char*) udf->name.str;
 
28
  return (uchar*) udf->name.str;
30
29
}
31
30
 
32
31
 
36
35
 
37
36
  if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0))
38
37
  {
39
 
    sql_print_error(_("Can't allocate memory for udf structures"));
 
38
    sql_print_error("Can't allocate memory for udf structures");
40
39
    hash_free(&udf_hash);
41
40
    free_root(&mem, MYF(0));
42
41
    return;
51
50
}
52
51
 
53
52
/* This is only called if using_udf_functions != 0 */
54
 
udf_func *find_udf(const char *name, uint32_t length)
 
53
udf_func *find_udf(const char *name, uint length)
55
54
{
56
55
  udf_func *udf;
57
56
 
59
58
    return NULL;
60
59
 
61
60
  udf= (udf_func*) hash_search(&udf_hash,
62
 
                               (unsigned char*) name,
 
61
                               (uchar*) name,
63
62
                               length ? length : (uint) strlen(name));
64
63
 
65
64
  return (udf);
67
66
 
68
67
static bool add_udf(udf_func *udf)
69
68
{
70
 
  if (my_hash_insert(&udf_hash, (unsigned char*) udf))
 
69
  if (my_hash_insert(&udf_hash, (uchar*) udf))
71
70
    return false;
72
71
 
73
72
  using_udf_functions= 1;
77
76
 
78
77
int initialize_udf(st_plugin_int *plugin)
79
78
{
80
 
  udf_func *f;
 
79
  udf_func *udff;
81
80
 
82
81
  if (udf_startup == false)
83
82
  {
84
83
    udf_init();
85
84
    udf_startup= true;
86
85
  }
 
86
          
 
87
  /* allocate the udf_func structure */
 
88
  udff = (udf_func *)my_malloc(sizeof(udf_func), MYF(MY_WME | MY_ZEROFILL));
 
89
  if (udff == NULL) return 1;
 
90
 
 
91
  plugin->data= (void *)udff;
87
92
 
88
93
  if (plugin->plugin->init)
89
94
  {
90
 
    int r;
91
 
    if ((r= plugin->plugin->init((void *)&f)))
 
95
    /* todo, if the plugin doesnt have an init, bail out */
 
96
 
 
97
    if (plugin->plugin->init((void *)udff))
92
98
    {
93
 
      sql_print_error("Plugin '%s' init function returned error %d.",
94
 
                      plugin->name.str, r);
95
 
      return r;
 
99
      sql_print_error("Plugin '%s' init function returned error.",
 
100
                      plugin->name.str);
 
101
      goto err;
96
102
    }
97
103
  }
98
 
  else
99
 
    return 1;
100
 
 
101
 
  if(!add_udf(f))
102
 
    return 2;
 
104
  
 
105
  add_udf(udff);
103
106
 
104
107
  return 0;
105
 
 
 
108
err:
 
109
  my_free(udff, MYF(0));
 
110
  return 1;
106
111
}
107
112
 
108
113
int finalize_udf(st_plugin_int *plugin)
114
119
    (void)plugin->plugin->deinit(udff);
115
120
 
116
121
  if (udff)
117
 
    free(udff);
 
122
    my_free(udff, MYF(0));
118
123
 
119
124
  return 0;
120
125
}