summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-09 02:12:10 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-09 02:12:10 +0000
commit6b3ba6912a2a7aec19b58327f460ec46880724a9 (patch)
treed709976ea26ae9adc4f63b3862da23eb683c0780 /ext
parente0f8351d5528cd01ab71855eae87ef067de55626 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dbm/dbm.c23
-rw-r--r--ext/dbm/extconf.rb79
2 files changed, 90 insertions, 12 deletions
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 6d5396066d..3c65d1f5bc 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -901,10 +901,13 @@ fdbm_reject(VALUE obj)
* 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 @@ Init_dbm(void)
*/
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
diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb
index 91d393b211..081aaa24b5 100644
--- a/ext/dbm/extconf.rb
+++ b/ext/dbm/extconf.rb
@@ -5,52 +5,113 @@ dir_config("dbm")
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")