From 95db3c74dfe5d9c8a3654754f2c9a0a908f6b90d Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Sun, 26 Sep 2010 17:09:25 -0300 Subject: [PATCH 1/7] Use MySQL 5.1.51 now from available mirror --- tasks/compile.rake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/compile.rake b/tasks/compile.rake index 4dae1b2..5e65e86 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -1,9 +1,8 @@ gem 'rake-compiler', '~> 0.7.1' require "rake/extensiontask" -MYSQL_VERSION = "5.1.50" -MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.mirrors.pair.com" - +MYSQL_VERSION = "5.1.51" +MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/" def gemspec @clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__))) From 553c9a77c3526702276eb2aed330df0fe763dda6 Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Sun, 26 Sep 2010 17:14:52 -0300 Subject: [PATCH 2/7] Inject 1.8/1.9 pure-ruby entry point during xcompile The original problem of .so files not included in the final gemspec is because rake-compiler put files in lib_dir/X.Y/extension while the pure-ruby entry point was looking for lib_dir/XY/extension --- tasks/compile.rake | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tasks/compile.rake b/tasks/compile.rake index 5e65e86..eb6b3b0 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -21,6 +21,11 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] ext.cross_config_options << "--with-mysql-include=#{mysql_lib}/include" ext.cross_config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + + # inject 1.8/1.9 pure-ruby entry point when cross compiling only + ext.cross_compiling do |spec| + spec.files << 'lib/mysql2/mysql2.rb' + end end ext.lib_dir = File.join 'lib', 'mysql2' @@ -30,25 +35,16 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| end Rake::Task[:spec].prerequisites << :compile -namespace :cross do - task :file_list do - gemspec.extensions = [] - gemspec.files += Dir["lib/#{gemspec.name}/#{gemspec.name}.rb"] - gemspec.files += Dir["lib/#{gemspec.name}/1.{8,9}/#{gemspec.name}.so"] - # gemspec.files += Dir["ext/mysql2/*.dll"] - end -end - -file 'lib/mysql2/mysql2.rb' do +file 'lib/mysql2/mysql2.rb' do |t| name = gemspec.name - File.open("lib/#{name}/#{name}.rb", 'wb') do |f| + File.open(t.name, 'wb') do |f| f.write <<-eoruby -require "#{name}/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/#{name}" +RUBY_VERSION =~ /(\\d+.\\d+)/ +require "#{name}/\#{$1}/#{name}" eoruby end end if Rake::Task.task_defined?(:cross) Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb" - Rake::Task[:cross].prerequisites << "cross:file_list" end From 685538ce528ff080e91396b1349dbaa990d5318d Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Sun, 26 Sep 2010 17:25:23 -0300 Subject: [PATCH 3/7] Dry windows configuration options --- tasks/compile.rake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tasks/compile.rake b/tasks/compile.rake index eb6b3b0..d46766c 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -12,15 +12,19 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| # reference where the vendored MySQL got extracted mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32")) + # DRY options feed into compile or cross-compile process + windows_options = [ + "--with-mysql-include=#{mysql_lib}/include", + "--with-mysql-lib=#{mysql_lib}/lib/opt" + ] + # automatically add build options to avoid need of manual input if RUBY_PLATFORM =~ /mswin|mingw/ then - ext.config_options << "--with-mysql-include=#{mysql_lib}/include" - ext.config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + ext.config_options = windows_options else ext.cross_compile = true ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] - ext.cross_config_options << "--with-mysql-include=#{mysql_lib}/include" - ext.cross_config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + ext.cross_config_options = windows_options # inject 1.8/1.9 pure-ruby entry point when cross compiling only ext.cross_compiling do |spec| From 307b92b966efc9e3b4cf5f666c03c815190feb20 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Mon, 27 Sep 2010 11:17:47 -0700 Subject: [PATCH 4/7] whoops, lost this line in a previous patch --- ext/mysql2/client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 395728b..6119380 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -140,6 +140,7 @@ static VALUE nogvl_close(void * ptr) { mysql_client_wrapper *wrapper = ptr; if (!wrapper->closed) { mysql_close(wrapper->client); + client->net.fd = -1; wrapper->closed = 1; } return Qnil; From 4383885634cf0bca81a0dcae6f322fb2e1db177f Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Mon, 27 Sep 2010 13:24:37 -0700 Subject: [PATCH 5/7] was in a hurry earlier --- ext/mysql2/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 6119380..a1bfaf1 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -140,7 +140,7 @@ static VALUE nogvl_close(void * ptr) { mysql_client_wrapper *wrapper = ptr; if (!wrapper->closed) { mysql_close(wrapper->client); - client->net.fd = -1; + wrapper->client->net.fd = -1; wrapper->closed = 1; } return Qnil; From 2ae908c512eeb1e5524561d9f6dff08e60db1452 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Mon, 27 Sep 2010 13:25:10 -0700 Subject: [PATCH 6/7] make sure we don't hit a race condition if this EM spec is taking longer to run than normal --- spec/em/em_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/em/em_spec.rb b/spec/em/em_spec.rb index ac4f65b..2213cff 100644 --- a/spec/em/em_spec.rb +++ b/spec/em/em_spec.rb @@ -7,7 +7,7 @@ describe Mysql2::EM::Client do results = [] EM.run do client1 = Mysql2::EM::Client.new - defer1 = client1.query "SELECT sleep(0.05) as first_query" + defer1 = client1.query "SELECT sleep(0.1) as first_query" defer1.callback do |result| results << result.first EM.stop_event_loop From 687487d5a5cc675d9a91f2998d4470a633052a65 Mon Sep 17 00:00:00 2001 From: Anton Mironov Date: Mon, 27 Sep 2010 21:46:30 +0800 Subject: [PATCH 7/7] Detach before executing callbacks. This allows to make queries in callbacks. --- lib/mysql2/em.rb | 2 +- spec/em/em_spec.rb | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/mysql2/em.rb b/lib/mysql2/em.rb index 6d95549..98da1e6 100644 --- a/lib/mysql2/em.rb +++ b/lib/mysql2/em.rb @@ -13,12 +13,12 @@ module Mysql2 end def notify_readable + detach begin @deferable.succeed(@client.async_result) rescue Exception => e @deferable.fail(e) end - detach end end diff --git a/spec/em/em_spec.rb b/spec/em/em_spec.rb index 2213cff..1254c4c 100644 --- a/spec/em/em_spec.rb +++ b/spec/em/em_spec.rb @@ -19,8 +19,27 @@ describe Mysql2::EM::Client do results << result.first end end - + results[0].keys.should include("second_query") results[1].keys.should include("first_query") end + + it "should support queries in callbacks" do + results = [] + EM.run do + client = Mysql2::EM::Client.new + defer1 = client.query "SELECT sleep(0.025) as first_query" + defer1.callback do |result| + results << result.first + defer2 = client.query "SELECT sleep(0.025) as second_query" + defer2.callback do |result| + results << result.first + EM.stop_event_loop + end + end + end + + results[0].keys.should include("first_query") + results[1].keys.should include("second_query") + end end