integrate K. Burge changes
This commit is contained in:
parent
b869f6b33b
commit
ef151477bf
7
bdb.h
7
bdb.h
|
@ -23,7 +23,7 @@
|
|||
#define FNLEN 40
|
||||
|
||||
#define filename_copy(fp,fv) \
|
||||
strncpy(fp,RSTRING(fv)->ptr,FNLEN);
|
||||
strncpy(fp,RSTRING_PTR(fv),FNLEN);
|
||||
|
||||
#define filename_dup(fpd,fps) \
|
||||
strncpy(fpd,fps,FNLEN);
|
||||
|
@ -57,8 +57,11 @@ typedef struct s_txnh {
|
|||
t_envh *env;
|
||||
} t_txnh;
|
||||
|
||||
#define cu(b,m) \
|
||||
rb_define_const(b,#m,UINT2NUM(m))
|
||||
|
||||
#define ci(b,m) \
|
||||
rb_define_const(b,#m,INT2FIX(m))
|
||||
rb_define_const(b,#m,INT2NUM(m))
|
||||
|
||||
#define cs(b,m) \
|
||||
rb_define_const(b,#m,rb_str_new2(m))
|
||||
|
|
37
extconf.rb
37
extconf.rb
|
@ -18,6 +18,10 @@ Options:
|
|||
calls. Note the impact on indicating the include, below.
|
||||
If you have not used bdb2 before, you need not use this argument.
|
||||
|
||||
--nsl add nsl rpc library to build (4.4 uses rpc for replication)
|
||||
|
||||
--usedb berkeley db root
|
||||
|
||||
-h,--help this
|
||||
|
||||
--dbh {dir for db.h}
|
||||
|
@ -30,7 +34,9 @@ end
|
|||
|
||||
opts = GetoptLong.new(
|
||||
[ "--va", GetoptLong::NO_ARGUMENT],
|
||||
[ "--nsl", GetoptLong::NO_ARGUMENT],
|
||||
[ "-h","--help",GetoptLong::NO_ARGUMENT],
|
||||
[ "--usedb", GetoptLong::REQUIRED_ARGUMENT],
|
||||
[ "--dbh", GetoptLong::REQUIRED_ARGUMENT]
|
||||
)
|
||||
opts.each do |opt,arg|
|
||||
|
@ -42,6 +48,10 @@ opts.each do |opt,arg|
|
|||
exit
|
||||
when '--dbh'
|
||||
$dbh_location=arg
|
||||
when '--nsl'
|
||||
$libs << " -lnsl"
|
||||
when '--usedb'
|
||||
$usedb=arg
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,12 +85,14 @@ when /solaris2/
|
|||
$libs << " -lnsl"
|
||||
end
|
||||
|
||||
versions=%w(db-4.5 db-4.4 db-4.3 db-4.2)
|
||||
locations=%w(/usr/local/lib /opt/local/lib /usr/local/BerkeleyDB.4.3/lib /usr/local/BerkeleyDB.4.2/lib /opt/csw/bdb44/lib)
|
||||
versions=%w(db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
|
||||
locations=%w(/usr/local/lib /opt/local/lib /usr/lib)
|
||||
until versions.empty?
|
||||
(lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break
|
||||
end
|
||||
|
||||
$stderr.puts(this_version)
|
||||
|
||||
$maj,$min=0,0
|
||||
if try_link0(<<SRC)
|
||||
#include <db.h>
|
||||
|
@ -129,6 +141,7 @@ h_test_locations=%w(
|
|||
/usr/local
|
||||
/opt/csw/bdb44/include
|
||||
)
|
||||
h_test_locations.unshift($usedb) if $usedb
|
||||
h_test_locations.unshift($dbh_location) if $dbh_location
|
||||
message("Header test locations are #{h_test_locations.inspect}\n")
|
||||
found=false
|
||||
|
@ -157,7 +170,7 @@ end
|
|||
# the above result, but it is another check.
|
||||
# Find db.h, not sure this will work everywhere, gcc is ok
|
||||
src=create_tmpsrc("#include <db.h>")
|
||||
cmd=cpp_command("-M")
|
||||
cmd=cpp_command(RUBY_PLATFORM =~ /mswin/ ? nil : "-M")
|
||||
r=`#{cmd}`
|
||||
header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0]
|
||||
message("header is #{header_loc}\n")
|
||||
|
@ -170,15 +183,25 @@ 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+(\"?)} and macro_defined?($1,inc)
|
||||
if $2 == '\"'
|
||||
hd.print(%Q{ cs(mBdb,%s);\n}%[$1])
|
||||
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
|
||||
hd.print(%Q{ ci(mBdb,%s);\n}%[$1])
|
||||
$stderr.puts "don't know how to handle #{name} #{value}, guessing UINT"
|
||||
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
|
||||
end
|
||||
message(".")
|
||||
n+=1
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
message("\nwrote #{n} defines\n")
|
||||
|
|
51
test.rb
51
test.rb
|
@ -67,6 +67,7 @@ $stderr.puts("All OK!")
|
|||
File.delete('db1.db') if File.exist?('db1.db')
|
||||
File.delete('db2.db') if File.exist?('db2.db')
|
||||
|
||||
if File.exist?('skus')
|
||||
db=Bdb::Db.new
|
||||
db.open(nil,"db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
|
||||
|
||||
|
@ -79,9 +80,8 @@ db.associate(nil,db2,0,
|
|||
key.split('-')[0]
|
||||
})
|
||||
|
||||
def write_data(db)
|
||||
c=0
|
||||
IO.popen("gzip -dc skus.gz") {|fd|
|
||||
File.open("skus") {|fd|
|
||||
tlen=fd.stat.size
|
||||
pf=tlen/10
|
||||
pl=0
|
||||
|
@ -89,24 +89,28 @@ def write_data(db)
|
|||
c+=1
|
||||
if c%1000==0
|
||||
$stderr.print('.')
|
||||
cp=fd.pos
|
||||
if ( cp/pf > pl )
|
||||
pl=cp/pf
|
||||
$stderr.print(" #{pl*10}% ")
|
||||
end
|
||||
end
|
||||
line.chomp!
|
||||
n=line*50 # multiply the amount of data written
|
||||
n=line*50
|
||||
isbn,item=line.split('|')[0..1]
|
||||
sku="%s-%03d"%[isbn,item]
|
||||
db.put(nil,sku,line,0)
|
||||
db.put(sku,line,0)
|
||||
end
|
||||
} if File.exist?("skus.gz")
|
||||
}
|
||||
$stderr.print("\ntotal count: #{c}\n")
|
||||
end
|
||||
|
||||
write_data(db)
|
||||
|
||||
db2.close(0)
|
||||
db.close(0)
|
||||
end
|
||||
|
||||
$stderr.puts("test environment")
|
||||
|
||||
if File.exist?('skus')
|
||||
env=Bdb::Env.new(0)
|
||||
env.cachesize=25*1024*1024;
|
||||
env.open(".",Bdb::DB_INIT_CDB|Bdb::DB_INIT_MPOOL|Bdb::DB_CREATE,0)
|
||||
|
@ -122,9 +126,36 @@ db.associate(nil,db2,0,
|
|||
proc {|sdb,key,data|
|
||||
key.split('-')[0]
|
||||
})
|
||||
|
||||
write_data(db)
|
||||
c=0
|
||||
File.open("skus") {|fd|
|
||||
tlen=fd.stat.size
|
||||
pf=tlen/10
|
||||
pl=0
|
||||
fd.each do |line|
|
||||
c+=1
|
||||
if c%1000==0
|
||||
$stderr.print('.')
|
||||
cp=fd.pos
|
||||
if ( cp/pf > pl )
|
||||
pl=cp/pf
|
||||
$stderr.print(" #{pl*10}% ")
|
||||
end
|
||||
end
|
||||
line.chomp!
|
||||
n=line*50
|
||||
isbn,item=line.split('|')[0..1]
|
||||
sku="%s-%03d"%[isbn,item]
|
||||
db.put(sku,line,0)
|
||||
end
|
||||
}
|
||||
$stderr.print("\ntotal count: #{c}\n")
|
||||
|
||||
db2.close(0)
|
||||
db.close(0)
|
||||
env.close
|
||||
end
|
||||
|
||||
exit
|
||||
|
||||
$stderr.puts(Rusage.get.inspect)
|
||||
$stderr.puts(`ps -up #{$$}`)
|
||||
|
|
Loading…
Reference in a new issue