rubysl-dbm 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,286 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("dbm")
4
+
5
+ if dblib = with_config("dbm-type", nil)
6
+ dblib = dblib.split(/[ ,]+/)
7
+ else
8
+ dblib = %w(libc db db2 db1 db5 db4 db3 dbm gdbm gdbm_compat qdbm)
9
+ end
10
+
11
+ headers = {
12
+ "libc" => ["ndbm.h"], # 4.4BSD libc contains Berkeley DB 1.
13
+ "db" => ["db.h"],
14
+ "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"],
15
+ "db2" => ["db2/db.h", "db2.h", "db.h"],
16
+ "db3" => ["db3/db.h", "db3.h", "db.h"],
17
+ "db4" => ["db4/db.h", "db4.h", "db.h"],
18
+ "db5" => ["db5/db.h", "db5.h", "db.h"],
19
+ "dbm" => ["ndbm.h"], # traditional ndbm (4.3BSD)
20
+ "gdbm" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], # gdbm until 1.8.0
21
+ "gdbm_compat" => ["gdbm-ndbm.h", "ndbm.h", "gdbm/ndbm.h"], # gdbm since 1.8.1
22
+ "qdbm" => ["relic.h", "qdbm/relic.h"],
23
+ }
24
+
25
+ class << headers
26
+ attr_accessor :found
27
+ attr_accessor :defs
28
+ end
29
+ headers.found = []
30
+ headers.defs = nil
31
+
32
+ def headers.db_check(db, hdr)
33
+ old_libs = $libs.dup
34
+ old_defs = $defs.dup
35
+ result = db_check2(db, hdr)
36
+ if !result
37
+ $libs = old_libs
38
+ $defs = old_defs
39
+ end
40
+ result
41
+ end
42
+
43
+ # BEGIN BACKPORTED FROM 2.0
44
+ class String
45
+ # Wraps a string in escaped quotes if it contains whitespace.
46
+ def quote
47
+ /\s/ =~ self ? "\"#{self}\"" : "#{self}"
48
+ end
49
+
50
+ # Generates a string used as cpp macro name.
51
+ def tr_cpp
52
+ strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
53
+ end
54
+
55
+ def funcall_style
56
+ /\)\z/ =~ self ? dup : "#{self}()"
57
+ end
58
+
59
+ def sans_arguments
60
+ self[/\A[^()]+/]
61
+ end
62
+ end
63
+
64
+ def rm_f(*files)
65
+ opt = (Hash === files.last ? [files.pop] : [])
66
+ FileUtils.rm_f(Dir[*files.flatten], *opt)
67
+ end
68
+
69
+ def try_func(func, libs, headers = nil, opt = "", &b)
70
+ headers = cpp_include(headers)
71
+ case func
72
+ when /^&/
73
+ decltype = proc {|x|"const volatile void *#{x}"}
74
+ when /\)$/
75
+ call = func
76
+ else
77
+ call = "#{func}()"
78
+ decltype = proc {|x| "void ((*#{x})())"}
79
+ end
80
+ if opt and !opt.empty?
81
+ [[:to_str], [:join, " "], [:to_s]].each do |meth, *args|
82
+ if opt.respond_to?(meth)
83
+ break opt = opt.send(meth, *args)
84
+ end
85
+ end
86
+ opt = "#{opt} #{libs}"
87
+ else
88
+ opt = libs
89
+ end
90
+ decltype && try_link(<<"SRC", opt, &b) or
91
+ #{headers}
92
+ /*top*/
93
+ #{MAIN_DOES_NOTHING}
94
+ extern int t(void);
95
+ int t(void) { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
96
+ SRC
97
+ call && try_link(<<"SRC", opt, &b)
98
+ #{headers}
99
+ /*top*/
100
+ #{MAIN_DOES_NOTHING}
101
+ extern int t(void);
102
+ int t(void) { #{call}; return 0; }
103
+ SRC
104
+ end
105
+
106
+ def try_var(var, headers = nil, opt = "", &b)
107
+ headers = cpp_include(headers)
108
+ try_compile(<<"SRC", opt, &b)
109
+ #{headers}
110
+ /*top*/
111
+ #{MAIN_DOES_NOTHING}
112
+ extern int t(void);
113
+ int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
114
+ SRC
115
+ end
116
+
117
+ def have_library(lib, func = nil, headers = nil, opt = "", &b)
118
+ func = "main" if !func or func.empty?
119
+ lib = with_config(lib+'lib', lib)
120
+ checking_for checking_message(func.funcall_style, LIBARG%lib, opt) do
121
+ if COMMON_LIBS.include?(lib)
122
+ true
123
+ else
124
+ libs = append_library($libs, lib)
125
+ if try_func(func, libs, headers, opt, &b)
126
+ $libs = libs
127
+ true
128
+ else
129
+ false
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ def have_func(func, headers = nil, opt = "", &b)
136
+ checking_for checking_message(func.funcall_style, headers, opt) do
137
+ if try_func(func, $libs, headers, opt, &b)
138
+ $defs << "-DHAVE_#{func.sans_arguments.tr_cpp}"
139
+ true
140
+ else
141
+ false
142
+ end
143
+ end
144
+ end
145
+
146
+ def have_var(var, headers = nil, opt = "", &b)
147
+ checking_for checking_message(var, headers, opt) do
148
+ if try_var(var, headers, opt, &b)
149
+ $defs.push(format("-DHAVE_%s", var.tr_cpp))
150
+ true
151
+ else
152
+ false
153
+ end
154
+ end
155
+ end
156
+
157
+ def try_cpp(src, opt="", *opts, &b)
158
+ try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b)
159
+ ensure
160
+ rm_f "conftest*"
161
+ end
162
+
163
+ alias :try_header :try_cpp
164
+
165
+ def have_header(header, preheaders = nil, opt = "", &b)
166
+ checking_for header do
167
+ if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b)
168
+ $defs.push(format("-DHAVE_%s", header.tr_cpp))
169
+ true
170
+ else
171
+ false
172
+ end
173
+ end
174
+ end
175
+
176
+ def convertible_int(type, headers = nil, opts = nil, &b)
177
+ type, macname = *type
178
+ checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
179
+ if UNIVERSAL_INTS.include?(type)
180
+ type
181
+ else
182
+ typedef, member, prelude = typedef_expr(type, headers, &b)
183
+ if member
184
+ prelude << "static rbcv_typedef_ rbcv_var;"
185
+ compat = UNIVERSAL_INTS.find {|t|
186
+ try_static_assert("sizeof(rbcv_var.#{member}) == sizeof(#{t})", [prelude], opts, &b)
187
+ }
188
+ else
189
+ next unless signed = try_signedness(typedef, member, [prelude])
190
+ u = "unsigned " if signed > 0
191
+ prelude << "extern rbcv_typedef_ foo();"
192
+ compat = UNIVERSAL_INTS.find {|t|
193
+ try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
194
+ }
195
+ end
196
+ if compat
197
+ macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
198
+ conv = (compat == "long long" ? "LL" : compat.upcase)
199
+ compat = "#{u}#{compat}"
200
+ typename = type.tr_cpp
201
+ $defs.push(format("-DSIZEOF_%s=SIZEOF_%s", typename, compat.tr_cpp))
202
+ $defs.push(format("-DTYPEOF_%s=%s", typename, compat.quote))
203
+ $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
204
+ conv = (u ? "U" : "") + conv
205
+ $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
206
+ $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
207
+ compat
208
+ end
209
+ end
210
+ end
211
+ end
212
+ # END BACKPORTED FROM 2.0
213
+
214
+ def have_libvar(var, headers = nil, opt = "", &b)
215
+ checking_for checking_message([*var].compact.join(' '), headers, opt) do
216
+ try_libvar(var, headers, opt, &b)
217
+ end
218
+ end
219
+
220
+ def try_libvar(var, headers = nil, opt = "", &b)
221
+ var, type = *var
222
+ if try_link(<<"SRC", opt, &b)
223
+ #{cpp_include(headers)}
224
+ /*top*/
225
+ int main(int argc, char *argv[]) {
226
+ typedef #{type || 'int'} conftest_type;
227
+ extern conftest_type #{var};
228
+ conftest_type *conftest_var = &#{var};
229
+ return 0;
230
+ }
231
+ SRC
232
+ $defs.push(format("-DHAVE_LIBVAR_%s", var.tr_cpp))
233
+ true
234
+ else
235
+ false
236
+ end
237
+ end
238
+
239
+
240
+ def headers.db_check2(db, hdr)
241
+ hsearch = nil
242
+
243
+ case db
244
+ when /^db[2-5]?$/
245
+ hsearch = "-DDB_DBM_HSEARCH"
246
+ when "gdbm_compat"
247
+ have_library("gdbm") or return false
248
+ end
249
+
250
+ if have_type("DBM", hdr, hsearch) and
251
+ (db == 'libc' ? have_func('dbm_open("", 0, 0)', hdr, hsearch) :
252
+ have_library(db, 'dbm_open("", 0, 0)', hdr, hsearch)) and
253
+ have_func('dbm_clearerr((DBM *)0)', hdr, hsearch) and
254
+ (/\Adb\d?\z/ =~ db || db == 'libc' || !have_macro('_DB_H_', hdr, hsearch)) # _DB_H_ should not be defined except Berkeley DB.
255
+ case db
256
+ when /\Adb\d?\z/
257
+ have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
258
+ when /\Agdbm/
259
+ have_var("gdbm_version", hdr, hsearch)
260
+ # gdbm_version is not declared by ndbm.h until gdbm 1.8.3.
261
+ # We can't include ndbm.h and gdbm.h because they both define datum type.
262
+ # ndbm.h includes gdbm.h and gdbm_version is declared since gdbm 1.9.
263
+ have_libvar(["gdbm_version", "char *"], hdr, hsearch)
264
+ when /\Aqdbm\z/
265
+ have_var("dpversion", hdr, hsearch)
266
+ end
267
+ if hsearch
268
+ $defs << hsearch
269
+ @defs = hsearch
270
+ end
271
+ $defs << '-DDBM_HDR="<'+hdr+'>"'
272
+ @found << hdr
273
+ true
274
+ else
275
+ false
276
+ end
277
+ end
278
+
279
+ if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } }
280
+ have_header("cdefs.h")
281
+ 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)
285
+ create_makefile("dbm/dbm")
286
+ end
@@ -0,0 +1 @@
1
+ require "rubysl/dbm"
@@ -0,0 +1,2 @@
1
+ require "dbm/dbm"
2
+ require "rubysl/dbm/version"
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module DBM
3
+ VERSION = "2.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/dbm/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-dbm"
6
+ spec.version = RubySL::DBM::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library dbm.}
10
+ spec.summary = %q{Ruby standard library dbm.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-dbm"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.extensions = ["ext/rubysl/dbm/extconf.rb"]
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "mspec", "~> 1.5"
23
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubysl-dbm
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Shirai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ description: Ruby standard library dbm.
56
+ email:
57
+ - brixen@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/rubysl/dbm/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - ext/rubysl/dbm/dbm.c
70
+ - ext/rubysl/dbm/extconf.rb
71
+ - lib/dbm.rb
72
+ - lib/rubysl/dbm.rb
73
+ - lib/rubysl/dbm/version.rb
74
+ - rubysl-dbm.gemspec
75
+ homepage: https://github.com/rubysl/rubysl-dbm
76
+ licenses:
77
+ - BSD
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.7
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby standard library dbm.
99
+ test_files: []
100
+ has_rdoc: