[前][次][番号順一覧][スレッド一覧]

ruby-changes:22630

From: akr <ko1@a...>
Date: Sat, 18 Feb 2012 18:47:18 +0900 (JST)
Subject: [ruby-changes:22630] akr:r34679 (trunk): * ext/dbm/extconf.rb (dblib): prefer recent GDBM over older GDBM.

akr	2012-02-18 18:47:07 +0900 (Sat, 18 Feb 2012)

  New Revision: 34679

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34679

  Log:
    * ext/dbm/extconf.rb (dblib): prefer recent GDBM over older GDBM.
      (have_declared_libvar): new function to check a declared variable
      exists in a library.
      (have_undeclared_libvar): renamed from renamed from have_libvar.
      (headers.db_check2): check that GDBM version variable if GDBM header
      is choosen.
    
    * ext/dbm/dbm.c (Init_dbm): use HAVE_DECLARED_LIBVAR_GDBM_VERSION and
      HAVE_UNDECLARED_LIBVAR_GDBM_VERSION macro.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dbm/dbm.c
    trunk/ext/dbm/extconf.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34678)
+++ ChangeLog	(revision 34679)
@@ -1,3 +1,15 @@
+Sat Feb 18 18:43:13 2012  Tanaka Akira  <akr@f...>
+
+	* ext/dbm/extconf.rb (dblib): prefer recent GDBM over older GDBM.
+	  (have_declared_libvar): new function to check a declared variable
+	  exists in a library.
+	  (have_undeclared_libvar): renamed from renamed from have_libvar.
+	  (headers.db_check2): check that GDBM version variable if GDBM header
+	  is choosen.
+
+	* ext/dbm/dbm.c (Init_dbm): use HAVE_DECLARED_LIBVAR_GDBM_VERSION and
+	  HAVE_UNDECLARED_LIBVAR_GDBM_VERSION macro.
+
 Sat Feb 18 13:53:01 2012  Tanaka Akira  <akr@f...>
 
 	* test/dbm/test_dbm.rb (test_dbmfile_suffix): DBM::VERSION should
Index: ext/dbm/dbm.c
===================================================================
--- ext/dbm/dbm.c	(revision 34678)
+++ ext/dbm/dbm.c	(revision 34679)
@@ -1082,10 +1082,10 @@
 #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(NULL, NULL, NULL)));
-#elif defined(HAVE_GDBM_VERSION)
+#elif defined(HAVE_DECLARED_LIBVAR_GDBM_VERSION)
     /* since gdbm 1.9 */
     rb_define_const(rb_cDBM, "VERSION",  rb_str_new2(gdbm_version));
-#elif defined(HAVE_LIBVAR_GDBM_VERSION)
+#elif defined(HAVE_UNDECLARED_LIBVAR_GDBM_VERSION)
     /* ndbm.h doesn't declare gdbm_version until gdbm 1.8.3.
      * See extconf.rb for more information. */
     {
Index: ext/dbm/extconf.rb
===================================================================
--- ext/dbm/extconf.rb	(revision 34678)
+++ ext/dbm/extconf.rb	(revision 34679)
@@ -5,7 +5,7 @@
 if dblib = with_config("dbm-type", nil)
   dblib = dblib.split(/[ ,]+/)
 else
-  dblib = %w(libc db db2 db1 db5 db4 db3 gdbm gdbm_compat qdbm)
+  dblib = %w(libc db db2 db1 db5 db4 db3 gdbm_compat gdbm qdbm)
 end
 
 headers = {
@@ -16,8 +16,8 @@
   "db3" => ["db3/db.h", "db3.h", "db.h"],
   "db4" => ["db4/db.h", "db4.h", "db.h"],
   "db5" => ["db5/db.h", "db5.h", "db.h"],
+  "gdbm_compat" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], # gdbm since 1.8.1
   "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"],
 }
 
@@ -39,13 +39,35 @@
   result
 end
 
-def have_libvar(var, headers = nil, opt = "", &b)
+def have_declared_libvar(var, headers = nil, opt = "", &b)
   checking_for checking_message([*var].compact.join(' '), headers, opt) do
-    try_libvar(var, headers, opt, &b)
+    try_declared_libvar(var, headers, opt, &b)
   end
 end
 
-def try_libvar(var, headers = nil, opt = "", &b)
+def try_declared_libvar(var, headers = nil, opt = "", &b)
+  if try_link(<<"SRC", opt, &b)
+#{cpp_include(headers)}
+/*top*/
+int main(int argc, char *argv[]) {
+  void *conftest_var = &#{var};
+  return 0;
+}
+SRC
+    $defs.push(format("-DHAVE_DECLARED_LIBVAR_%s", var.tr_cpp))
+    true
+  else
+    false
+  end
+end
+
+def have_undeclared_libvar(var, headers = nil, opt = "", &b)
+  checking_for checking_message([*var].compact.join(' '), headers, opt) do
+    try_undeclared_libvar(var, headers, opt, &b)
+  end
+end
+
+def try_undeclared_libvar(var, headers = nil, opt = "", &b)
   var, type = *var
   if try_link(<<"SRC", opt, &b)
 #{cpp_include(headers)}
@@ -57,7 +79,7 @@
   return 0;
 }
 SRC
-    $defs.push(format("-DHAVE_LIBVAR_%s", var.tr_cpp))
+    $defs.push(format("-DHAVE_UNDECLARED_LIBVAR_%s", var.tr_cpp))
     true
   else
     false
@@ -66,6 +88,9 @@
 
 
 def headers.db_check2(db, hdr)
+  $defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'})
+  $defs.push(%{-DRUBYDBM_DBM_TYPE='"#{db}"'})
+
   hsearch = nil
 
   case db
@@ -103,47 +128,58 @@
     return false
   end
 
+  # Berkeley DB's ndbm.h (since 1.85 at least) includes db.h and
+  # it defines _DB_H_.
+  have_db_header_macro = have_macro('_DB_H_', hdr, hsearch)
+
+  # Recent GDBM's ndbm.h, since 1.9, includes gdbm.h and it defines _GDBM_H_.
+  # ndbm compatibility layer of GDBM is provided by libgdbm (until 1.8.0)
+  # and libgdbm_compat (since 1.8.1).
+  have_gdbm_header_macro = have_macro('_GDBM_H_', hdr, hsearch)
+
+  # 4.3BSD's ndbm.h defines _DBM_IOERR.
+  # The original ndbm is provided by libc in 4.3BSD.
+  have_ndbm_header_macro = have_macro('_DBM_IOERR', hdr, hsearch)
+
   # ndbm.h is provided by the original (4.3BSD) dbm,
   # Berkeley DB 1 in libc of 4.4BSD and
   # ndbm compatibility layer of gdbm.
   # So, try to check header/library mismatch.
   #
-  # Assumption: There are no insane environment which libc provides ndbm
-  # functions but ndbm.h is not for that.
-  # 
   if hdr == 'ndbm.h' && db != 'libc'
-    # Berkeley DB's ndbm.h (since 1.85 at least) includes db.h and
-    # it defines _DB_H_.
-    if /\Adb\d?\z/ !~ db && have_macro('_DB_H_', hdr, hsearch)
+    if /\Adb\d?\z/ !~ db && have_db_header_macro
       return false
     end
 
-    # Recent GDBM's ndbm.h, since 1.9, includes gdbm.h and it defines _GDBM_H_.
-    # ndbm compatibility layer of GDBM is provided by libgdbm (until 1.8.0)
-    # and libgdbm_compat (since 1.8.1).
-    if /\Agdbm/ !~ db && have_macro('_GDBM_H_', hdr, hsearch)
+    if /\Agdbm/ !~ db && have_gdbm_header_macro
       return false
     end
     
-    # 4.3BSD's ndbm.h defines _DBM_IOERR.
-    # The original ndbm is provided by libc in 4.3BSD.
-    if have_macro('_DBM_IOERR', hdr, hsearch)
+    if have_ndbm_header_macro
       return false
     end
   end
 
-  case db
-  when /\Adb\d?\z/
-    have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
-  when /\Agdbm/
-    have_var("gdbm_version", hdr, hsearch)
-    # 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, hsearch)
-  when /\Aqdbm\z/
-    have_var("dpversion", hdr, hsearch)
+  # Berkeley DB
+  have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
+
+  # GDBM
+  have_gdbm_variable = have_declared_libvar("gdbm_version", hdr, hsearch)
+  # gdbm_version is available since very old version (gdbm 1.5 at least).
+  # However it is not declared by ndbm.h until gdbm 1.8.3.
+  # We can't include both 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_gdbm_variable |= have_undeclared_libvar(["gdbm_version", "char *"], hdr, hsearch)
+
+  # QDBM
+  have_var("dpversion", hdr, hsearch)
+
+  # detect mismatch between GDBM header and other library.
+  # If GDBM header is included, GDBM library should be linked.
+  if have_gdbm_header_macro && !have_gdbm_variable
+    return false
   end
+
   if hsearch
     $defs << hsearch
     @defs = hsearch

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]