dbm 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/ext/dbm/dbm.c +1160 -0
  3. data/ext/dbm/extconf.rb +290 -0
  4. metadata +75 -0
@@ -0,0 +1,290 @@
1
+ # frozen_string_literal: true
2
+ # configure option:
3
+ # --with-dbm-type=COMMA-SEPARATED-NDBM-TYPES
4
+ #
5
+ # ndbm type:
6
+ # libc ndbm compatible library in libc.
7
+ # db Berkeley DB (libdb)
8
+ # db2 Berkeley DB (libdb2)
9
+ # db1 Berkeley DB (libdb1)
10
+ # db5 Berkeley DB (libdb5)
11
+ # db4 Berkeley DB (libdb4)
12
+ # db3 Berkeley DB (libdb3)
13
+ # gdbm_compat GDBM since 1.8.1 (libgdbm_compat)
14
+ # gdbm GDBM until 1.8.0 (libgdbm)
15
+ # qdbm QDBM (libqdbm)
16
+ # ndbm Some legacy OS may have libndbm.
17
+
18
+ # :stopdoc:
19
+ require 'mkmf'
20
+
21
+ dir_config("dbm")
22
+
23
+ if dblib = with_config("dbm-type", nil)
24
+ dblib = dblib.split(/[ ,]+/)
25
+ else
26
+ dblib = %w(libc db db2 db1 db5 db4 db3 gdbm_compat gdbm qdbm)
27
+ end
28
+
29
+ headers = {
30
+ "libc" => ["ndbm.h"], # 4.3BSD original ndbm, Berkeley DB 1 in 4.4BSD libc.
31
+ "db" => ["db.h"],
32
+ "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"],
33
+ "db2" => ["db2/db.h", "db2.h", "db.h"],
34
+ "db3" => ["db3/db.h", "db3.h", "db.h"],
35
+ "db4" => ["db4/db.h", "db4.h", "db.h"],
36
+ "db5" => ["db5/db.h", "db5.h", "db.h"],
37
+ "gdbm_compat" => ["gdbm-ndbm.h", "gdbm/ndbm.h", "ndbm.h"], # GDBM since 1.8.1
38
+ "gdbm" => ["gdbm-ndbm.h", "gdbm/ndbm.h", "ndbm.h"], # GDBM until 1.8.0
39
+ "qdbm" => ["qdbm/relic.h", "relic.h"],
40
+ }
41
+
42
+ class << headers
43
+ attr_accessor :found
44
+ attr_accessor :defs
45
+ end
46
+ headers.found = []
47
+ headers.defs = nil
48
+
49
+ def headers.db_check(db, hdr)
50
+ old_libs = $libs.dup
51
+ old_defs = $defs.dup
52
+ result = db_check2(db, hdr)
53
+ if !result
54
+ $libs = old_libs
55
+ $defs = old_defs
56
+ end
57
+ result
58
+ end
59
+
60
+ def have_declared_libvar(var, headers = nil, opt = "", &b)
61
+ checking_for checking_message([*var].compact.join(' '), headers, opt) do
62
+ try_declared_libvar(var, headers, opt, &b)
63
+ end
64
+ end
65
+
66
+ def try_declared_libvar(var, headers = nil, opt = "", &b)
67
+ if try_link(<<"SRC", opt, &b)
68
+ #{cpp_include(headers)}
69
+ /*top*/
70
+ int main(int argc, char *argv[]) {
71
+ void *conftest_var = &#{var};
72
+ return 0;
73
+ }
74
+ SRC
75
+ $defs.push(format("-DHAVE_DECLARED_LIBVAR_%s", var.tr_cpp))
76
+ true
77
+ else
78
+ false
79
+ end
80
+ end
81
+
82
+ def have_undeclared_libvar(var, headers = nil, opt = "", &b)
83
+ checking_for checking_message([*var].compact.join(' '), headers, opt) do
84
+ try_undeclared_libvar(var, headers, opt, &b)
85
+ end
86
+ end
87
+
88
+ def try_undeclared_libvar(var, headers = nil, opt = "", &b)
89
+ var, type = *var
90
+ if try_link(<<"SRC", opt, &b)
91
+ #{cpp_include(headers)}
92
+ /*top*/
93
+ int main(int argc, char *argv[]) {
94
+ typedef #{type || 'int'} conftest_type;
95
+ extern conftest_type #{var};
96
+ conftest_type *conftest_var = &#{var};
97
+ return 0;
98
+ }
99
+ SRC
100
+ $defs.push(format("-DHAVE_UNDECLARED_LIBVAR_%s", var.tr_cpp))
101
+ true
102
+ else
103
+ false
104
+ end
105
+ end
106
+
107
+ def have_empty_macro_dbm_clearerr(headers = nil, opt = "", &b)
108
+ checking_for checking_message('empty macro of dbm_clearerr(foobarbaz)',
109
+ headers, opt) do
110
+ try_toplevel('dbm_clearerr(foobarbaz)', headers, opt, &b)
111
+ end
112
+ end
113
+
114
+ def try_toplevel(src, headers = nil, opt = "", &b)
115
+ if try_compile(<<"SRC", opt, &b)
116
+ #{cpp_include(headers)}
117
+ /*top*/
118
+ #{src}
119
+ SRC
120
+ true
121
+ else
122
+ false
123
+ end
124
+ end
125
+
126
+
127
+ def headers.db_check2(db, hdr)
128
+ $defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'})
129
+ $defs.push(%{-DRUBYDBM_DBM_TYPE='"#{db}"'})
130
+
131
+ hsearch = nil
132
+
133
+ case db
134
+ when /^db[2-5]?$/
135
+ hsearch = "-DDB_DBM_HSEARCH"
136
+ when "gdbm_compat"
137
+ have_library("gdbm") or return false
138
+ end
139
+
140
+ if !have_type("DBM", hdr, hsearch)
141
+ return false
142
+ end
143
+
144
+ # 'libc' means ndbm is provided by libc.
145
+ # 4.3BSD original ndbm is contained in libc.
146
+ # 4.4BSD (and its derivatives such as NetBSD) contains Berkeley DB 1 in libc.
147
+ if !(db == 'libc' ? have_func('dbm_open("", 0, 0)', hdr, hsearch) :
148
+ have_library(db, 'dbm_open("", 0, 0)', hdr, hsearch))
149
+ return false
150
+ end
151
+
152
+ # Skip a mismatch of Berkeley DB's ndbm.h and old GDBM library.
153
+ #
154
+ # dbm_clearerr() should be available for any ndbm implementation.
155
+ # It is available since the original (4.3BSD) ndbm and standardized by POSIX.
156
+ #
157
+ # However "can't resolve symbol 'dbm_clearerr'" problem may be caused by
158
+ # header/library mismatch: Berkeley DB ndbm.h and GDBM library until 1.8.3.
159
+ # GDBM (until 1.8.3) provides dbm_clearerr() as a empty macro in the header
160
+ # and the library don't provide dbm_clearerr().
161
+ # Berkeley DB provides dbm_clearerr() as a usual function.
162
+ # So Berkeley DB header with GDBM library causes the problem.
163
+ #
164
+ if !have_func('dbm_clearerr((DBM *)0)', hdr, hsearch)
165
+ return false
166
+ end
167
+
168
+ # Berkeley DB's ndbm.h (since 1.85 at least) defines DBM_SUFFIX.
169
+ # Note that _DB_H_ is not defined on Mac OS X because
170
+ # it uses Berkeley DB 1 but ndbm.h doesn't include db.h.
171
+ have_db_header = have_macro('DBM_SUFFIX', hdr, hsearch)
172
+
173
+ # Old GDBM's ndbm.h, until 1.8.3, defines dbm_clearerr as a macro which
174
+ # expands to no tokens.
175
+ have_gdbm_header1 = have_empty_macro_dbm_clearerr(hdr, hsearch)
176
+
177
+ # Recent GDBM's ndbm.h, since 1.9, includes gdbm.h and it defines _GDBM_H_.
178
+ # ndbm compatibility layer of GDBM is provided by libgdbm (until 1.8.0)
179
+ # and libgdbm_compat (since 1.8.1).
180
+ have_gdbm_header2 = have_macro('_GDBM_H_', hdr, hsearch)
181
+
182
+ # 4.3BSD's ndbm.h defines _DBM_IOERR.
183
+ # The original ndbm is provided by libc in 4.3BSD.
184
+ have_ndbm_header = have_macro('_DBM_IOERR', hdr, hsearch)
185
+
186
+ # GDBM provides ndbm functions in libgdbm_compat since GDBM 1.8.1.
187
+ # GDBM's ndbm.h defines _GDBM_H_ since GDBM 1.9.
188
+ # If _GDBM_H_ is defined, 'gdbm_compat' is required and reject 'gdbm'.
189
+ if have_gdbm_header2 && db == 'gdbm'
190
+ return false
191
+ end
192
+
193
+ if have_db_header
194
+ $defs.push('-DRUBYDBM_DB_HEADER')
195
+ end
196
+
197
+ have_gdbm_header = have_gdbm_header1 | have_gdbm_header2
198
+ if have_gdbm_header
199
+ $defs.push('-DRUBYDBM_GDBM_HEADER')
200
+ end
201
+
202
+ # ndbm.h is provided by the original (4.3BSD) ndbm,
203
+ # Berkeley DB 1 in libc of 4.4BSD and
204
+ # ndbm compatibility layer of GDBM.
205
+ # So, try to check header/library mismatch.
206
+ #
207
+ # Several (possibly historical) distributions provides libndbm.
208
+ # It may be Berkeley DB, GDBM or 4.3BSD ndbm.
209
+ # So mismatch check is not performed for that.
210
+ # Note that libndbm is searched only when --with-dbm-type=ndbm is
211
+ # given for configure.
212
+ #
213
+ if hdr == 'ndbm.h' && db != 'libc' && db != 'ndbm'
214
+ if /\Adb\d?\z/ !~ db && have_db_header
215
+ return false
216
+ end
217
+
218
+ if /\Agdbm/ !~ db && have_gdbm_header
219
+ return false
220
+ end
221
+
222
+ if have_ndbm_header
223
+ return false
224
+ end
225
+ end
226
+
227
+ # Berkeley DB
228
+ have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
229
+
230
+ # GDBM
231
+ have_gdbm_version = have_declared_libvar("gdbm_version", hdr, hsearch)
232
+ # gdbm_version is available since very old version (GDBM 1.5 at least).
233
+ # However it is not declared by ndbm.h until GDBM 1.8.3.
234
+ # We can't include both ndbm.h and gdbm.h because they both define datum type.
235
+ # ndbm.h includes gdbm.h and gdbm_version is declared since GDBM 1.9.
236
+ have_gdbm_version |= have_undeclared_libvar(["gdbm_version", "char *"], hdr, hsearch)
237
+
238
+ # QDBM
239
+ have_var("dpversion", hdr, hsearch)
240
+
241
+ # detect mismatch between GDBM header and other library.
242
+ # If GDBM header is included, GDBM library should be linked.
243
+ if have_gdbm_header && !have_gdbm_version
244
+ return false
245
+ end
246
+
247
+ # DBC type is required to disable error messages by Berkeley DB 2 or later.
248
+ if have_db_header
249
+ have_type("DBC", hdr, hsearch)
250
+ end
251
+
252
+ if hsearch
253
+ $defs << hsearch
254
+ @defs = hsearch
255
+ end
256
+ $defs << '-DDBM_HDR="<'+hdr+'>"'
257
+ @found << hdr
258
+
259
+ puts "header: #{hdr}"
260
+ puts "library: #{db}"
261
+
262
+ true
263
+ end
264
+
265
+ if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } }
266
+ have_header("cdefs.h")
267
+ have_header("sys/cdefs.h")
268
+ have_func("dbm_pagfno((DBM *)0)", headers.found, headers.defs)
269
+ have_func("dbm_dirfno((DBM *)0)", headers.found, headers.defs)
270
+ convertible_int("datum.dsize", headers.found, headers.defs)
271
+ checking_for("sizeof(DBM) is available") {
272
+ if try_compile(<<SRC)
273
+ #ifdef HAVE_CDEFS_H
274
+ # include <cdefs.h>
275
+ #endif
276
+ #ifdef HAVE_SYS_CDEFS_H
277
+ # include <sys/cdefs.h>
278
+ #endif
279
+ #include DBM_HDR
280
+
281
+ const int sizeof_DBM = (int)sizeof(DBM);
282
+ SRC
283
+ $defs << '-DDBM_SIZEOF_DBM=sizeof(DBM)'
284
+ else
285
+ $defs << '-DDBM_SIZEOF_DBM=0'
286
+ end
287
+ }
288
+ create_makefile("dbm")
289
+ end
290
+ # :startdoc:
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Yukihiro Matsumoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Provides a wrapper for the UNIX-style Database Manager Library
42
+ email:
43
+ - matz@ruby-lang.org
44
+ executables: []
45
+ extensions:
46
+ - ext/dbm/extconf.rb
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ext/dbm/dbm.c
50
+ - ext/dbm/extconf.rb
51
+ homepage: https://www.ruby-lang.org
52
+ licenses:
53
+ - BSD-2-Clause
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.5.0dev
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.6.11
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Provides a wrapper for the UNIX-style Database Manager Library
75
+ test_files: []