Skip to content

Commit d101d14

Browse files
author
Sergei Golubchik
committed
WL#4903 Plugin Service API part I
(mysql-next-mr backport)
1 parent d3bf417 commit d101d14

34 files changed

Lines changed: 764 additions & 258 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ ADD_SUBDIRECTORY(extra)
311311
ADD_SUBDIRECTORY(client)
312312
ADD_SUBDIRECTORY(sql)
313313
ADD_SUBDIRECTORY(libmysql)
314+
ADD_SUBDIRECTORY(libservices)
314315
ADD_SUBDIRECTORY(tests)
315316
IF(WITH_EMBEDDED_SERVER)
316317
ADD_SUBDIRECTORY(libmysqld)

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \
2323

2424
SUBDIRS = . include @docs_dirs@ @zlib_dir@ \
2525
@readline_topdir@ sql-common scripts \
26-
@pstack_dir@ \
26+
@pstack_dir@ libservices \
2727
@sql_union_dirs@ unittest \
2828
@sql_server@ @man_dirs@ tests \
2929
netware @libmysqld_dirs@ \
@@ -32,7 +32,7 @@ SUBDIRS = . include @docs_dirs@ @zlib_dir@ \
3232

3333
DIST_SUBDIRS = . include Docs zlib \
3434
cmd-line-utils sql-common scripts \
35-
pstack \
35+
pstack libservices \
3636
strings mysys dbug extra regex libmysql libmysql_r client unittest storage plugin \
3737
vio sql man tests \
3838
netware libmysqld \

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,7 @@ AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
29462946
man/Makefile BUILD/Makefile vio/Makefile dnl
29472947
libmysql/Makefile libmysql_r/Makefile client/Makefile dnl
29482948
sql/Makefile sql/share/Makefile dnl
2949-
sql/sql_builtin.cc sql-common/Makefile dnl
2949+
sql/sql_builtin.cc sql-common/Makefile libservices/Makefile dnl
29502950
dbug/Makefile scripts/Makefile include/Makefile dnl
29512951
tests/Makefile Docs/Makefile support-files/Makefile dnl
29522952
support-files/MacOSX/Makefile support-files/RHEL4-SElinux/Makefile dnl

include/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ HEADERS_GEN_MAKE = my_config.h
2121
HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \
2222
my_list.h my_alloc.h typelib.h mysql/plugin.h
2323
pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
24-
my_xml.h mysql_embed.h \
24+
my_xml.h mysql_embed.h mysql/services.h \
25+
mysql/service_my_snprintf.h mysql/service_thd_alloc.h \
2526
my_pthread.h my_no_pthread.h \
2627
decimal.h errmsg.h my_global.h my_net.h \
2728
my_getopt.h sslopt-longopts.h my_dir.h \
@@ -36,7 +37,7 @@ noinst_HEADERS = config-win.h config-netware.h my_bit.h \
3637
my_nosys.h my_alarm.h queues.h rijndael.h sha1.h \
3738
my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \
3839
thr_lock.h t_ctype.h violite.h my_md5.h base64.h \
39-
my_handler.h my_time.h \
40+
my_handler.h my_time.h service_versions.h \
4041
my_vle.h my_user.h my_atomic.h atomic/nolock.h \
4142
atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h \
4243
atomic/solaris.h \

include/m_string.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,10 @@ extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
250250

251251
/*
252252
LEX_STRING -- a pair of a C-string and its length.
253+
(it's part of the plugin API as a MYSQL_LEX_STRING)
253254
*/
254255

255-
#ifndef _my_plugin_h
256-
/* This definition must match the one given in mysql/plugin.h */
257-
struct st_mysql_lex_string
258-
{
259-
char *str;
260-
size_t length;
261-
};
262-
#endif
256+
#include <mysql/plugin.h>
263257
typedef struct st_mysql_lex_string LEX_STRING;
264258

265259
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))

include/my_sys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ extern void my_error _VARARGS((int nr,myf MyFlags, ...));
683683
extern void my_printf_error _VARARGS((uint my_err, const char *format,
684684
myf MyFlags, ...))
685685
ATTRIBUTE_FORMAT(printf, 2, 4);
686+
extern void my_printv_error(uint error, const char *format, myf MyFlags,
687+
va_list ap);
686688
extern int my_error_register(const char** (*get_errmsgs) (),
687689
int first, int last);
688690
extern const char **my_error_unregister(int first, int last);

include/mysql/plugin.h

Lines changed: 5 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2005 MySQL AB
1+
/* Copyright (C) 2005 MySQL AB, 2009 Sun Microsystems, Inc.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -16,12 +16,6 @@
1616
#ifndef _my_plugin_h
1717
#define _my_plugin_h
1818

19-
/* size_t */
20-
#include <stdlib.h>
21-
22-
typedef struct st_mysql MYSQL;
23-
24-
2519
/*
2620
On Windows, exports from DLL need to be declared
2721
*/
@@ -39,15 +33,7 @@ class Item;
3933
#define MYSQL_THD void*
4034
#endif
4135

42-
#ifndef _m_string_h
43-
/* This definition must match the one given in m_string.h */
44-
struct st_mysql_lex_string
45-
{
46-
char *str;
47-
unsigned int length;
48-
};
49-
#endif /* _m_string_h */
50-
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
36+
#include <mysql/services.h>
5137

5238
#define MYSQL_XIDDATASIZE 128
5339
/**
@@ -70,7 +56,7 @@ typedef struct st_mysql_xid MYSQL_XID;
7056
Plugin API. Common for all plugin types.
7157
*/
7258

73-
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0100
59+
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0101
7460

7561
/*
7662
The allowable types of plugins
@@ -126,7 +112,8 @@ enum enum_mysql_show_type
126112
{
127113
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
128114
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
129-
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
115+
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
116+
SHOW_always_last
130117
};
131118

132119
struct st_mysql_show_var {
@@ -750,54 +737,6 @@ int thd_killed(const MYSQL_THD thd);
750737
*/
751738
unsigned long thd_get_thread_id(const MYSQL_THD thd);
752739

753-
754-
/**
755-
Allocate memory in the connection's local memory pool
756-
757-
@details
758-
When properly used in place of @c my_malloc(), this can significantly
759-
improve concurrency. Don't use this or related functions to allocate
760-
large chunks of memory. Use for temporary storage only. The memory
761-
will be freed automatically at the end of the statement; no explicit
762-
code is required to prevent memory leaks.
763-
764-
@see alloc_root()
765-
*/
766-
void *thd_alloc(MYSQL_THD thd, unsigned int size);
767-
/**
768-
@see thd_alloc()
769-
*/
770-
void *thd_calloc(MYSQL_THD thd, unsigned int size);
771-
/**
772-
@see thd_alloc()
773-
*/
774-
char *thd_strdup(MYSQL_THD thd, const char *str);
775-
/**
776-
@see thd_alloc()
777-
*/
778-
char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
779-
/**
780-
@see thd_alloc()
781-
*/
782-
void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
783-
784-
/**
785-
Create a LEX_STRING in this connection's local memory pool
786-
787-
@param thd user thread connection handle
788-
@param lex_str pointer to LEX_STRING object to be initialized
789-
@param str initializer to be copied into lex_str
790-
@param size length of str, in bytes
791-
@param allocate_lex_string flag: if TRUE, allocate new LEX_STRING object,
792-
instead of using lex_str value
793-
@return NULL on failure, or pointer to the LEX_STRING object
794-
795-
@see thd_alloc()
796-
*/
797-
MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
798-
const char *str, unsigned int size,
799-
int allocate_lex_string);
800-
801740
/**
802741
Get the XID for this connection's transaction
803742
@@ -818,64 +757,6 @@ void mysql_query_cache_invalidate4(MYSQL_THD thd,
818757
const char *key, unsigned int key_length,
819758
int using_trx);
820759

821-
/**
822-
Get the value of user variable as an integer.
823-
824-
This function will return the value of variable @a name as an
825-
integer. If the original value of the variable is not an integer,
826-
the value will be converted into an integer.
827-
828-
@param name user variable name
829-
@param value pointer to return the value
830-
@param null_value if not NULL, the function will set it to true if
831-
the value of variable is null, set to false if not
832-
833-
@retval 0 Success
834-
@retval 1 Variable not found
835-
*/
836-
int get_user_var_int(const char *name,
837-
long long int *value, int *null_value);
838-
839-
/**
840-
Get the value of user variable as a double precision float number.
841-
842-
This function will return the value of variable @a name as real
843-
number. If the original value of the variable is not a real number,
844-
the value will be converted into a real number.
845-
846-
@param name user variable name
847-
@param value pointer to return the value
848-
@param null_value if not NULL, the function will set it to true if
849-
the value of variable is null, set to false if not
850-
851-
@retval 0 Success
852-
@retval 1 Variable not found
853-
*/
854-
int get_user_var_real(const char *name,
855-
double *value, int *null_value);
856-
857-
/**
858-
Get the value of user variable as a string.
859-
860-
This function will return the value of variable @a name as
861-
string. If the original value of the variable is not a string,
862-
the value will be converted into a string.
863-
864-
@param name user variable name
865-
@param value pointer to the value buffer
866-
@param len length of the value buffer
867-
@param precision precision of the value if it is a float number
868-
@param null_value if not NULL, the function will set it to true if
869-
the value of variable is null, set to false if not
870-
871-
@retval 0 Success
872-
@retval 1 Variable not found
873-
*/
874-
int get_user_var_str(const char *name,
875-
char *value, unsigned long len,
876-
unsigned int precision, int *null_value);
877-
878-
879760
#ifdef __cplusplus
880761
}
881762
#endif

include/mysql/plugin.h.pp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1+
#include <mysql/services.h>
2+
#include <mysql/service_my_snprintf.h>
3+
#include <stdarg.h>
4+
#include <stdlib.h>
5+
extern struct my_snprintf_service_st {
6+
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
7+
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
8+
} *my_snprintf_service;
9+
size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
10+
size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
11+
#include <mysql/service_thd_alloc.h>
112
#include <stdlib.h>
2-
typedef struct st_mysql MYSQL;
313
struct st_mysql_lex_string
414
{
515
char *str;
6-
unsigned int length;
16+
size_t length;
717
};
818
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
19+
extern struct thd_alloc_service_st {
20+
void *(*thd_alloc_func)(void*, unsigned int);
21+
void *(*thd_calloc_func)(void*, unsigned int);
22+
char *(*thd_strdup_func)(void*, const char *);
23+
char *(*thd_strmake_func)(void*, const char *, unsigned int);
24+
void *(*thd_memdup_func)(void*, const void*, unsigned int);
25+
MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *,
26+
const char *, unsigned int, int);
27+
} *thd_alloc_service;
28+
void *thd_alloc(void* thd, unsigned int size);
29+
void *thd_calloc(void* thd, unsigned int size);
30+
char *thd_strdup(void* thd, const char *str);
31+
char *thd_strmake(void* thd, const char *str, unsigned int size);
32+
void *thd_memdup(void* thd, const void* str, unsigned int size);
33+
MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
34+
const char *str, unsigned int size,
35+
int allocate_lex_string);
936
struct st_mysql_xid {
1037
long formatID;
1138
long gtrid_length;
@@ -17,7 +44,8 @@
1744
{
1845
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
1946
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
20-
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
47+
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
48+
SHOW_always_last
2149
};
2250
struct st_mysql_show_var {
2351
const char *name;
@@ -107,9 +135,9 @@
107135
{
108136
int interface_version;
109137
};
110-
struct Mysql_replication {
111-
int interface_version;
112-
};
138+
struct Mysql_replication {
139+
int interface_version;
140+
};
113141
struct st_mysql_value
114142
{
115143
int (*value_type)(struct st_mysql_value *);
@@ -130,22 +158,7 @@
130158
int mysql_tmpfile(const char *prefix);
131159
int thd_killed(const void* thd);
132160
unsigned long thd_get_thread_id(const void* thd);
133-
void *thd_alloc(void* thd, unsigned int size);
134-
void *thd_calloc(void* thd, unsigned int size);
135-
char *thd_strdup(void* thd, const char *str);
136-
char *thd_strmake(void* thd, const char *str, unsigned int size);
137-
void *thd_memdup(void* thd, const void* str, unsigned int size);
138-
MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
139-
const char *str, unsigned int size,
140-
int allocate_lex_string);
141161
void thd_get_xid(const void* thd, MYSQL_XID *xid);
142162
void mysql_query_cache_invalidate4(void* thd,
143163
const char *key, unsigned int key_length,
144164
int using_trx);
145-
int get_user_var_int(const char *name,
146-
long long int *value, int *null_value);
147-
int get_user_var_real(const char *name,
148-
double *value, int *null_value);
149-
int get_user_var_str(const char *name,
150-
char *value, unsigned long len,
151-
unsigned int precision, int *null_value);

0 commit comments

Comments
 (0)