Skip to content

Commit de889a3

Browse files
committed
* ext/dbm/extconf.rb: merge trunk's ext/dbm/extconf.rb and
related functions of lib/mkmf.rb. [Backport #6021] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 4ec9395 commit de889a3

File tree

3 files changed

+190
-17
lines changed

3 files changed

+190
-17
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Thu Feb 16 17:54:14 2012 NARUSE, Yui <naruse@ruby-lang.org>
2+
3+
* ext/dbm/extconf.rb: merge trunk's ext/dbm/extconf.rb and
4+
related functions of lib/mkmf.rb. [Backport #6021]
5+
16
Thu Feb 16 09:25:52 2012 NARUSE, Yui <naruse@ruby-lang.org>
27

38
* configure.in (enable_pthread): use -pthread on OpenBSD without

ext/dbm/extconf.rb

Lines changed: 184 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
if dblib = with_config("dbm-type", nil)
66
dblib = dblib.split(/[ ,]+/)
77
else
8-
dblib = %w(libc db db2 db1 db5 db4 db3 dbm gdbm gdbm_compat qdbm)
8+
#dblib = %w(libc db db2 db1 db5 db4 db3 dbm gdbm gdbm_compat qdbm)
9+
dblib = %w(gdbm gdbm_compat qdbm)
910
end
1011

1112
headers = {
@@ -40,6 +41,177 @@ def headers.db_check(db, hdr)
4041
result
4142
end
4243

44+
# BEGIN BACKPORTED FROM 2.0
45+
class String
46+
# Wraps a string in escaped quotes if it contains whitespace.
47+
def quote
48+
/\s/ =~ self ? "\"#{self}\"" : "#{self}"
49+
end
50+
51+
# Generates a string used as cpp macro name.
52+
def tr_cpp
53+
strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
54+
end
55+
56+
def funcall_style
57+
/\)\z/ =~ self ? dup : "#{self}()"
58+
end
59+
60+
def sans_arguments
61+
self[/\A[^()]+/]
62+
end
63+
end
64+
65+
def rm_f(*files)
66+
opt = (Hash === files.last ? [files.pop] : [])
67+
FileUtils.rm_f(Dir[*files.flatten], *opt)
68+
end
69+
70+
def try_func(func, libs, headers = nil, opt = "", &b)
71+
headers = cpp_include(headers)
72+
case func
73+
when /^&/
74+
decltype = proc {|x|"const volatile void *#{x}"}
75+
when /\)$/
76+
call = func
77+
else
78+
call = "#{func}()"
79+
decltype = proc {|x| "void ((*#{x})())"}
80+
end
81+
if opt and !opt.empty?
82+
[[:to_str], [:join, " "], [:to_s]].each do |meth, *args|
83+
if opt.respond_to?(meth)
84+
break opt = opt.send(meth, *args)
85+
end
86+
end
87+
opt = "#{opt} #{libs}"
88+
else
89+
opt = libs
90+
end
91+
decltype && try_link(<<"SRC", opt, &b) or
92+
#{headers}
93+
/*top*/
94+
#{MAIN_DOES_NOTHING}
95+
extern int t(void);
96+
int t(void) { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
97+
SRC
98+
call && try_link(<<"SRC", opt, &b)
99+
#{headers}
100+
/*top*/
101+
#{MAIN_DOES_NOTHING}
102+
extern int t(void);
103+
int t(void) { #{call}; return 0; }
104+
SRC
105+
end
106+
107+
def try_var(var, headers = nil, opt = "", &b)
108+
headers = cpp_include(headers)
109+
try_compile(<<"SRC", opt, &b)
110+
#{headers}
111+
/*top*/
112+
#{MAIN_DOES_NOTHING}
113+
extern int t(void);
114+
int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
115+
SRC
116+
end
117+
118+
def have_library(lib, func = nil, headers = nil, opt = "", &b)
119+
func = "main" if !func or func.empty?
120+
lib = with_config(lib+'lib', lib)
121+
checking_for checking_message(func.funcall_style, LIBARG%lib, opt) do
122+
if COMMON_LIBS.include?(lib)
123+
true
124+
else
125+
libs = append_library($libs, lib)
126+
if try_func(func, libs, headers, opt, &b)
127+
$libs = libs
128+
true
129+
else
130+
false
131+
end
132+
end
133+
end
134+
end
135+
136+
def have_func(func, headers = nil, opt = "", &b)
137+
checking_for checking_message(func.funcall_style, headers, opt) do
138+
if try_func(func, $libs, headers, opt, &b)
139+
$defs << "-DHAVE_#{func.sans_arguments.tr_cpp}"
140+
true
141+
else
142+
false
143+
end
144+
end
145+
end
146+
147+
def have_var(var, headers = nil, opt = "", &b)
148+
checking_for checking_message(var, headers, opt) do
149+
if try_var(var, headers, opt, &b)
150+
$defs.push(format("-DHAVE_%s", var.tr_cpp))
151+
true
152+
else
153+
false
154+
end
155+
end
156+
end
157+
158+
def try_cpp(src, opt="", *opts, &b)
159+
try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b)
160+
ensure
161+
rm_f "conftest*"
162+
end
163+
164+
alias :try_header :try_cpp
165+
166+
def have_header(header, preheaders = nil, opt = "", &b)
167+
checking_for header do
168+
if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b)
169+
$defs.push(format("-DHAVE_%s", header.tr_cpp))
170+
true
171+
else
172+
false
173+
end
174+
end
175+
end
176+
177+
def convertible_int(type, headers = nil, opts = nil, &b)
178+
type, macname = *type
179+
checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
180+
if UNIVERSAL_INTS.include?(type)
181+
type
182+
else
183+
typedef, member, prelude = typedef_expr(type, headers, &b)
184+
if member
185+
prelude << "static rbcv_typedef_ rbcv_var;"
186+
compat = UNIVERSAL_INTS.find {|t|
187+
try_static_assert("sizeof(rbcv_var.#{member}) == sizeof(#{t})", [prelude], opts, &b)
188+
}
189+
else
190+
next unless signed = try_signedness(typedef, member, [prelude])
191+
u = "unsigned " if signed > 0
192+
prelude << "extern rbcv_typedef_ foo();"
193+
compat = UNIVERSAL_INTS.find {|t|
194+
try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
195+
}
196+
end
197+
if compat
198+
macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
199+
conv = (compat == "long long" ? "LL" : compat.upcase)
200+
compat = "#{u}#{compat}"
201+
typename = type.tr_cpp
202+
$defs.push(format("-DSIZEOF_%s=SIZEOF_%s", typename, compat.tr_cpp))
203+
$defs.push(format("-DTYPEOF_%s=%s", typename, compat.quote))
204+
$defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
205+
conv = (u ? "U" : "") + conv
206+
$defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
207+
$defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
208+
compat
209+
end
210+
end
211+
end
212+
end
213+
# END BACKPORTED FROM 2.0
214+
43215
def have_libvar(var, headers = nil, opt = "", &b)
44216
checking_for checking_message([*var].compact.join(' '), headers, opt) do
45217
try_libvar(var, headers, opt, &b)
@@ -67,37 +239,30 @@ def try_libvar(var, headers = nil, opt = "", &b)
67239

68240

69241
def headers.db_check2(db, hdr)
70-
db_prefix = ''
71-
have_gdbm = false
72242
hsearch = nil
73243

74244
case db
75245
when /^db[2-5]?$/
76-
db_prefix = "__db_n"
77246
hsearch = "-DDB_DBM_HSEARCH"
78-
when "gdbm"
79-
have_gdbm = true
80247
when "gdbm_compat"
81-
have_gdbm = true
82248
have_library("gdbm") or return false
83249
end
84250

85-
if (have_library(db, db_prefix+"dbm_open") || have_func(db_prefix+"dbm_open")) and
86-
hdr = self.fetch(db, ["ndbm.h"]).find {|h| have_type("DBM", h, hsearch)} or
87-
hdr = self.fetch(db, ["ndbm.h"]).find {|h| have_type("DBM", ["db.h", h], hsearch)}
88-
have_func(db_prefix+"dbm_clearerr") unless have_gdbm
89-
$defs << hsearch if hsearch
251+
if have_type("DBM", hdr, hsearch) and
252+
(db == 'libc' ? have_func('dbm_open("", 0, 0)', hdr, hsearch) :
253+
have_library(db, 'dbm_open("", 0, 0)', hdr, hsearch)) and
254+
have_func('dbm_clearerr((DBM *)0)', hdr, hsearch)
90255
case db
91256
when /\Adb\d?\z/
92-
have_func('db_version')
257+
have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
93258
when /\Agdbm/
94-
have_var("gdbm_version", hdr)
259+
have_var("gdbm_version", hdr, hsearch)
95260
# gdbm_version is not declared by ndbm.h until gdbm 1.8.3.
96261
# We can't include ndbm.h and gdbm.h because they both define datum type.
97262
# ndbm.h includes gdbm.h and gdbm_version is declared since gdbm 1.9.
98-
have_libvar(["gdbm_version", "char *"], hdr)
263+
have_libvar(["gdbm_version", "char *"], hdr, hsearch)
99264
when /\Aqdbm\z/
100-
have_var("dpversion", hdr)
265+
have_var("dpversion", hdr, hsearch)
101266
end
102267
if hsearch
103268
$defs << hsearch
@@ -114,5 +279,8 @@ def headers.db_check2(db, hdr)
114279
if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } }
115280
have_header("cdefs.h")
116281
have_header("sys/cdefs.h")
282+
have_func("dbm_pagfno((DBM *)0)", headers.found, headers.defs)
283+
have_func("dbm_dirfno((DBM *)0)", headers.found, headers.defs)
284+
convertible_int("datum.dsize", headers.found, headers.defs)
117285
create_makefile("dbm")
118286
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define RUBY_VERSION "1.9.3"
2-
#define RUBY_PATCHLEVEL 124
2+
#define RUBY_PATCHLEVEL 125
33

44
#define RUBY_RELEASE_DATE "2012-02-16"
55
#define RUBY_RELEASE_YEAR 2012

0 commit comments

Comments
 (0)