Gemification and updated extconf.rb

master
mattbauer 2008-12-27 20:12:49 -06:00
parent b9d57911df
commit e505f13f17
14 changed files with 146 additions and 280 deletions

105
ChangeLog
View File

@ -1,105 +0,0 @@
2007-01-20 16:32 tag R0_8
2007-01-20 16:32 danj
* bdb.c: resolve #906. Changed cursor management semantics. Should
eliminate SEGV during finalize cleanup
2006-12-21 19:48 danj
* extconf.rb: make dbh find work a little better with --dbh arg
2006-12-21 19:48 danj
* bdb.c: add set/get shm key
2006-12-12 11:13 danj
* extconf.rb: add more berkeley locations
2006-12-12 11:12 danj
* bdb.c: add hash page controls
2006-07-11 17:02 danj
* bdb.c: fix db_stat wild pointer for txn
2006-05-15 17:28 tag R0_7
2006-05-15 17:28 danj
* bdb.c, bdb.h: another cpp fix
2006-05-15 17:22 danj
* bdb.h: fix for linux
2006-05-15 12:35 tag R0_6
2006-05-15 12:35 danj
* bdb.h, extconf.rb: expand automagic configuration
2006-05-12 20:41 tag R0_5
2006-05-12 20:41 danj
* bdb.c: compat for 4.2
2006-05-10 15:03 danj
* bdb.c: fix hash and queue stat variable creation (macro was
wrong)
2006-05-04 15:45 tag R0_4
2006-05-04 15:45 danj
* bdb.c: fix aproc initialization
2006-04-24 20:56 tag R0_3
2006-04-24 20:56 danj
* bdb.c: finished initial round of rdoc
2006-04-24 16:48 danj
* bdb.c: adding rdoc, unfinished
2006-04-24 15:40 danj
* bdb.c, extconf.rb: make extconf.rb accept --va so the library can
coexist with bdb2 release prior to transactions. Note, howerver
the two libraries cannot be used at the same time
2006-04-24 14:21 danj
* bdb.c: add truncate and sync
2006-04-24 14:12 danj
* bdb.c: status for db and txn
2006-04-21 16:45 danj
* bdb.c, bdb.h: added transactions, cleanup of finalizers, addition
of pget, in process of adding many other API calls
2006-03-06 12:44 danj
* bdb.h, extconf.rb: fix solaris install problems
2006-02-13 21:56 tag R0_2
2006-02-13 21:56 danj
* MANIFEST, bdb.c, bdb.h, extconf.rb, README, status.txt, test.rb:
Initial
2006-02-13 21:56 danj
* MANIFEST, bdb.c, bdb.h, extconf.rb, README, status.txt, test.rb:
Initial revision

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2008 Dan Janowski <danj@3skel.com>, Matt Bauer <bauer@pedalbrain.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,2 +0,0 @@
bdb2.c
rusage.c

43
Rakefile Normal file
View File

@ -0,0 +1,43 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
load 'bdb.gemspec'
Rake::GemPackageTask.new(BDB_SPEC) do |pkg|
pkg.need_tar = true
end
task :default => "test"
desc "Clean"
task :clean do
include FileUtils
rm_rf File.join('ext', 'bdb_aux._c')
rm_rf File.join('ext', 'Makefile')
rm_rf File.join('ext', 'mkmf.log')
rm_rf File.join('ext', 'conftest.c')
rm_rf File.join('ext', '*.o')
rm_rf 'pkg'
end
desc "Run tests"
Rake::TestTask.new("test") do |t|
t.libs << ["test", "ext"]
t.pattern = 'test/*_test.rb'
t.verbose = true
t.warning = true
end
task :doc => [:rdoc]
namespace :doc do
Rake::RDocTask.new do |rdoc|
files = ["README", "lib/**/*.rb"]
rdoc.rdoc_files.add(files)
rdoc.main = "README.textile"
rdoc.title = "Bdb Docs"
rdoc.rdoc_dir = "doc"
rdoc.options << "--line-numbers" << "--inline-source"
end
end

17
bdb.gemspec Normal file
View File

@ -0,0 +1,17 @@
BDB_SPEC = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.required_ruby_version = '>=1.8.4'
s.name = "bdb"
s.version = "0.0.1"
s.authors = ["Matt Bauer", "Dan Janowski"]
s.email = "bauer@pedalbrain.com"
s.summary = "A Ruby interface to BerkeleyDB"
s.files = FileList['lib/**/*', 'ext/**/*', 'test/**/*', 'LICENSE', 'README.textile', 'Rakefile'].to_a
s.extensions = ["ext/extconf.rb"]
s.homepage = "http://github.com/mattbauer/bdb"
s.require_paths = ["lib", "ext"]
s.test_files = Dir.glob('test/*.rb')
s.has_rdoc = true
end

View File

@ -2528,7 +2528,7 @@ VALUE txn_set_timeout(VALUE obj, VALUE vtimeout, VALUE vflags)
* Developed against 4.3/4.4. No support for prior versions.
*/
void Init_bdb2() {
void Init_bdb() {
fv_call=rb_intern("call");
fv_err_new=rb_intern("new");
fv_err_code=rb_intern("@code");

View File

@ -17,7 +17,6 @@
#endif
#include <version.h>
#include <extconf.h>
#include <db.h>
#define NOTXN NULL
@ -70,10 +69,10 @@ typedef struct s_txnh {
t_envh *env;
} t_txnh;
#define cu(b,m) \
#define cu(b,m) \
rb_define_const(b,#m,UINT2NUM(m))
#define ci(b,m) \
#define ci(b,m) \
rb_define_const(b,#m,INT2NUM(m))
#define cs(b,m) \
@ -89,13 +88,13 @@ VALUE db_ ## fname ## _eq(VALUE obj, VALUE v) \
#define attr_writer(fname) \
VALUE fname ## _writer(VALUE obj, VALUE v) \
{ \
rb_ivar_set(obj,fv_ ## fname,v); \
return obj; \
rb_ivar_set(obj,fv_ ## fname,v); \
return obj; \
}
#define attr_reader(fname) \
VALUE fname ## _reader(VALUE obj) \
{ \
{ \
return rb_ivar_get(obj,fv_ ## fname); \
}

59
ext/extconf.rb Normal file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env ruby
require 'mkmf'
dir_config('db')
versions=%w(db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
until versions.empty?
(lib_ok = have_library(versions.shift,'db_version', 'db.h')) && break
end
def create_header
if File.exist?("bdb_aux._c")
message("Not writing bdb_aux._c (defines), already exists\n")
return
end
message("Writing bdb_aux._c (defines), this takes a while\n")
db_header = $CPPFLAGS.split.select { |f| f =~ /^-I/ }.map { |e|
f = File.join(e[2..-1], 'db.h')
File.exists?(f) ? f : nil
}.select { |e| e }.first
n=0
defines=[]
File.open(db_header) {|fd|
File.open("bdb_aux._c","w") {|hd|
hd.puts("/* This file automatically generated by extconf.rb */\n")
fd.each_line {|l|
if l =~ %r{^#define\s+(DBC?_\w*)\s+([^\/]*)\s*(.*?)(\/\*.*)?$}
name = $1
value = $2
if macro_defined?(name,"#include <db.h>")
case value
when /^"/
hd.print(%Q{cs(mBdb,%s);\n}%[name])
when /^\(?(0x|\d)/
hd.print(%Q{cu(mBdb,%s);\n}%[name])
when /^\(?-/
hd.print(%Q{ci(mBdb,%s);\n}%[name])
else
$stderr.puts "don't know how to handle #{name} #{value.strip}, guessing UINT"
hd.print(%Q{cu(mBdb,%s);\n}%[name])
end
n+=1
end
end
}
}
message("\nwrote #{n} defines\n")
}
end
if lib_ok
create_header
create_makefile('bdb')
else
$stderr.puts("cannot create Makefile")
exit 1
end

View File

@ -1,122 +0,0 @@
#!/usr/bin/env ruby
require 'mkmf'
$distcleanfiles=["bdb_aux._c"]
dir_config('db')
mj,mi,rv=RUBY_VERSION.split('.').collect {|s| s.to_i}
ri=(((mj*1000)+mi)*1000)+rv
if ri < 1008004
$stderr.puts("Version 1.8.4 minimum required")
exit(3)
end
versions=%w(db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
until versions.empty?
(lib_ok=find_library(this_version=versions.shift,'db_create')) && break
end
$stderr.puts(this_version)
$maj,$min=0,0
if try_link0(<<SRC)
#include <db.h>
#include <stdio.h>
main() {
int maj,min;
db_version(&maj,&min,NULL);
printf("%d %d",maj,min);
}
SRC
xpopen("./conftest") do |f|
$maj,$min=f.gets.chomp.split.collect {|v| v.to_i}
end
libpath=`ldd conftest`.split.find {|e| e =~ %r{/.+#{this_version}} }
$stderr.puts("library path #{libpath}")
rm_f("conftest*")
else
message("unable to compile against found DB library\n")
exit
end
message("Found DB version #{$maj}.#{$min} in #{libpath}\n")
# lets find its header now
incpath=libpath
while incpath!= "/"
incpath=File.dirname(incpath)
i=File.join(incpath,"include","db.h")
if File.exist?(i)
incpath=i ; break
end
end
if incpath=="/"
message("unable to find db.h")
exit
end
incpath=File.dirname(incpath)
message("Found db.h in #{incpath}\n")
def check_header dir
opt=if dir; "-I#{dir}".quote; else nil; end
hmaj=hmin=nil
if try_cpp(cpp_include("db.h"),opt)
if (hmaj=try_constant("DB_VERSION_MAJOR","db.h",opt)) and
(hmin=try_constant("DB_VERSION_MINOR","db.h",opt)) and
hmaj.to_i == $maj and hmin.to_i == $min
message("Found matching db.h with #{opt}\n")
$INCFLAGS << " " << opt
$db_inc=dir
return true
else
if hmaj
message("found a db.h, but wrong version (lib) #{$maj}.#{$min} != (db.h) #{hmaj}.#{hmin}\n")
end
end
end
false
end
exit unless check_header(incpath)
inc="#include <db.h>"
n=0
message("Writing bdb_aux._c (defines), this takes a while\n")
defines=[]
File.open(File.join($db_inc,"db.h")) {|fd|
File.open("bdb_aux._c","w") {|hd|
hd.puts("/* This file automatically generated by extconf.rb */\n")
fd.each_line {|l|
if l =~ %r{^#define\s+(DBC?_\w*)\s+([^\/]*)\s*(.*?)(\/\*.*)?$}
name = $1
value = $2
if macro_defined?(name,inc)
case value
when /^"/
hd.print(%Q{ cs(mBdb,%s);\n}%[name])
when /^\(?(0x|\d)/
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
when /^\(?-/
hd.print(%Q{ ci(mBdb,%s);\n}%[name])
else
$stderr.puts "don't know how to handle #{name} #{value}, guessing UINT"
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
end
n+=1
end
end
}
}
message("\nwrote #{n} defines\n")
} unless File.exist?("bdb_aux._c")
$defs << $INCFLAGS
if lib_ok
create_header
create_makefile('bdb2')
else
$stderr.puts("cannot create Makefile")
end

View File

@ -1,43 +0,0 @@
20-Jan-2007
The library is stable. With the 0.8 release, the last known bug has been
resolved. The library now has transactions, many more environment
management functions (hash params, shm, etc), and open transactions,
cursors and databases are tracked and properly cleaned up during finalization,
or at least when env.close is called. The library is size stable (no leaks)
and is being used in a heavy production environment with great reliability.
The future:
There are numerous DB controls that are not yet in the interface, as well
as handling sequences and other DB features. There has been no call for
them yet, so they linger.
The build system is a little weak. DB can be installed in so many different
places and variety of versions, making version selection tricky. There is
a complication, in that it is not enough for the compiler chain to find the
db.h and libraries, the build needs to find the exact db.h, because symbols
are extracted from it to generate the Ruby-side defines. It would be nice to
fix the build process and to turn it into a Gem.
Numerous, more ruby-like, methods need to be added. Probably in just a .rb
file to wrap and increase the ease of use for the core methods. The methods
do not deal with variable argument lists as they are largely faithful to
the DB API. But methods like cursor#next, cursor#first, and cursor.each
are appropriate.
9-Feb-2006
Done:
All common environment, database and cursor functions are in. They are also
_fully_ unit tested and are in production under heavy use. There are a
few missing, like pget.
Limitations:
If Ruby process exits and there are any open cursors (your program did not
close them) the process will SEGV. This is due to dbc_free trying to close
the cursor(s), even though the DB may already be closed. This will be fixed
by keeping track of open cursors and automatically closing then when
db->close is called, either by calling close or during finalization. Other
than messing up your BDB environment, the SEGV is larglely harmless (but
annoying). It should never happen if your program is written correctly.

View File

@ -1,5 +1,5 @@
#!/usr/bin/env ruby
require 'bdb2'
require 'test_helper'
50.times {|n|
db=Bdb::Db.new

1
test/test_helper.rb Normal file
View File

@ -0,0 +1 @@
require "bdb"