From 0187905af2e16438606ead7618328bf062cc3339 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 18 Feb 2012 16:06:52 +0000 Subject: * ext/dbm/extconf.rb: detect GDBM's ndbm.h by testing dbm_clearerr is an empty macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/dbm/dbm.c | 2 +- ext/dbm/extconf.rb | 30 ++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c97609ca6a..e8441f2162 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Feb 19 01:05:41 2012 Tanaka Akira + + * ext/dbm/extconf.rb: detect GDBM's ndbm.h by testing dbm_clearerr is + an empty macro. + Sun Feb 19 00:25:55 2012 Tanaka Akira * ext/dbm/extconf.rb: don't choose 'dbm' if _GDB_H_ is defined which diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 1091020ec3..aba395c9a0 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -1096,7 +1096,7 @@ Init_dbm(void) 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)")); -#elif defined(_GDBM_H_) +#elif defined(_GDBM_H_) || defined(HAVE_EMPTY_MACRO_DBM_CLEARERR) rb_define_const(rb_cDBM, "VERSION", rb_str_new2("GDBM (unknown)")); #elif defined(_DBM_IOERR) rb_define_const(rb_cDBM, "VERSION", rb_str_new2("NDBM (4.3BSD)")); diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb index 15a4702dd8..24b11b9bc6 100644 --- a/ext/dbm/extconf.rb +++ b/ext/dbm/extconf.rb @@ -86,6 +86,26 @@ SRC end end +def have_empty_macro_dbm_clearerr(headers = nil, opt = "", &b) + checking_for checking_message('empty macro of dbm_clearerr(foobarbaz)', + headers, opt) do + try_toplevel('dbm_clearerr(foobarbaz)', headers, opt, &b) + end +end + +def try_toplevel(src, headers = nil, opt = "", &b) + if try_compile(<<"SRC", opt, &b) +#{cpp_include(headers)} +/*top*/ +#{src} +SRC + $defs.push("-DHAVE_EMPTY_MACRO_DBM_CLEARERR") + true + else + false + end +end + def headers.db_check2(db, hdr) $defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'}) @@ -132,10 +152,14 @@ def headers.db_check2(db, hdr) # it defines _DB_H_. have_db_header_macro = have_macro('_DB_H_', hdr, hsearch) + # Old GDBM's ndbm.h, until 1.8.3, defines dbm_clearerr as a macro which + # expands to no tokens. + have_gdbm_header_macro1 = have_empty_macro_dbm_clearerr(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) + have_gdbm_header_macro2 = have_macro('_GDBM_H_', hdr, hsearch) # 4.3BSD's ndbm.h defines _DBM_IOERR. # The original ndbm is provided by libc in 4.3BSD. @@ -144,10 +168,12 @@ def headers.db_check2(db, hdr) # GDBM provides NDBM functions in libgdbm_compat since GDBM 1.8.1. # GDBM's ndbm.h defines _GDBM_H_ since GDBM 1.9. # So, reject 'gdbm'. 'gdbm_compat' is required. - if have_gdbm_header_macro && db == 'gdbm' + if have_gdbm_header_macro2 && db == 'gdbm' return false end + have_gdbm_header_macro = have_gdbm_header_macro1 | have_gdbm_header_macro2 + # ndbm.h is provided by the original (4.3BSD) dbm, # Berkeley DB 1 in libc of 4.4BSD and # ndbm compatibility layer of gdbm. -- cgit v1.2.3