Skip to content

Commit d4d37f1

Browse files
WL#2936
"Server variables for plugins" Post review fixes.
1 parent dc24473 commit d4d37f1

13 files changed

Lines changed: 156 additions & 69 deletions

File tree

client/mysql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ static struct my_option my_long_options[] =
743743
"Number of seconds before connection timeout.",
744744
(gptr*) &opt_connect_timeout,
745745
(gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
746-
0, 1},
746+
0, 0},
747747
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
748748
"Max packet length to send to, or receive from server",
749749
(gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, GET_ULONG,

include/my_getopt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct my_option
5454
longlong max_value; /* Max allowed value */
5555
longlong sub_size; /* Subtract this from given value */
5656
long block_size; /* Value should be a mult. of this */
57-
long app_type; /* To be used by an application */
57+
void *app_type; /* To be used by an application */
5858
};
5959

6060
typedef my_bool (* my_get_one_option) (int, const struct my_option *, char * );

include/my_global.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ C_MODE_END
458458
*/
459459
#include <assert.h>
460460

461+
/* an assert that works at compile-time. only for constant expression */
462+
#define compile_time_assert(X) \
463+
do \
464+
{ \
465+
char compile_time_assert[(X) ? 1 : -1] \
466+
__attribute__ ((unused)); \
467+
} while(0)
468+
461469
/* Go around some bugs in different OS and compilers */
462470
#if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
463471
#define _LARGEFILE64_SOURCE

include/mysql/plugin.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,43 @@ typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *)
122122
struct st_mysql_sys_var;
123123
struct st_mysql_value;
124124

125+
/*
126+
SYNOPSIS
127+
(*mysql_var_check_func)()
128+
thd thread handle
129+
var dynamic variable being altered
130+
save pointer to temporary storage
131+
value user provided value
132+
RETURN
133+
0 user provided value is OK and the update func may be called.
134+
any other value indicates error.
135+
136+
This function should parse the user provided value and store in the
137+
provided temporary storage any data as required by the update func.
138+
There is sufficient space in the temporary storage to store a double.
139+
Note that the update func may not be called if any other error occurs
140+
so any memory allocated should be thread-local so that it may be freed
141+
automatically at the end of the statement.
142+
*/
143+
125144
typedef int (*mysql_var_check_func)(MYSQL_THD thd,
126145
struct st_mysql_sys_var *var,
127146
void *save, struct st_mysql_value *value);
147+
148+
/*
149+
SYNOPSIS
150+
(*mysql_var_update_func)()
151+
thd thread handle
152+
var dynamic variable being altered
153+
var_ptr pointer to dynamic variable
154+
save pointer to temporary storage
155+
RETURN
156+
NONE
157+
158+
This function should use the validated value stored in the temporary store
159+
and persist it in the provided pointer to the dynamic variable.
160+
For example, strings may require memory to be allocated.
161+
*/
128162
typedef void (*mysql_var_update_func)(MYSQL_THD thd,
129163
struct st_mysql_sys_var *var,
130164
void *var_ptr, void *save);
@@ -582,6 +616,10 @@ struct st_mysql_information_schema
582616
st_mysql_value struct for reading values from mysqld.
583617
Used by server variables framework to parse user-provided values.
584618
Will be used for arguments when implementing UDFs.
619+
620+
Note that val_str() returns a string in temporary memory
621+
that will be freed at the end of statement. Copy the string
622+
if you need it to persist.
585623
*/
586624

587625
#define MYSQL_VALUE_TYPE_STRING 0

mysys/array.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
5757
}
5858

5959
if (!init_alloc)
60+
{
6061
init_alloc=alloc_increment;
61-
else
6262
init_buffer= 0;
63+
}
6364
array->elements=0;
6465
array->max_element=init_alloc;
6566
array->alloc_increment=alloc_increment;

mysys/typelib.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <m_ctype.h>
2121

2222

23+
static const char field_separator=',';
24+
2325
/*
2426
Search after a string in a list of strings. Endspace in x is not compared.
2527
@@ -31,6 +33,7 @@
3133
If & 1 accept only whole names
3234
If & 2 don't expand if half field
3335
If & 4 allow #number# as type
36+
If & 8 use ',' as string terminator
3437
3538
NOTES
3639
If part, uniq field is found and full_name == 0 then x is expanded
@@ -60,16 +63,18 @@ int find_type(my_string x, TYPELIB *typelib, uint full_name)
6063
for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
6164
{
6265
for (i=x ;
63-
*i && my_toupper(&my_charset_latin1,*i) ==
66+
*i && (!(full_name & 8) || *i != field_separator) &&
67+
my_toupper(&my_charset_latin1,*i) ==
6468
my_toupper(&my_charset_latin1,*j) ; i++, j++) ;
6569
if (! *j)
6670
{
6771
while (*i == ' ')
6872
i++; /* skip_end_space */
69-
if (! *i)
73+
if (! *i || ((full_name & 8) && *i == field_separator))
7074
DBUG_RETURN(pos+1);
7175
}
72-
if (! *i && (!*j || !(full_name & 1)))
76+
if ((!*i && (!(full_name & 8) || *i != field_separator)) &&
77+
(!*j || !(full_name & 1)))
7378
{
7479
find++;
7580
findpos=pos;
@@ -120,8 +125,6 @@ const char *get_type(TYPELIB *typelib, uint nr)
120125
}
121126

122127

123-
static const char field_separator=',';
124-
125128
/*
126129
Create an integer value to represent the supplied comma-seperated
127130
string where each string in the TYPELIB denotes a bit position.
@@ -157,9 +160,7 @@ my_ulonglong find_typeset(my_string x, TYPELIB *lib, int *err)
157160
(*err)++;
158161
i= x;
159162
while (*x && *x != field_separator) x++;
160-
if (*x)
161-
*x++= 0;
162-
if ((find= find_type(i, lib, 2) - 1) < 0)
163+
if ((find= find_type(i, lib, 2 | 8) - 1) < 0)
163164
DBUG_RETURN(0);
164165
result|= (ULL(1) << find);
165166
}

sql/set_var.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,6 @@ int set_var_init()
28382838

28392839
error:
28402840
fprintf(stderr, "failed to initialize system variables");
2841-
pthread_mutex_unlock(&LOCK_global_system_variables);
28422841
DBUG_RETURN(1);
28432842
}
28442843

sql/sql_class.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,35 +167,45 @@ Open_tables_state::Open_tables_state(ulong version_arg)
167167
reset_open_tables_state();
168168
}
169169

170+
/*
171+
The following functions form part of the C plugin API
172+
*/
173+
174+
extern "C"
170175
int thd_in_lock_tables(const THD *thd)
171176
{
172177
return test(thd->in_lock_tables);
173178
}
174179

175180

181+
extern "C"
176182
int thd_tablespace_op(const THD *thd)
177183
{
178184
return test(thd->tablespace_op);
179185
}
180186

181187

188+
extern "C"
182189
const char *thd_proc_info(THD *thd, const char *info)
183190
{
184191
const char *old_info= thd->proc_info;
185192
thd->proc_info= info;
186193
return old_info;
187194
}
188195

196+
extern "C"
189197
void **thd_ha_data(const THD *thd, const struct handlerton *hton)
190198
{
191199
return (void **) thd->ha_data + hton->slot;
192200
}
193201

202+
extern "C"
194203
long long thd_test_options(const THD *thd, long long test_options)
195204
{
196205
return thd->options & test_options;
197206
}
198207

208+
extern "C"
199209
int thd_sql_command(const THD *thd)
200210
{
201211
return (int) thd->lex->sql_command;
@@ -216,6 +226,7 @@ int thd_sql_command(const THD *thd)
216226
RETURN VALUES
217227
pointer to string
218228
*/
229+
extern "C"
219230
char *thd_security_context(THD *thd, char *buffer, int length,
220231
int max_query_len)
221232
{
@@ -268,6 +279,7 @@ char *thd_security_context(THD *thd, char *buffer, int length,
268279
return thd->strmake(str.ptr(), str.length());
269280
}
270281

282+
271283
/*
272284
Pass nominal parameters to Statement constructor only to ensure that
273285
the destructor works OK in case of error. The main_mem_root will be

sql/sql_lex.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,9 @@ st_lex::st_lex()
17451745
:result(0), yacc_yyss(0), yacc_yyvs(0),
17461746
sql_command(SQLCOM_END)
17471747
{
1748+
/* Check that plugins_static_buffer is declared immediately after plugins */
1749+
compile_time_assert((&plugins + 1) == (DYNAMIC_ARRAY*)plugins_static_buffer);
1750+
17481751
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
17491752
plugins_static_buffer,
17501753
INITIAL_LEX_PLUGIN_LIST_SIZE,

0 commit comments

Comments
 (0)