From fcdc6337cfd4d408a55f3dcb20696957c99fded5 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Thu, 28 Aug 2008 17:10:04 -0600 Subject: [PATCH 1/8] add in ability to make queries on 1.9 absolutely simultaneously--currently broken, however--feel free to help out--currently the master branch is faster --- ext/Makefile | 166 ------------------------------------------------- ext/extconf.rb | 5 ++ ext/mysql.c | 28 ++++++++- 3 files changed, 32 insertions(+), 167 deletions(-) delete mode 100644 ext/Makefile diff --git a/ext/Makefile b/ext/Makefile deleted file mode 100644 index cac97bb..0000000 --- a/ext/Makefile +++ /dev/null @@ -1,166 +0,0 @@ - -SHELL = /bin/sh - -#### Start of system configuration section. #### - -srcdir = . -topdir = /usr/local/include/ruby-1.9.0 -hdrdir = /usr/local/include/ruby-1.9.0 -arch_hdrdir = /usr/local/include/ruby-1.9.0/$(arch) -VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby -prefix = $(DESTDIR)/usr/local -exec_prefix = $(prefix) -bindir = $(exec_prefix)/bin -sbindir = $(exec_prefix)/sbin -libexecdir = $(exec_prefix)/libexec -datarootdir = $(prefix)/share -datadir = $(datarootdir) -sysconfdir = $(prefix)/etc -sharedstatedir = $(prefix)/com -localstatedir = $(prefix)/var -includedir = $(prefix)/include -oldincludedir = $(DESTDIR)/usr/include -docdir = $(datarootdir)/doc/$(PACKAGE) -infodir = $(datarootdir)/info -htmldir = $(docdir) -dvidir = $(docdir) -pdfdir = $(docdir) -psdir = $(docdir) -libdir = $(exec_prefix)/lib -localedir = $(datarootdir)/locale -mandir = $(datarootdir)/man -sitedir = $(prefix)/lib/ruby/site_ruby -vendordir = $(prefix)/lib/ruby/vendor_ruby -rubyhdrdir = $(includedir)/ruby-$(MAJOR).$(MINOR).$(TEENY) -sitehdrdir = $(rubyhdrdir)/site_ruby -vendorhdrdir = $(rubyhdrdir)/vendor_ruby -rubylibdir = $(libdir)/ruby/$(ruby_version) -archdir = $(rubylibdir)/$(arch) -sitelibdir = $(sitedir)/$(ruby_version) -sitearchdir = $(sitelibdir)/$(sitearch) -vendorlibdir = $(vendordir)/$(ruby_version) -vendorarchdir = $(vendorlibdir)/$(sitearch) - -CC = gcc -CXX = g++ -LIBRUBY = $(LIBRUBY_A) -LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a -LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -OUTFLAG = -o -COUTFLAG = -o - -RUBY_EXTCONF_H = -CFLAGS = -fPIC -g -O2 $(cflags) -INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir) -I$(srcdir) -DEFS = -D_FILE_OFFSET_BITS=64 -CPPFLAGS = -DHAVE_MYSQL_SSL_SET -DHAVE_RB_STR_SET_LEN -DHAVE_MYSQL_MYSQL_H -I/usr/local/include $(DEFS) $(cppflags) -CXXFLAGS = $(CFLAGS) -g -O2 -ldflags = -L. -rdynamic -Wl,-export-dynamic -dldflags = -archflag = -DLDFLAGS = $(ldflags) $(dldflags) $(archflag) -LDSHARED = $(CC) -shared -LDSHAREDXX = $(CXX) -shared -AR = ar -EXEEXT = - -RUBY_INSTALL_NAME = ruby -RUBY_SO_NAME = ruby -arch = i686-linux -sitearch = i686-linux -ruby_version = 1.9.0 -ruby = /usr/local/bin/ruby -RUBY = $(ruby) -RM = rm -f -MAKEDIRS = mkdir -p -INSTALL = /usr/bin/install -c -INSTALL_PROG = $(INSTALL) -m 0755 -INSTALL_DATA = $(INSTALL) -m 644 -COPY = cp - -#### End of system configuration section. #### - -preload = - -libpath = . $(libdir) /usr/local/lib -LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib -Wl,-R/usr/local/lib -DEFFILE = - -CLEANFILES = mkmf.log -DISTCLEANFILES = - -extout = -extout_prefix = -target_prefix = -LOCAL_LIBS = -LIBS = -lmysqlclient -lpthread -lrt -ldl -lcrypt -lm -lc -SRCS = mysql.c -OBJS = mysql.o -TARGET = mysqlplus -DLLIB = $(TARGET).so -EXTSTATIC = -STATIC_LIB = - -RUBYCOMMONDIR = $(sitedir)$(target_prefix) -RUBYLIBDIR = $(sitelibdir)$(target_prefix) -RUBYARCHDIR = $(sitearchdir)$(target_prefix) -HDRDIR = $(rubyhdrdir)/ruby$(target_prefix) -ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix) - -TARGET_SO = $(DLLIB) -CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map -CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak - -all: $(DLLIB) -static: $(STATIC_LIB) - -clean: - @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) - -distclean: clean - @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log - @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) - -realclean: distclean -install: install-so install-rb - -install-so: $(RUBYARCHDIR) -install-so: $(RUBYARCHDIR)/$(DLLIB) -$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) - $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) -install-rb: pre-install-rb install-rb-default -install-rb-default: pre-install-rb-default -pre-install-rb: Makefile -pre-install-rb-default: Makefile -$(RUBYARCHDIR): - $(MAKEDIRS) $@ - -site-install: site-install-so site-install-rb -site-install-so: install-so -site-install-rb: install-rb - -.SUFFIXES: .c .m .cc .cxx .cpp .C .o - -.cc.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cxx.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cpp.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.C.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.c.o: - $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< - -$(DLLIB): $(OBJS) - @-$(RM) $(@) - $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) - - - -$(OBJS): ruby.h defines.h diff --git a/ext/extconf.rb b/ext/extconf.rb index bc00612..848cb19 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -67,4 +67,9 @@ File.open('error_const.h', 'w') do |f| end end +# check for 1.9 +if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') + $CFLAGS += " -DHAVE_TBR" +end + create_makefile("mysql") diff --git a/ext/mysql.c b/ext/mysql.c index 765cfde..19f91d0 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -683,11 +683,37 @@ static VALUE my_stat(VALUE obj) return rb_tainted_str_new2(s); } +typedef struct +{ + MYSQL *mysql_instance; + MYSQL_RES **store_it_here; + +} mysql_result_to_here_t, + *shared_stuff_p; + +static VALUE store_result_to_location(void *settings_in) +{ + mysql_result_to_here_t *settings = (mysql_result_to_here_t *) settings_in; + *(settings->store_it_here) = mysql_store_result(settings->mysql_instance); // this one runs a good long while for very large queries + return Qnil; +} + /* store_result() */ static VALUE store_result(VALUE obj) { MYSQL* m = GetHandler(obj); - MYSQL_RES* res = mysql_store_result(m); + MYSQL_RES* res = NULL; +#ifndef HAVE_TBR + res = mysql_store_result(m); + //store_result_to_location(m, &res); +#else + mysql_result_to_here_t linker; + linker.mysql_instance = m; + linker.store_it_here = &res; + //store_result_to_location((void *) &linker); + rb_thread_blocking_region(store_result_to_location, (void *) &linker, RB_UBF_DFL, 0); +#endif + if (res == NULL) mysql_raise(m); return mysqlres2obj(res); From 02e265072ca7fa65b2e763bd501bfbfc389d730a Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Mon, 8 Sep 2008 12:39:00 -0600 Subject: [PATCH 2/8] update the RB_UBF_DL for more recent versions of Ruby 1.9, which doesn't have it --- ext/extconf.rb | 10 +++------- ext/mysql.c | 5 ++--- test/test_all_hashes.rb | 3 ++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index c90fedc..d037cc2 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -31,8 +31,9 @@ else exit 1 end -if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') - flags << "-DHAVE_TBR" +# check for 1.9 +if have_func('rb_thread_blocking_region') and have_macro('RUBY_UBF_IO', 'ruby.h') + $CFLAGS += " -DHAVE_TBR " end # make mysql constant @@ -71,9 +72,4 @@ File.open('error_const.h', 'w') do |f| end end -# check for 1.9 -if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') - $CFLAGS += " -DHAVE_TBR" -end - create_makefile("mysql") diff --git a/ext/mysql.c b/ext/mysql.c index 89ee69d..779c2d5 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -711,17 +711,16 @@ static VALUE store_result(VALUE obj) MYSQL_RES* res = NULL; #ifndef HAVE_TBR res = mysql_store_result(m); - //store_result_to_location(m, &res); #else mysql_result_to_here_t linker; linker.mysql_instance = m; linker.store_it_here = &res; - //store_result_to_location((void *) &linker); - rb_thread_blocking_region(store_result_to_location, (void *) &linker, RB_UBF_DFL, 0); + rb_thread_blocking_region(store_result_to_location, (void *) &linker, RUBY_UBF_IO, 0); /* not sure if this should be RUBY_UBF_IO or RUBY_UBF_PROCESS here -- see Ruby 1.9 ChangeLog */ #endif if (res == NULL) mysql_raise(m); + return mysqlres2obj(res); } diff --git a/test/test_all_hashes.rb b/test/test_all_hashes.rb index b9b5119..b5527bf 100644 --- a/test/test_all_hashes.rb +++ b/test/test_all_hashes.rb @@ -1,7 +1,8 @@ # shows the effect of using .all_hashes instead of looping on each hash # run it by substiting in a 'long' [many row] query for the query variable and toggling use_all_hashes here at the top # note that we load all the rows first, then run .all_hashes on the result [to see more easily the effect of all hashes] -# on my machine and a 200_000 row table, it took 3.38s versus 3.65s +# on my machine and a 200_000 row table, it took 3.38s versus 3.65s for the old .each_hash way [note also that .each_hash is +# almost as fast, now, as .all_hashes--they've both been optimized] require 'mysqlplus' use_the_all_hashes_method = true From ee9cf7c47ed486711a0daa2e34ad16ddd187f09a Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Tue, 30 Sep 2008 17:04:06 -0600 Subject: [PATCH 3/8] overcome another merge conflict --- ext/extconf.rb | 2 +- ext/mysql.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index 6877d3c..986bde5 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -35,7 +35,7 @@ end # check for 1.9 if have_func('rb_thread_blocking_region') and have_macro('RUBY_UBF_IO', 'ruby.h') $CFLAGS += " -DHAVE_TBR " - $CPPFLAGS << " -DHAVE_TBR" + $CPPFLAGS << " -DHAVE_TBR " end # make mysql constant diff --git a/ext/mysql.c b/ext/mysql.c index a45c4bf..7d15303 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -231,8 +231,13 @@ static VALUE init(VALUE klass) return obj; } +#if MYSQL_VERSION_ID >= 32200 +int mysql_real_connect_nonblocking() {} + +#endif + /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ -static VALUE real_connect(int argc, VALUE* argv, VALUE klass) +static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets run */ { VALUE host, user, passwd, db, port, sock, flag; char *h, *u, *p, *d, *s; @@ -258,7 +263,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); #if MYSQL_VERSION_ID >= 32200 - mysql_init(&myp->handler); + mysql_init(&myp->handler); /* we get here */ if (mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) @@ -324,6 +329,7 @@ static VALUE client_version(VALUE obj) /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ static VALUE real_connect2(int argc, VALUE* argv, VALUE obj) { + printf("conn2\n"); VALUE host, user, passwd, db, port, sock, flag; char *h, *u, *p, *d, *s; unsigned int pp, f; From ce962ebc7d9b816b3b761ef7827f624251952f12 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Tue, 30 Sep 2008 22:35:59 -0600 Subject: [PATCH 4/8] add in a function to make real_connect non blocking --- ext/mysql.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/ext/mysql.c b/ext/mysql.c index 7d15303..865f1ba 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -6,6 +6,7 @@ #include #include +#include #ifndef RSTRING_PTR #define RSTRING_PTR(str) RSTRING(str)->ptr #endif @@ -234,6 +235,66 @@ static VALUE init(VALUE klass) #if MYSQL_VERSION_ID >= 32200 int mysql_real_connect_nonblocking() {} +typedef struct +{ + void *func_pointer; + int param_count; + void *args[10]; + void *return_val; +} arg_holder, *arg_holder2; + + +static void call_single_function_rb_thread_blocking_region(void *arg_holder_in); + +void *rb_thread_blocking_region_variable_params(int number, ...) +{ + va_list param_pt; // TODO assert <= 10 + va_start(param_pt, number); + int index; + arg_holder param_storer; + void *func_pointer = va_arg(param_pt, void *); + void *interrupter = va_arg(param_pt, void *); + param_storer.func_pointer = func_pointer; + int real_param_count = number - 2; + param_storer.param_count = real_param_count; + for(index = 0 ; index < real_param_count ; index++) + { + void *arg = va_arg(param_pt, void *); + param_storer.args[index] = arg; + + } + va_end(param_pt); + + rb_thread_blocking_region(&call_single_function_rb_thread_blocking_region, (void *) ¶m_storer, interrupter, 0); + + return param_storer.return_val; + +} + +static void call_single_function_rb_thread_blocking_region(void *arg_holder_in) +{ + arg_holder *params_and_func = (arg_holder *) arg_holder_in; + int param_count = params_and_func->param_count; + void *result; + if(param_count == 3) + { + void * (*pt2Func)(void *, void *, void *) = params_and_func->func_pointer; + result = (*pt2Func)(params_and_func->args[0], params_and_func->args[1], params_and_func->args[2]); + }else if(param_count == 6) + { + void * (*pt2Func)(void *, void *, void *, void *, void *, void *) = params_and_func->func_pointer; + result = (*pt2Func)(params_and_func->args[0], params_and_func->args[1], params_and_func->args[2], params_and_func->args[3], params_and_func->args[4], params_and_func->args[5]); + }else if(param_count == 8) + { + void * (*pt2Func)(void *, void *, void *, void *, void *, void *, void *, void *) = params_and_func->func_pointer; + result = (*pt2Func)(params_and_func->args[0], params_and_func->args[1], params_and_func->args[2], params_and_func->args[3], params_and_func->args[4], params_and_func->args[5], params_and_func->args[6], params_and_func->args[7]); + }else + printf("UN nonwn %d\n", param_count); + + params_and_func->return_val = result; +} + + #endif /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ @@ -263,8 +324,10 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); #if MYSQL_VERSION_ID >= 32200 + printf("conn5 -- \n"); mysql_init(&myp->handler); /* we get here */ - if (mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) + int answer = rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f); + if (answer == NULL) #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) #else @@ -329,7 +392,6 @@ static VALUE client_version(VALUE obj) /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ static VALUE real_connect2(int argc, VALUE* argv, VALUE obj) { - printf("conn2\n"); VALUE host, user, passwd, db, port, sock, flag; char *h, *u, *p, *d, *s; unsigned int pp, f; From 4ff863b4f994596b52982f607e7161da24b98634 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Wed, 1 Oct 2008 08:09:55 -0600 Subject: [PATCH 5/8] code cleanup to avoid warnings --- ext/mysql.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ext/mysql.c b/ext/mysql.c index 865f1ba..109ab3e 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -233,7 +233,6 @@ static VALUE init(VALUE klass) } #if MYSQL_VERSION_ID >= 32200 -int mysql_real_connect_nonblocking() {} typedef struct { @@ -265,7 +264,7 @@ void *rb_thread_blocking_region_variable_params(int number, ...) } va_end(param_pt); - rb_thread_blocking_region(&call_single_function_rb_thread_blocking_region, (void *) ¶m_storer, interrupter, 0); + rb_thread_blocking_region((rb_blocking_function_t *)call_single_function_rb_thread_blocking_region, (void *) ¶m_storer, interrupter, 0); return param_storer.return_val; @@ -289,7 +288,10 @@ static void call_single_function_rb_thread_blocking_region(void *arg_holder_in) void * (*pt2Func)(void *, void *, void *, void *, void *, void *, void *, void *) = params_and_func->func_pointer; result = (*pt2Func)(params_and_func->args[0], params_and_func->args[1], params_and_func->args[2], params_and_func->args[3], params_and_func->args[4], params_and_func->args[5], params_and_func->args[6], params_and_func->args[7]); }else - printf("UN nonwn %d\n", param_count); + { + printf("UN nonwn param count--please add it! %d\n", param_count); + result = Qnil; + } params_and_func->return_val = result; } @@ -326,7 +328,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r #if MYSQL_VERSION_ID >= 32200 printf("conn5 -- \n"); mysql_init(&myp->handler); /* we get here */ - int answer = rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f); + VALUE answer = rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f); if (answer == NULL) #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) @@ -1221,7 +1223,7 @@ static VALUE process_all_hashes(VALUE obj, VALUE with_table, int build_array, in { MYSQL_RES* res = GetMysqlRes(obj); unsigned int n = mysql_num_fields(res); - VALUE ary; + VALUE ary = Qnil; if(build_array) ary = rb_ary_new(); MYSQL_ROW row = mysql_fetch_row(res); // grab one off the top, to determine the rows @@ -1288,6 +1290,8 @@ static VALUE process_all_hashes(VALUE obj, VALUE with_table, int build_array, in if(yield) return obj; + + return Qnil; // we should never get here } /* fetch_hash2 (internal) */ From 1404c2bc44cbe8dc0ec2f70ca8b37c4c43fb0c7a Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Fri, 3 Oct 2008 14:11:11 -0600 Subject: [PATCH 6/8] code cleanup, since rb_thread_blocking_region actually returns the value of the function passed to it --- ext/mysql.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ext/mysql.c b/ext/mysql.c index 109ab3e..038c23d 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -232,14 +232,13 @@ static VALUE init(VALUE klass) return obj; } -#if MYSQL_VERSION_ID >= 32200 +#ifdef HAVE_TBR typedef struct { void *func_pointer; int param_count; void *args[10]; - void *return_val; } arg_holder, *arg_holder2; @@ -247,7 +246,7 @@ static void call_single_function_rb_thread_blocking_region(void *arg_holder_in); void *rb_thread_blocking_region_variable_params(int number, ...) { - va_list param_pt; // TODO assert <= 10 + va_list param_pt; // TODO handle all the way through 10 args va_start(param_pt, number); int index; arg_holder param_storer; @@ -264,9 +263,7 @@ void *rb_thread_blocking_region_variable_params(int number, ...) } va_end(param_pt); - rb_thread_blocking_region((rb_blocking_function_t *)call_single_function_rb_thread_blocking_region, (void *) ¶m_storer, interrupter, 0); - - return param_storer.return_val; + return rb_thread_blocking_region((rb_blocking_function_t *)call_single_function_rb_thread_blocking_region, (void *) ¶m_storer, interrupter, 0); } @@ -293,10 +290,9 @@ static void call_single_function_rb_thread_blocking_region(void *arg_holder_in) result = Qnil; } - params_and_func->return_val = result; + return result; } - #endif /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ @@ -326,10 +322,13 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); #if MYSQL_VERSION_ID >= 32200 - printf("conn5 -- \n"); + printf("conn5 -- \n"); mysql_init(&myp->handler); /* we get here */ - VALUE answer = rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f); - if (answer == NULL) +#ifdef HAVE_TBR + if( (int) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f) == NULL) +#else + if(mysql_real_connect +#endif #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) #else From 8099da577d6fef8f3b0d1592f55d6c2b78a38f1d Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Fri, 31 Oct 2008 12:37:00 -0600 Subject: [PATCH 7/8] allow the 19_non_gvl branch to work with 1.8, also fix some warnings --- ext/mysql.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/mysql.c b/ext/mysql.c index 038c23d..0079af7 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -327,7 +327,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r #ifdef HAVE_TBR if( (int) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f) == NULL) #else - if(mysql_real_connect + if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) #endif #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) @@ -862,8 +862,13 @@ static VALUE socket(VALUE obj) static VALUE socket_type(VALUE obj) { MYSQL* m = GetHandler(obj); + char *answer; VALUE description = vio_description( m->net.vio ); - return NILorSTRING( description ); + answer = NILorSTRING( description ); + if(answer) + return Qtrue; // TODO return a ruby string + else + return Qnil; } /* blocking */ From d2549f3907e39d30807ff874c48b99166beb87a3 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Sat, 20 Dec 2008 23:07:21 +0000 Subject: [PATCH 8/8] remove test output --- ext/mysql.c | 7 +++---- test/test_parsing_while_response_is_being_read.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/mysql.c b/ext/mysql.c index d885e02..6fa282f 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -322,13 +322,12 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); #if MYSQL_VERSION_ID >= 32200 - printf("conn5 -- \n"); mysql_init(&myp->handler); /* we get here */ -#ifdef HAVE_TBR +# ifdef HAVE_TBR if( (int) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f) == NULL) -#else +# else if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) -#endif +# endif #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) #else diff --git a/test/test_parsing_while_response_is_being_read.rb b/test/test_parsing_while_response_is_being_read.rb index 3f6883f..7f4d237 100644 --- a/test/test_parsing_while_response_is_being_read.rb +++ b/test/test_parsing_while_response_is_being_read.rb @@ -5,7 +5,7 @@ # from .82s to .62s # you can experiment with it by changing the query here to be a long one, and toggling the do_the_use_query_optimization variable # this also has the interesting property of 'freeing' Ruby to do thread changes mid-query. - +require 'rubygems' require 'mysqlplus' do_the_use_query_optimization = true