ruby-changes:22453
From: naruse <ko1@a...>
Date: Thu, 9 Feb 2012 11:13:52 +0900 (JST)
Subject: [ruby-changes:22453] naruse:r34502 (ruby_1_9_3): merge revision(s) 33959,33963,34265:
naruse 2012-02-09 11:12:10 +0900 (Thu, 09 Feb 2012) New Revision: 34502 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34502 Log: merge revision(s) 33959,33963,34265: * ext/dbm/extconf.rb: detect gdbm_version in libgdbm. * ext/dbm/dbm.c: make DBM::VERSION more informative for gdbm, qdbm and Berkeley DB 1.x. [ruby-dev:44944] * ext/dbm/dbm.c: use db_version() instead of DB_VERSION_STRING to detect runtime Berkeley DB version. use dpversion instead of _QDBM_VERSION to detect runtime QDBM version. [ruby-dev:44948] * ext/dbm/dbm.c (Init_dbm): fix a build error on mswin32. use `extern __declspec(dllimport)` for dll link with VC. [ruby-core:41996] [Bug #5869] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/ext/dbm/dbm.c branches/ruby_1_9_3/ext/dbm/extconf.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34501) +++ ruby_1_9_3/ChangeLog (revision 34502) @@ -1,3 +1,24 @@ +Thu Feb 9 11:11:15 2012 Hiroshi Shirosaki <h.shirosaki@g...> + + * ext/dbm/dbm.c (Init_dbm): fix a build error on mswin32. + use `extern __declspec(dllimport)` for dll link with VC. + [ruby-core:41996] [Bug #5869] + +Thu Feb 9 11:11:15 2012 Tanaka Akira <akr@f...> + + * ext/dbm/dbm.c: use db_version() instead of DB_VERSION_STRING to + detect runtime Berkeley DB version. + use dpversion instead of _QDBM_VERSION to detect runtime QDBM + version. + [ruby-dev:44948] + +Thu Feb 9 11:11:15 2012 Tanaka Akira <akr@f...> + + * ext/dbm/extconf.rb: detect gdbm_version in libgdbm. + + * ext/dbm/dbm.c: make DBM::VERSION more informative for gdbm, qdbm and + Berkeley DB 1.x. [ruby-dev:44944] + Thu Feb 9 07:32:40 2012 NARUSE, Yui <naruse@r...> * numeric.c (rb_enc_uint_char): raise RangeError when added codepoint Index: ruby_1_9_3/ext/dbm/dbm.c =================================================================== --- ruby_1_9_3/ext/dbm/dbm.c (revision 34501) +++ ruby_1_9_3/ext/dbm/dbm.c (revision 34502) @@ -901,10 +901,13 @@ * The exact library used depends on how Ruby was compiled. It could be any * of the following: * + * - The original ndbm library is released in 4.3BSD. + * It is based on dbm library in Unix Version 7 but has different API to + * support multiple databases in a process. * - {Berkeley DB}[http://en.wikipedia.org/wiki/Berkeley_DB] versions * 1 thru 5, also known as BDB and Sleepycat DB, now owned by Oracle * Corporation. - * - ndbm, aka Berkeley DB 1.x, still found in FreeBSD and OpenBSD. + * - Berkeley DB 1.x, still found in FreeBSD and OpenBSD. * - {gdbm}[http://www.gnu.org/software/gdbm/], the GNU implementation of dbm. * - {qdbm}[http://fallabs.com/qdbm/index.html], another open source * reimplementation of dbm. @@ -1016,9 +1019,23 @@ */ rb_define_const(rb_cDBM, "NEWDB", INT2FIX(O_RDWR|O_CREAT|O_TRUNC|RUBY_DBM_RW_BIT)); -#ifdef DB_VERSION_STRING +#if defined(HAVE_DB_VERSION) /* The version of the dbm library, if using Berkeley DB */ - rb_define_const(rb_cDBM, "VERSION", rb_str_new2(DB_VERSION_STRING)); + rb_define_const(rb_cDBM, "VERSION", rb_str_new2(db_version(NULL, NULL, NULL))); +#elif defined(HAVE_GDBM_VERSION) + /* since gdbm 1.9 */ + rb_define_const(rb_cDBM, "VERSION", rb_str_new2(gdbm_version)); +#elif defined(HAVE_LIBVAR_GDBM_VERSION) + /* ndbm.h doesn't declare gdbm_version until gdbm 1.8.3. + * See extconf.rb for more information. */ + { + RUBY_EXTERN char *gdbm_version; + rb_define_const(rb_cDBM, "VERSION", rb_str_new2(gdbm_version)); + } +#elif defined(HAVE_DPVERSION) + rb_define_const(rb_cDBM, "VERSION", rb_sprintf("QDBM %s", dpversion)); +#elif defined(_DB_H_) + rb_define_const(rb_cDBM, "VERSION", rb_str_new2("Berkeley DB (unknown)")); #else rb_define_const(rb_cDBM, "VERSION", rb_str_new2("unknown")); #endif Index: ruby_1_9_3/ext/dbm/extconf.rb =================================================================== --- ruby_1_9_3/ext/dbm/extconf.rb (revision 34501) +++ ruby_1_9_3/ext/dbm/extconf.rb (revision 34502) @@ -5,52 +5,113 @@ if dblib = with_config("dbm-type", nil) dblib = dblib.split(/[ ,]+/) else - dblib = %w(db db2 db1 db5 db4 db3 dbm gdbm gdbm_compat qdbm) + dblib = %w(libc db db2 db1 db5 db4 db3 dbm gdbm gdbm_compat qdbm) end headers = { + "libc" => ["ndbm.h"], # 4.4BSD libc contains Berkeley DB 1. "db" => ["db.h"], "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"], "db2" => ["db2/db.h", "db2.h", "db.h"], "db3" => ["db3/db.h", "db3.h", "db.h"], "db4" => ["db4/db.h", "db4.h", "db.h"], "db5" => ["db5/db.h", "db5.h", "db.h"], - "dbm" => ["ndbm.h"], - "gdbm" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], - "gdbm_compat" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], + "dbm" => ["ndbm.h"], # traditional ndbm (4.3BSD) + "gdbm" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], # gdbm until 1.8.0 + "gdbm_compat" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], # gdbm since 1.8.1 "qdbm" => ["relic.h", "qdbm/relic.h"], } -def headers.db_check(db) - db_prefix = nil +class << headers + attr_accessor :found + attr_accessor :defs +end +headers.found = [] +headers.defs = nil + +def headers.db_check(db, hdr) + old_libs = $libs.dup + old_defs = $defs.dup + result = db_check2(db, hdr) + if !result + $libs = old_libs + $defs = old_defs + end + result +end + +def have_libvar(var, headers = nil, opt = "", &b) + checking_for checking_message([*var].compact.join(' '), headers, opt) do + try_libvar(var, headers, opt, &b) + end +end + +def try_libvar(var, headers = nil, opt = "", &b) + var, type = *var + if try_link(<<"SRC", opt, &b) +#{cpp_include(headers)} +/*top*/ +int main(int argc, char *argv[]) { + typedef #{type || 'int'} conftest_type; + extern conftest_type #{var}; + conftest_type *conftest_var = &#{var}; + return 0; +} +SRC + $defs.push(format("-DHAVE_LIBVAR_%s", var.tr_cpp)) + true + else + false + end +end + + +def headers.db_check2(db, hdr) + db_prefix = '' have_gdbm = false hsearch = nil case db when /^db[2-5]?$/ db_prefix = "__db_n" - hsearch = "-DDB_DBM_HSEARCH " + hsearch = "-DDB_DBM_HSEARCH" when "gdbm" have_gdbm = true when "gdbm_compat" have_gdbm = true have_library("gdbm") or return false end - db_prefix ||= "" if (have_library(db, db_prefix+"dbm_open") || have_func(db_prefix+"dbm_open")) and hdr = self.fetch(db, ["ndbm.h"]).find {|h| have_type("DBM", h, hsearch)} or hdr = self.fetch(db, ["ndbm.h"]).find {|h| have_type("DBM", ["db.h", h], hsearch)} have_func(db_prefix+"dbm_clearerr") unless have_gdbm $defs << hsearch if hsearch + case db + when /\Adb\d?\z/ + have_func('db_version') + when /\Agdbm/ + have_var("gdbm_version", hdr) + # gdbm_version is not declared by ndbm.h until gdbm 1.8.3. + # We can't include ndbm.h and gdbm.h because they both define datum type. + # ndbm.h includes gdbm.h and gdbm_version is declared since gdbm 1.9. + have_libvar(["gdbm_version", "char *"], hdr) + when /\Aqdbm\z/ + have_var("dpversion", hdr) + end + if hsearch + $defs << hsearch + @defs = hsearch + end $defs << '-DDBM_HDR="<'+hdr+'>"' + @found << hdr true else false end end -if dblib.any? {|db| headers.db_check(db)} +if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } } have_header("cdefs.h") have_header("sys/cdefs.h") create_makefile("dbm") Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 34501) +++ ruby_1_9_3/version.h (revision 34502) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 71 +#define RUBY_PATCHLEVEL 72 #define RUBY_RELEASE_DATE "2012-02-09" #define RUBY_RELEASE_YEAR 2012 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/