merging in latest from master
This commit is contained in:
commit
6c4fd8a9ca
44
Rakefile
44
Rakefile
@ -1,49 +1,5 @@
|
||||
# encoding: UTF-8
|
||||
begin
|
||||
require 'rubygems'
|
||||
require 'jeweler'
|
||||
JEWELER = Jeweler::Tasks.new do |gem|
|
||||
gem.name = "mysql2"
|
||||
gem.summary = "A simple, fast Mysql library for Ruby, binding to libmysql"
|
||||
gem.email = "seniorlopez@gmail.com"
|
||||
gem.homepage = "http://github.com/brianmario/mysql2"
|
||||
gem.authors = ["Brian Lopez"]
|
||||
gem.require_paths = ["lib", "ext"]
|
||||
gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n")
|
||||
gem.files = `git ls-files`.split("\n")
|
||||
gem.extensions = ["ext/mysql2/extconf.rb"]
|
||||
gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)
|
||||
# gem.rubyforge_project = "mysql2"
|
||||
end
|
||||
rescue LoadError
|
||||
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
|
||||
end
|
||||
|
||||
require 'rake'
|
||||
require 'spec/rake/spectask'
|
||||
|
||||
desc "Run all examples with RCov"
|
||||
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
||||
t.spec_files = FileList['spec/']
|
||||
t.rcov = true
|
||||
t.rcov_opts = lambda do
|
||||
IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
||||
end
|
||||
end
|
||||
Spec::Rake::SpecTask.new('spec') do |t|
|
||||
t.spec_files = FileList['spec/']
|
||||
t.spec_opts << '--options' << 'spec/spec.opts'
|
||||
t.verbose = true
|
||||
t.warning = true
|
||||
end
|
||||
|
||||
Spec::Rake::SpecTask.new('spec:gdb') do |t|
|
||||
t.spec_files = FileList['spec/']
|
||||
t.spec_opts << '--options' << 'spec/spec.opts'
|
||||
t.ruby_cmd = "gdb --args #{RUBY}"
|
||||
end
|
||||
|
||||
task :default => :spec
|
||||
|
||||
# Load custom tasks
|
||||
Dir['tasks/*.rake'].sort.each { |f| load f }
|
||||
|
@ -1,20 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
||||
|
||||
require 'rubygems'
|
||||
require 'benchmark'
|
||||
require 'mysql2'
|
||||
|
||||
iterations = 1000
|
||||
client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "test")
|
||||
query = lambda{ iterations.times{ client.query("SELECT mysql2_test.* FROM mysql2_test") } }
|
||||
Benchmark.bmbm do |x|
|
||||
x.report('select') do
|
||||
query.call
|
||||
end
|
||||
x.report('rb_thread_select') do
|
||||
thread = Thread.new{ sleep(10) }
|
||||
query.call
|
||||
thread.kill
|
||||
end
|
||||
end
|
@ -104,8 +104,10 @@ static VALUE nogvl_connect(void *ptr) {
|
||||
return client ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static void rb_mysql_client_free(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)ptr;
|
||||
static VALUE nogvl_close(void *ptr) {
|
||||
mysql_client_wrapper *wrapper = ptr;
|
||||
if (!wrapper->closed) {
|
||||
wrapper->closed = 1;
|
||||
|
||||
/*
|
||||
* we'll send a QUIT message to the server, but that message is more of a
|
||||
@ -129,37 +131,29 @@ static void rb_mysql_client_free(void * ptr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* It's safe to call mysql_close() on an already closed connection. */
|
||||
if (!wrapper->closed) {
|
||||
mysql_close(wrapper->client);
|
||||
if (!wrapper->freed) {
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
static VALUE nogvl_close(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = ptr;
|
||||
if (!wrapper->closed) {
|
||||
wrapper->closed = 1;
|
||||
mysql_close(wrapper->client);
|
||||
wrapper->client->net.fd = -1;
|
||||
if (!wrapper->freed) {
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static void rb_mysql_client_free(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)ptr;
|
||||
|
||||
nogvl_close(wrapper);
|
||||
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
static VALUE allocate(VALUE klass) {
|
||||
VALUE obj;
|
||||
mysql_client_wrapper * wrapper;
|
||||
obj = Data_Make_Struct(klass, mysql_client_wrapper, rb_mysql_client_mark, rb_mysql_client_free, wrapper);
|
||||
wrapper->encoding = Qnil;
|
||||
wrapper->active = 0;
|
||||
wrapper->closed = 0;
|
||||
wrapper->freed = 0;
|
||||
wrapper->closed = 1;
|
||||
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
|
||||
return obj;
|
||||
}
|
||||
@ -523,6 +517,7 @@ static VALUE init_connection(VALUE self) {
|
||||
return rb_raise_mysql2_error(wrapper->client);
|
||||
}
|
||||
|
||||
wrapper->closed = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,6 @@ typedef struct {
|
||||
VALUE encoding;
|
||||
short int active;
|
||||
short int closed;
|
||||
short int freed;
|
||||
MYSQL *client;
|
||||
} mysql_client_wrapper;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# encoding: UTF-8
|
||||
if defined? EventMachine
|
||||
require 'spec_helper'
|
||||
require 'mysql2/em'
|
||||
|
||||
@ -43,3 +44,6 @@ describe Mysql2::EM::Client do
|
||||
results[1].keys.should include("second_query")
|
||||
end
|
||||
end
|
||||
else
|
||||
puts "EventMachine not installed, skipping the specs that use it"
|
||||
end
|
@ -1,2 +0,0 @@
|
||||
--format specdoc
|
||||
--colour
|
@ -1,10 +1,11 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'rubygems'
|
||||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
||||
require 'rspec'
|
||||
require 'mysql2'
|
||||
require 'timeout'
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
RSpec.configure do |config|
|
||||
config.before(:all) do
|
||||
client = Mysql2::Client.new :database => 'test'
|
||||
client.query %[
|
||||
|
17
tasks/jeweler.rake
Normal file
17
tasks/jeweler.rake
Normal file
@ -0,0 +1,17 @@
|
||||
begin
|
||||
require 'jeweler'
|
||||
JEWELER = Jeweler::Tasks.new do |gem|
|
||||
gem.name = "mysql2"
|
||||
gem.summary = "A simple, fast Mysql library for Ruby, binding to libmysql"
|
||||
gem.email = "seniorlopez@gmail.com"
|
||||
gem.homepage = "http://github.com/brianmario/mysql2"
|
||||
gem.authors = ["Brian Lopez"]
|
||||
gem.require_paths = ["lib", "ext"]
|
||||
gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n")
|
||||
gem.files = `git ls-files`.split("\n")
|
||||
gem.extensions = ["ext/mysql2/extconf.rb"]
|
||||
gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)
|
||||
end
|
||||
rescue LoadError
|
||||
puts "jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
||||
end
|
16
tasks/rspec.rake
Normal file
16
tasks/rspec.rake
Normal file
@ -0,0 +1,16 @@
|
||||
begin
|
||||
require 'rspec'
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
desc "Run all examples with RCov"
|
||||
RSpec::Core::RakeTask.new('spec:rcov') do |t|
|
||||
t.rcov = true
|
||||
end
|
||||
RSpec::Core::RakeTask.new('spec') do |t|
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
task :default => :spec
|
||||
rescue LoadError
|
||||
puts "rspec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
|
||||
end
|
Loading…
Reference in New Issue
Block a user