bdb1 0.2.4 → 0.2.5
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.
- data/Changes +15 -2
- data/VERSION +1 -1
- data/bdb1.gemspec +12 -12
- data/ext/bdb1/bdb1.c +151 -272
- data/ext/bdb1/bdb1.h +2 -26
- data/ext/bdb1/delegate.c +44 -64
- data/ext/bdb1/extconf.rb +0 -18
- data/ext/bdb1/recnum.c +65 -178
- data/test/test_btree.rb +7 -3
- data/test/test_hash.rb +2 -30
- metadata +55 -86
data/Changes
CHANGED
@@ -39,13 +39,26 @@
|
|
39
39
|
* BDB1::Common::[]
|
40
40
|
* corrected set_fetch_value
|
41
41
|
* new return value for []= (1.8.0)
|
42
|
-
* adapted
|
42
|
+
* adapted to 1.8.0
|
43
43
|
|
44
44
|
--- 0.1.9
|
45
45
|
|
46
|
-
* adapted
|
46
|
+
* adapted to 1.8 (minor modifications)
|
47
47
|
|
48
48
|
--- 0.2.2
|
49
49
|
|
50
50
|
* corrected dbst->info (Thanks Matthew Luckie <mjl@luckie.org.nz>)
|
51
51
|
* added documentation for ri (make ri-site)
|
52
|
+
|
53
|
+
--- 0.2.3
|
54
|
+
|
55
|
+
* adapted to ruby 1.9.0.
|
56
|
+
|
57
|
+
--- 0.2.4
|
58
|
+
|
59
|
+
* converted rd to rdoc.
|
60
|
+
* gemified.
|
61
|
+
|
62
|
+
--- 0.2.5
|
63
|
+
|
64
|
+
* adapted to ruby 1.9.3.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/bdb1.gemspec
CHANGED
@@ -4,15 +4,15 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.2.
|
7
|
+
s.name = %q{bdb1}
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
15
|
-
s.extensions = [
|
11
|
+
s.authors = [%q{Guy Decoux}, %q{Akinori MUSHA}]
|
12
|
+
s.date = %q{2012-01-02}
|
13
|
+
s.description = %q{This is a Ruby interface to Berkeley DB 1.85 and 1.86.}
|
14
|
+
s.email = %q{knu@idaemons.org}
|
15
|
+
s.extensions = [%q{ext/bdb1/extconf.rb}]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
18
18
|
"README.md"
|
@@ -45,11 +45,11 @@ Gem::Specification.new do |s|
|
|
45
45
|
"test/test_recnum.rb",
|
46
46
|
"test/tmp/.keep_me"
|
47
47
|
]
|
48
|
-
s.homepage =
|
49
|
-
s.licenses = [
|
50
|
-
s.require_paths = [
|
51
|
-
s.rubygems_version =
|
52
|
-
s.summary =
|
48
|
+
s.homepage = %q{http://github.com/knu/ruby-bdb1}
|
49
|
+
s.licenses = [%q{Ruby's}]
|
50
|
+
s.require_paths = [%q{lib}]
|
51
|
+
s.rubygems_version = %q{1.8.5}
|
52
|
+
s.summary = %q{A Ruby interface to Berkeley DB 1.85 and 1.86}
|
53
53
|
|
54
54
|
if s.respond_to? :specification_version then
|
55
55
|
s.specification_version = 3
|
data/ext/bdb1/bdb1.c
CHANGED
@@ -13,7 +13,7 @@ static ID id_bt_compare, id_bt_prefix, id_h_hash, bdb1_id_call;
|
|
13
13
|
static VALUE bdb1_errstr;
|
14
14
|
static int bdb1_errcall = 0;
|
15
15
|
|
16
|
-
static char *
|
16
|
+
static const char *
|
17
17
|
db_strerror(int err)
|
18
18
|
{
|
19
19
|
if (err == 0)
|
@@ -26,8 +26,7 @@ db_strerror(int err)
|
|
26
26
|
}
|
27
27
|
|
28
28
|
int
|
29
|
-
bdb1_test_error(comm)
|
30
|
-
int comm;
|
29
|
+
bdb1_test_error(int comm)
|
31
30
|
{
|
32
31
|
VALUE error;
|
33
32
|
|
@@ -39,7 +38,7 @@ bdb1_test_error(comm)
|
|
39
38
|
error = bdb1_eFatal;
|
40
39
|
if (bdb1_errcall) {
|
41
40
|
bdb1_errcall = 0;
|
42
|
-
rb_raise(error, "%s -- %s",
|
41
|
+
rb_raise(error, "%s -- %s", StringValueCStr(bdb1_errstr), db_strerror(comm));
|
43
42
|
}
|
44
43
|
else
|
45
44
|
rb_raise(error, "%s", db_strerror(errno));
|
@@ -48,14 +47,9 @@ bdb1_test_error(comm)
|
|
48
47
|
}
|
49
48
|
|
50
49
|
static VALUE
|
51
|
-
test_dump(obj, key, a, type_kv)
|
52
|
-
VALUE obj;
|
53
|
-
DBT *key;
|
54
|
-
VALUE a;
|
55
|
-
int type_kv;
|
50
|
+
test_dump(VALUE obj, DBT *key, VALUE a, int type_kv)
|
56
51
|
{
|
57
52
|
bdb1_DB *dbst;
|
58
|
-
int is_nil = 0;
|
59
53
|
VALUE tmp = a;
|
60
54
|
|
61
55
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -67,7 +61,7 @@ test_dump(obj, key, a, type_kv)
|
|
67
61
|
tmp = rb_funcall(dbst->filter[type_kv], bdb1_id_call, 1, a);
|
68
62
|
}
|
69
63
|
}
|
70
|
-
if (dbst->marshal) {
|
64
|
+
if (dbst->marshal != Qundef) {
|
71
65
|
if (rb_obj_is_kind_of(a, bdb1_cDelegate)) {
|
72
66
|
tmp = bdb1_deleg_to_orig(tmp);
|
73
67
|
}
|
@@ -78,22 +72,23 @@ test_dump(obj, key, a, type_kv)
|
|
78
72
|
}
|
79
73
|
else {
|
80
74
|
tmp = rb_obj_as_string(tmp);
|
81
|
-
if (a
|
82
|
-
|
75
|
+
if (NIL_P(a)) {
|
76
|
+
key->data = StringValueCStr(tmp);
|
77
|
+
key->size = RSTRING_LEN(tmp) + 1;
|
78
|
+
return tmp;
|
79
|
+
}
|
83
80
|
}
|
84
81
|
key->data = StringValuePtr(tmp);
|
85
|
-
key->size = RSTRING_LEN(tmp)
|
82
|
+
key->size = RSTRING_LEN(tmp);
|
86
83
|
return tmp;
|
87
84
|
}
|
88
85
|
|
89
86
|
static VALUE
|
90
|
-
test_ret(obj, tmp, a, type_kv)
|
91
|
-
VALUE obj, tmp, a;
|
92
|
-
int type_kv;
|
87
|
+
test_ret(VALUE obj, VALUE tmp, VALUE a, int type_kv)
|
93
88
|
{
|
94
89
|
bdb1_DB *dbst;
|
95
90
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
96
|
-
if (dbst->marshal || a
|
91
|
+
if (dbst->marshal != Qundef || NIL_P(a)) {
|
97
92
|
return a;
|
98
93
|
}
|
99
94
|
if (dbst->filter[type_kv]) {
|
@@ -103,11 +98,7 @@ test_ret(obj, tmp, a, type_kv)
|
|
103
98
|
}
|
104
99
|
|
105
100
|
static VALUE
|
106
|
-
test_recno(obj, key, recno, a)
|
107
|
-
VALUE obj;
|
108
|
-
DBT *key;
|
109
|
-
db_recno_t *recno;
|
110
|
-
VALUE a;
|
101
|
+
test_recno(VALUE obj, DBT *key, db_recno_t *recno, VALUE a)
|
111
102
|
{
|
112
103
|
bdb1_DB *dbst;
|
113
104
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -121,17 +112,14 @@ test_recno(obj, key, recno, a)
|
|
121
112
|
}
|
122
113
|
|
123
114
|
VALUE
|
124
|
-
bdb1_test_load(obj, a, type_kv)
|
125
|
-
VALUE obj;
|
126
|
-
DBT *a;
|
127
|
-
int type_kv;
|
115
|
+
bdb1_test_load(VALUE obj, const DBT *a, int type_kv)
|
128
116
|
{
|
129
117
|
VALUE res;
|
130
118
|
int i;
|
131
119
|
bdb1_DB *dbst;
|
132
120
|
|
133
121
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
134
|
-
if (dbst->marshal) {
|
122
|
+
if (dbst->marshal != Qundef) {
|
135
123
|
res = rb_str_new(a->data, a->size);
|
136
124
|
if (dbst->filter[2 + type_kv]) {
|
137
125
|
if (FIXNUM_P(dbst->filter[2 + type_kv])) {
|
@@ -168,9 +156,7 @@ bdb1_test_load(obj, a, type_kv)
|
|
168
156
|
}
|
169
157
|
|
170
158
|
static VALUE
|
171
|
-
test_load_dyna(obj, key, val)
|
172
|
-
VALUE obj;
|
173
|
-
DBT *key, *val;
|
159
|
+
test_load_dyna(VALUE obj, DBT *key, DBT *val)
|
174
160
|
{
|
175
161
|
bdb1_DB *dbst;
|
176
162
|
VALUE del, res, tmp;
|
@@ -178,7 +164,7 @@ test_load_dyna(obj, key, val)
|
|
178
164
|
|
179
165
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
180
166
|
res = bdb1_test_load(obj, val, FILTER_VALUE);
|
181
|
-
if (dbst->marshal && !SPECIAL_CONST_P(res)) {
|
167
|
+
if (dbst->marshal != Qundef && !SPECIAL_CONST_P(res)) {
|
182
168
|
del = Data_Make_Struct(bdb1_cDelegate, struct deleg_class,
|
183
169
|
bdb1_deleg_mark, bdb1_deleg_free, delegst);
|
184
170
|
delegst->db = obj;
|
@@ -197,13 +183,12 @@ test_load_dyna(obj, key, val)
|
|
197
183
|
|
198
184
|
|
199
185
|
static int
|
200
|
-
bdb1_bt_compare(a, b)
|
201
|
-
DBT *a, *b;
|
186
|
+
bdb1_bt_compare(const DBT *a, const DBT *b)
|
202
187
|
{
|
203
188
|
VALUE obj, av, bv, res;
|
204
189
|
bdb1_DB *dbst;
|
205
190
|
|
206
|
-
if ((obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))
|
191
|
+
if (NIL_P(obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))) {
|
207
192
|
rb_raise(bdb1_eFatal, "BUG : current_db not set");
|
208
193
|
}
|
209
194
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -217,13 +202,12 @@ bdb1_bt_compare(a, b)
|
|
217
202
|
}
|
218
203
|
|
219
204
|
static size_t
|
220
|
-
bdb1_bt_prefix(a, b)
|
221
|
-
DBT *a, *b;
|
205
|
+
bdb1_bt_prefix(const DBT *a, const DBT *b)
|
222
206
|
{
|
223
207
|
VALUE obj, av, bv, res;
|
224
208
|
bdb1_DB *dbst;
|
225
209
|
|
226
|
-
if ((obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))
|
210
|
+
if (NIL_P(obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))) {
|
227
211
|
rb_raise(bdb1_eFatal, "BUG : current_db not set");
|
228
212
|
}
|
229
213
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -237,14 +221,12 @@ bdb1_bt_prefix(a, b)
|
|
237
221
|
}
|
238
222
|
|
239
223
|
static u_int32_t
|
240
|
-
bdb1_h_hash(bytes, length)
|
241
|
-
void *bytes;
|
242
|
-
u_int32_t length;
|
224
|
+
bdb1_h_hash(const void *bytes, size_t length)
|
243
225
|
{
|
244
226
|
VALUE obj, st, res;
|
245
227
|
bdb1_DB *dbst;
|
246
228
|
|
247
|
-
if ((obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))
|
229
|
+
if (NIL_P(obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))) {
|
248
230
|
rb_raise(bdb1_eFatal, "BUG : current_db not set");
|
249
231
|
}
|
250
232
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -253,12 +235,11 @@ bdb1_h_hash(bytes, length)
|
|
253
235
|
res = rb_funcall(obj, id_h_hash, 1, st);
|
254
236
|
else
|
255
237
|
res = rb_funcall(dbst->h_hash, bdb1_id_call, 1, st);
|
256
|
-
return
|
238
|
+
return (u_int32_t)NUM2LONG(res);
|
257
239
|
}
|
258
240
|
|
259
241
|
static void
|
260
|
-
bdb1_i_close(dbst)
|
261
|
-
bdb1_DB *dbst;
|
242
|
+
bdb1_i_close(bdb1_DB *dbst)
|
262
243
|
{
|
263
244
|
if (dbst->dbp != NULL && !(dbst->options & BDB1_NOT_OPEN)) {
|
264
245
|
dbst->options |= BDB1_NOT_OPEN;
|
@@ -268,16 +249,14 @@ bdb1_i_close(dbst)
|
|
268
249
|
}
|
269
250
|
|
270
251
|
static void
|
271
|
-
bdb1_free(dbst)
|
272
|
-
bdb1_DB *dbst;
|
252
|
+
bdb1_free(bdb1_DB *dbst)
|
273
253
|
{
|
274
254
|
bdb1_i_close(dbst);
|
275
255
|
free(dbst);
|
276
256
|
}
|
277
257
|
|
278
258
|
static void
|
279
|
-
bdb1_mark(dbst)
|
280
|
-
bdb1_DB *dbst;
|
259
|
+
bdb1_mark(bdb1_DB *dbst)
|
281
260
|
{
|
282
261
|
int i;
|
283
262
|
|
@@ -291,8 +270,7 @@ bdb1_mark(dbst)
|
|
291
270
|
}
|
292
271
|
|
293
272
|
static VALUE
|
294
|
-
bdb1_i185_btree(obj, dbstobj)
|
295
|
-
VALUE obj, dbstobj;
|
273
|
+
bdb1_i185_btree(VALUE obj, VALUE dbstobj)
|
296
274
|
{
|
297
275
|
VALUE key, value;
|
298
276
|
bdb1_DB *dbst;
|
@@ -302,7 +280,7 @@ bdb1_i185_btree(obj, dbstobj)
|
|
302
280
|
key = rb_ary_entry(obj, 0);
|
303
281
|
value = rb_ary_entry(obj, 1);
|
304
282
|
key = rb_obj_as_string(key);
|
305
|
-
options =
|
283
|
+
options = StringValueCStr(key);
|
306
284
|
if (strcmp(options, "set_flags") == 0) {
|
307
285
|
dbst->has_info = Qtrue;
|
308
286
|
dbst->info.bi.flags = NUM2INT(value);
|
@@ -345,8 +323,7 @@ bdb1_i185_btree(obj, dbstobj)
|
|
345
323
|
}
|
346
324
|
|
347
325
|
static VALUE
|
348
|
-
bdb1_i185_hash(obj, dbstobj)
|
349
|
-
VALUE obj, dbstobj;
|
326
|
+
bdb1_i185_hash(VALUE obj, VALUE dbstobj)
|
350
327
|
{
|
351
328
|
VALUE key, value;
|
352
329
|
bdb1_DB *dbst;
|
@@ -356,7 +333,7 @@ bdb1_i185_hash(obj, dbstobj)
|
|
356
333
|
key = rb_ary_entry(obj, 0);
|
357
334
|
value = rb_ary_entry(obj, 1);
|
358
335
|
key = rb_obj_as_string(key);
|
359
|
-
options =
|
336
|
+
options = StringValueCStr(key);
|
360
337
|
if (strcmp(options, "set_h_ffactor") == 0) {
|
361
338
|
dbst->has_info = Qtrue;
|
362
339
|
dbst->info.hi.ffactor = NUM2INT(value);
|
@@ -386,8 +363,7 @@ bdb1_i185_hash(obj, dbstobj)
|
|
386
363
|
}
|
387
364
|
|
388
365
|
static VALUE
|
389
|
-
bdb1_i185_recno(obj, dbstobj)
|
390
|
-
VALUE obj, dbstobj;
|
366
|
+
bdb1_i185_recno(VALUE obj, VALUE dbstobj)
|
391
367
|
{
|
392
368
|
VALUE key, value;
|
393
369
|
bdb1_DB *dbst;
|
@@ -397,7 +373,7 @@ bdb1_i185_recno(obj, dbstobj)
|
|
397
373
|
key = rb_ary_entry(obj, 0);
|
398
374
|
value = rb_ary_entry(obj, 1);
|
399
375
|
key = rb_obj_as_string(key);
|
400
|
-
options =
|
376
|
+
options = StringValueCStr(key);
|
401
377
|
if (strcmp(options, "set_flags") == 0) {
|
402
378
|
dbst->has_info = Qtrue;
|
403
379
|
dbst->info.ri.flags = NUM2INT(value);
|
@@ -405,7 +381,7 @@ bdb1_i185_recno(obj, dbstobj)
|
|
405
381
|
else if (strcmp(options, "set_re_delim") == 0) {
|
406
382
|
int ch;
|
407
383
|
if (TYPE(value) == T_STRING) {
|
408
|
-
str =
|
384
|
+
str = StringValueCStr(value);
|
409
385
|
dbst->info.ri.bval = str[0];
|
410
386
|
}
|
411
387
|
else {
|
@@ -422,7 +398,7 @@ bdb1_i185_recno(obj, dbstobj)
|
|
422
398
|
else if (strcmp(options, "set_re_pad") == 0) {
|
423
399
|
int ch;
|
424
400
|
if (TYPE(value) == T_STRING) {
|
425
|
-
str =
|
401
|
+
str = StringValueCStr(value);
|
426
402
|
dbst->info.ri.bval = str[0];
|
427
403
|
}
|
428
404
|
else {
|
@@ -456,8 +432,7 @@ bdb1_i185_recno(obj, dbstobj)
|
|
456
432
|
}
|
457
433
|
|
458
434
|
static VALUE
|
459
|
-
bdb1_load_dump(obj)
|
460
|
-
VALUE obj;
|
435
|
+
bdb1_load_dump(VALUE obj)
|
461
436
|
{
|
462
437
|
VALUE res;
|
463
438
|
|
@@ -469,8 +444,7 @@ bdb1_load_dump(obj)
|
|
469
444
|
}
|
470
445
|
|
471
446
|
static VALUE
|
472
|
-
bdb1_i185_common(obj, dbstobj)
|
473
|
-
VALUE obj, dbstobj;
|
447
|
+
bdb1_i185_common(VALUE obj, VALUE dbstobj)
|
474
448
|
{
|
475
449
|
VALUE key, value;
|
476
450
|
bdb1_DB *dbst;
|
@@ -480,7 +454,7 @@ bdb1_i185_common(obj, dbstobj)
|
|
480
454
|
key = rb_ary_entry(obj, 0);
|
481
455
|
value = rb_ary_entry(obj, 1);
|
482
456
|
key = rb_obj_as_string(key);
|
483
|
-
options =
|
457
|
+
options = StringValueCStr(key);
|
484
458
|
if (strcmp(options, "marshal") == 0) {
|
485
459
|
switch (value) {
|
486
460
|
case Qtrue:
|
@@ -488,7 +462,7 @@ bdb1_i185_common(obj, dbstobj)
|
|
488
462
|
dbst->options |= BDB1_MARSHAL;
|
489
463
|
break;
|
490
464
|
case Qfalse:
|
491
|
-
dbst->marshal =
|
465
|
+
dbst->marshal = Qundef;
|
492
466
|
dbst->options &= ~BDB1_MARSHAL;
|
493
467
|
break;
|
494
468
|
default:
|
@@ -528,12 +502,11 @@ bdb1_i185_common(obj, dbstobj)
|
|
528
502
|
}
|
529
503
|
|
530
504
|
static int
|
531
|
-
bdb1_hard_count(dbp)
|
532
|
-
DB *dbp;
|
505
|
+
bdb1_hard_count(DB *dbp)
|
533
506
|
{
|
534
507
|
DBT key, data;
|
535
508
|
db_recno_t recno;
|
536
|
-
|
509
|
+
int count = 0;
|
537
510
|
|
538
511
|
DATA_ZERO(key);
|
539
512
|
key.data = &recno;
|
@@ -644,10 +617,7 @@ bdb1_hard_count(dbp)
|
|
644
617
|
* end
|
645
618
|
*/
|
646
619
|
VALUE
|
647
|
-
bdb1_init(argc, argv, obj)
|
648
|
-
int argc;
|
649
|
-
VALUE *argv;
|
650
|
-
VALUE obj;
|
620
|
+
bdb1_init(int argc, VALUE *argv, VALUE obj)
|
651
621
|
{
|
652
622
|
VALUE b, c, d, f;
|
653
623
|
int mode, oflags;
|
@@ -668,7 +638,7 @@ bdb1_init(argc, argv, obj)
|
|
668
638
|
/* ... */
|
669
639
|
case 2:
|
670
640
|
if (TYPE(c) == T_STRING) {
|
671
|
-
char *m =
|
641
|
+
char *m = StringValueCStr(c);
|
672
642
|
if (strcmp(m, "r") == 0) {
|
673
643
|
oflags = DB_RDONLY;
|
674
644
|
}
|
@@ -685,7 +655,7 @@ bdb1_init(argc, argv, obj)
|
|
685
655
|
rb_raise(bdb1_eFatal, "flags must be r, r+, w, w+, a or a+");
|
686
656
|
}
|
687
657
|
}
|
688
|
-
else if (c
|
658
|
+
else if (NIL_P(c)) {
|
689
659
|
oflags = DB_RDONLY;
|
690
660
|
}
|
691
661
|
else {
|
@@ -695,7 +665,7 @@ bdb1_init(argc, argv, obj)
|
|
695
665
|
case 1:
|
696
666
|
if (!NIL_P(b)) {
|
697
667
|
SafeStringValue(b);
|
698
|
-
name =
|
668
|
+
name = StringValueCStr(b);
|
699
669
|
}
|
700
670
|
else {
|
701
671
|
name = NULL;
|
@@ -758,8 +728,7 @@ bdb1_init(argc, argv, obj)
|
|
758
728
|
* Closes the file.
|
759
729
|
*/
|
760
730
|
static VALUE
|
761
|
-
bdb1_close(obj)
|
762
|
-
VALUE obj;
|
731
|
+
bdb1_close(VALUE obj)
|
763
732
|
{
|
764
733
|
VALUE opt;
|
765
734
|
bdb1_DB *dbst;
|
@@ -773,13 +742,13 @@ bdb1_close(obj)
|
|
773
742
|
}
|
774
743
|
|
775
744
|
VALUE
|
776
|
-
bdb1_s_alloc(obj)
|
777
|
-
VALUE obj;
|
745
|
+
bdb1_s_alloc(VALUE obj)
|
778
746
|
{
|
779
747
|
bdb1_DB *dbst;
|
780
748
|
VALUE res, cl;
|
781
749
|
|
782
750
|
res = Data_Make_Struct(obj, bdb1_DB, bdb1_mark, bdb1_free, dbst);
|
751
|
+
dbst->marshal = Qundef;
|
783
752
|
dbst->options |= BDB1_NOT_OPEN;
|
784
753
|
cl = obj;
|
785
754
|
while (cl) {
|
@@ -795,7 +764,7 @@ bdb1_s_alloc(obj)
|
|
795
764
|
dbst->type = DB_RECNO;
|
796
765
|
break;
|
797
766
|
}
|
798
|
-
cl =
|
767
|
+
cl = RCLASS_SUPER(cl);
|
799
768
|
}
|
800
769
|
if (!cl) {
|
801
770
|
rb_raise(bdb1_eFatal, "unknown database type");
|
@@ -804,16 +773,16 @@ bdb1_s_alloc(obj)
|
|
804
773
|
dbst->marshal = obj;
|
805
774
|
dbst->options |= BDB1_MARSHAL;
|
806
775
|
}
|
807
|
-
if (rb_method_boundp(obj, rb_intern("bdb1_store_key"), 0)
|
776
|
+
if (rb_method_boundp(obj, rb_intern("bdb1_store_key"), 0)) {
|
808
777
|
dbst->filter[FILTER_KEY] = INT2FIX(rb_intern("bdb1_store_key"));
|
809
778
|
}
|
810
|
-
if (rb_method_boundp(obj, rb_intern("bdb1_fetch_key"), 0)
|
779
|
+
if (rb_method_boundp(obj, rb_intern("bdb1_fetch_key"), 0)) {
|
811
780
|
dbst->filter[2 + FILTER_KEY] = INT2FIX(rb_intern("bdb1_fetch_key"));
|
812
781
|
}
|
813
|
-
if (rb_method_boundp(obj, rb_intern("bdb1_store_value"), 0)
|
782
|
+
if (rb_method_boundp(obj, rb_intern("bdb1_store_value"), 0)) {
|
814
783
|
dbst->filter[FILTER_VALUE] = INT2FIX(rb_intern("bdb1_store_value"));
|
815
784
|
}
|
816
|
-
if (rb_method_boundp(obj, rb_intern("bdb1_fetch_value"), 0)
|
785
|
+
if (rb_method_boundp(obj, rb_intern("bdb1_fetch_value"), 0)) {
|
817
786
|
dbst->filter[2 + FILTER_VALUE] = INT2FIX(rb_intern("bdb1_fetch_value"));
|
818
787
|
}
|
819
788
|
return res;
|
@@ -823,10 +792,7 @@ bdb1_s_alloc(obj)
|
|
823
792
|
* Same as +new+.
|
824
793
|
*/
|
825
794
|
static VALUE
|
826
|
-
bdb1_s_create(argc, argv, obj)
|
827
|
-
int argc;
|
828
|
-
VALUE *argv;
|
829
|
-
VALUE obj;
|
795
|
+
bdb1_s_create(int argc, VALUE *argv, VALUE obj)
|
830
796
|
{
|
831
797
|
VALUE st, res;
|
832
798
|
|
@@ -836,8 +802,7 @@ bdb1_s_create(argc, argv, obj)
|
|
836
802
|
}
|
837
803
|
|
838
804
|
static VALUE
|
839
|
-
bdb1_i_create(obj, db)
|
840
|
-
VALUE obj, db;
|
805
|
+
bdb1_i_create(VALUE obj, VALUE db)
|
841
806
|
{
|
842
807
|
VALUE tmp[2];
|
843
808
|
tmp[0] = rb_ary_entry(obj, 0);
|
@@ -859,10 +824,7 @@ bdb1_i_create(obj, db)
|
|
859
824
|
* given hash or pairs of objects.
|
860
825
|
*/
|
861
826
|
static VALUE
|
862
|
-
bdb1_s_aref(argc, argv, obj)
|
863
|
-
int argc;
|
864
|
-
VALUE *argv;
|
865
|
-
VALUE obj;
|
827
|
+
bdb1_s_aref(int argc, VALUE *argv, VALUE obj)
|
866
828
|
{
|
867
829
|
VALUE res, tmp[2];
|
868
830
|
int i;
|
@@ -886,10 +848,7 @@ bdb1_s_aref(argc, argv, obj)
|
|
886
848
|
* initialized object which is automatically closed when done.
|
887
849
|
*/
|
888
850
|
static VALUE
|
889
|
-
bdb1_s_open(argc, argv, obj)
|
890
|
-
int argc;
|
891
|
-
VALUE *argv;
|
892
|
-
VALUE obj;
|
851
|
+
bdb1_s_open(int argc, VALUE *argv, VALUE obj)
|
893
852
|
{
|
894
853
|
VALUE res = rb_funcall2(obj, rb_intern("new"), argc, argv);
|
895
854
|
if (rb_block_given_p()) {
|
@@ -909,10 +868,7 @@ bdb1_s_open(argc, argv, obj)
|
|
909
868
|
* return +nil+ if the specified key exist, otherwise +true+.
|
910
869
|
*/
|
911
870
|
VALUE
|
912
|
-
bdb1_put(argc, argv, obj)
|
913
|
-
int argc;
|
914
|
-
VALUE *argv;
|
915
|
-
VALUE obj;
|
871
|
+
bdb1_put(int argc, VALUE *argv, VALUE obj)
|
916
872
|
{
|
917
873
|
volatile VALUE a0 = Qnil;
|
918
874
|
volatile VALUE b0 = Qnil;
|
@@ -924,11 +880,10 @@ bdb1_put(argc, argv, obj)
|
|
924
880
|
|
925
881
|
rb_secure(4);
|
926
882
|
GetDB(obj, dbst);
|
927
|
-
|
928
|
-
a = b = c = Qnil;
|
929
|
-
if (rb_scan_args(argc, argv, "21", &a, &b, &c) == 3) {
|
883
|
+
if (rb_scan_args(argc, argv, "21", &a, &b, &c) == 3)
|
930
884
|
flags = NUM2INT(c);
|
931
|
-
|
885
|
+
else
|
886
|
+
flags = 0;
|
932
887
|
DATA_ZERO(key);
|
933
888
|
DATA_ZERO(data);
|
934
889
|
a0 = test_recno(obj, &key, &recno, a);
|
@@ -936,14 +891,11 @@ bdb1_put(argc, argv, obj)
|
|
936
891
|
ret = bdb1_test_error(dbst->dbp->put(dbst->dbp, &key, &data, flags));
|
937
892
|
if (ret == DB_KEYEXIST)
|
938
893
|
return Qfalse;
|
939
|
-
|
940
|
-
return test_ret(obj, b0, b, FILTER_VALUE);
|
941
|
-
}
|
894
|
+
return test_ret(obj, b0, b, FILTER_VALUE);
|
942
895
|
}
|
943
896
|
|
944
897
|
static VALUE
|
945
|
-
bdb1_assign(obj, a, b)
|
946
|
-
VALUE obj, a, b;
|
898
|
+
bdb1_assign(VALUE obj, VALUE a, VALUE b)
|
947
899
|
{
|
948
900
|
VALUE tmp[2];
|
949
901
|
tmp[0] = a;
|
@@ -953,9 +905,7 @@ bdb1_assign(obj, a, b)
|
|
953
905
|
}
|
954
906
|
|
955
907
|
static VALUE
|
956
|
-
test_load_key(obj, key)
|
957
|
-
VALUE obj;
|
958
|
-
DBT *key;
|
908
|
+
test_load_key(VALUE obj, DBT *key)
|
959
909
|
{
|
960
910
|
bdb1_DB *dbst;
|
961
911
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
@@ -965,30 +915,21 @@ test_load_key(obj, key)
|
|
965
915
|
}
|
966
916
|
|
967
917
|
static VALUE
|
968
|
-
bdb1_assoc(obj, key, data)
|
969
|
-
VALUE obj;
|
970
|
-
DBT *key, *data;
|
918
|
+
bdb1_assoc(VALUE obj, DBT *key, DBT *data)
|
971
919
|
{
|
972
920
|
return rb_assoc_new(test_load_key(obj, key),
|
973
921
|
bdb1_test_load(obj, data, FILTER_VALUE));
|
974
922
|
}
|
975
923
|
|
976
924
|
static VALUE
|
977
|
-
bdb1_assoc_dyna(obj, key, data)
|
978
|
-
VALUE obj;
|
979
|
-
DBT *key, *data;
|
925
|
+
bdb1_assoc_dyna(VALUE obj, DBT *key, DBT *data)
|
980
926
|
{
|
981
927
|
return rb_assoc_new(test_load_key(obj, key),
|
982
928
|
test_load_dyna(obj, key, data));
|
983
929
|
}
|
984
930
|
|
985
931
|
static VALUE
|
986
|
-
bdb1_get_internal(argc, argv, obj, notfound, dyna)
|
987
|
-
int argc;
|
988
|
-
VALUE *argv;
|
989
|
-
VALUE obj;
|
990
|
-
VALUE notfound;
|
991
|
-
int dyna;
|
932
|
+
bdb1_get_internal(int argc, VALUE *argv, VALUE obj, VALUE notfound, int dyna)
|
992
933
|
{
|
993
934
|
volatile VALUE a = Qnil;
|
994
935
|
VALUE b, c;
|
@@ -1024,10 +965,7 @@ bdb1_get_internal(argc, argv, obj, notfound, dyna)
|
|
1024
965
|
}
|
1025
966
|
|
1026
967
|
VALUE
|
1027
|
-
bdb1_get(argc, argv, obj)
|
1028
|
-
int argc;
|
1029
|
-
VALUE *argv;
|
1030
|
-
VALUE obj;
|
968
|
+
bdb1_get(int argc, VALUE *argv, VALUE obj)
|
1031
969
|
{
|
1032
970
|
return bdb1_get_internal(argc, argv, obj, Qnil, 0);
|
1033
971
|
}
|
@@ -1040,18 +978,13 @@ bdb1_get(argc, argv, obj)
|
|
1040
978
|
* Returns the value corresponding to +key+.
|
1041
979
|
*/
|
1042
980
|
static VALUE
|
1043
|
-
bdb1_get_dyna(argc, argv, obj)
|
1044
|
-
int argc;
|
1045
|
-
VALUE *argv;
|
1046
|
-
VALUE obj;
|
981
|
+
bdb1_get_dyna(int argc, VALUE *argv, VALUE obj)
|
1047
982
|
{
|
1048
983
|
return bdb1_get_internal(argc, argv, obj, Qnil, 1);
|
1049
984
|
}
|
1050
985
|
|
1051
986
|
static VALUE
|
1052
|
-
bdb1_fetch(argc, argv, obj)
|
1053
|
-
int argc;
|
1054
|
-
VALUE *argv, obj;
|
987
|
+
bdb1_fetch(int argc, VALUE *argv, VALUE obj)
|
1055
988
|
{
|
1056
989
|
VALUE key, if_none;
|
1057
990
|
VALUE val;
|
@@ -1074,10 +1007,9 @@ bdb1_fetch(argc, argv, obj)
|
|
1074
1007
|
}
|
1075
1008
|
|
1076
1009
|
static VALUE
|
1077
|
-
bdb1_has_key(obj, key)
|
1078
|
-
VALUE obj, key;
|
1010
|
+
bdb1_has_key(VALUE obj, VALUE key)
|
1079
1011
|
{
|
1080
|
-
return bdb1_get_internal(1, &key, obj, Qfalse);
|
1012
|
+
return bdb1_get_internal(1, &key, obj, Qfalse, 0);
|
1081
1013
|
}
|
1082
1014
|
|
1083
1015
|
/*
|
@@ -1087,8 +1019,7 @@ bdb1_has_key(obj, key)
|
|
1087
1019
|
* Returns +true+ if the association from +key+ is +value+.
|
1088
1020
|
*/
|
1089
1021
|
static VALUE
|
1090
|
-
bdb1_has_both(obj, a, b)
|
1091
|
-
VALUE obj, a, b;
|
1022
|
+
bdb1_has_both(VALUE obj, VALUE a, VALUE b)
|
1092
1023
|
{
|
1093
1024
|
bdb1_DB *dbst;
|
1094
1025
|
DBT key, data;
|
@@ -1132,8 +1063,7 @@ bdb1_has_both(obj, a, b)
|
|
1132
1063
|
* exist.
|
1133
1064
|
*/
|
1134
1065
|
VALUE
|
1135
|
-
bdb1_del(obj, a)
|
1136
|
-
VALUE a, obj;
|
1066
|
+
bdb1_del(VALUE obj, VALUE a)
|
1137
1067
|
{
|
1138
1068
|
bdb1_DB *dbst;
|
1139
1069
|
DBT key;
|
@@ -1156,8 +1086,7 @@ bdb1_del(obj, a)
|
|
1156
1086
|
}
|
1157
1087
|
|
1158
1088
|
static VALUE
|
1159
|
-
bdb1_empty(obj)
|
1160
|
-
VALUE obj;
|
1089
|
+
bdb1_empty(VALUE obj)
|
1161
1090
|
{
|
1162
1091
|
bdb1_DB *dbst;
|
1163
1092
|
DBT key, data;
|
@@ -1176,8 +1105,7 @@ bdb1_empty(obj)
|
|
1176
1105
|
}
|
1177
1106
|
|
1178
1107
|
static VALUE
|
1179
|
-
bdb1_delete_if(obj)
|
1180
|
-
VALUE obj;
|
1108
|
+
bdb1_delete_if(VALUE obj)
|
1181
1109
|
{
|
1182
1110
|
bdb1_DB *dbst;
|
1183
1111
|
DBT key, data, save;
|
@@ -1203,8 +1131,7 @@ bdb1_delete_if(obj)
|
|
1203
1131
|
}
|
1204
1132
|
|
1205
1133
|
VALUE
|
1206
|
-
bdb1_clear(obj)
|
1207
|
-
VALUE obj;
|
1134
|
+
bdb1_clear(VALUE obj)
|
1208
1135
|
{
|
1209
1136
|
bdb1_DB *dbst;
|
1210
1137
|
DBT key, data, save;
|
@@ -1229,8 +1156,7 @@ bdb1_clear(obj)
|
|
1229
1156
|
}
|
1230
1157
|
|
1231
1158
|
static VALUE
|
1232
|
-
bdb1_length(obj)
|
1233
|
-
VALUE obj;
|
1159
|
+
bdb1_length(VALUE obj)
|
1234
1160
|
{
|
1235
1161
|
bdb1_DB *dbst;
|
1236
1162
|
DBT key, data;
|
@@ -1258,9 +1184,7 @@ bdb1_length(obj)
|
|
1258
1184
|
}
|
1259
1185
|
|
1260
1186
|
static VALUE
|
1261
|
-
bdb1_each_valuec(obj, sens, result)
|
1262
|
-
VALUE obj, result;
|
1263
|
-
int sens;
|
1187
|
+
bdb1_each_valuec(VALUE obj, VALUE sens, VALUE result)
|
1264
1188
|
{
|
1265
1189
|
bdb1_DB *dbst;
|
1266
1190
|
DBT key, data;
|
@@ -1281,19 +1205,26 @@ bdb1_each_valuec(obj, sens, result)
|
|
1281
1205
|
FREE_KEY(dbst, key);
|
1282
1206
|
interm = bdb1_test_load(obj, &data, FILTER_VALUE);
|
1283
1207
|
rest = rb_yield(interm);
|
1284
|
-
if (result
|
1208
|
+
if (!NIL_P(result) && RTEST(rest)) {
|
1285
1209
|
rb_ary_push(result, interm);
|
1286
1210
|
}
|
1287
1211
|
} while (1);
|
1288
1212
|
}
|
1289
1213
|
|
1290
|
-
VALUE
|
1291
|
-
|
1214
|
+
VALUE
|
1215
|
+
bdb1_each_value(VALUE obj)
|
1216
|
+
{
|
1217
|
+
return bdb1_each_valuec(obj, DB_NEXT, Qnil);
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
VALUE
|
1221
|
+
bdb1_each_eulav(VALUE obj)
|
1222
|
+
{
|
1223
|
+
return bdb1_each_valuec(obj, DB_PREV, Qnil);
|
1224
|
+
}
|
1292
1225
|
|
1293
1226
|
static VALUE
|
1294
|
-
bdb1_each_keyc(obj, sens)
|
1295
|
-
VALUE obj;
|
1296
|
-
int sens;
|
1227
|
+
bdb1_each_keyc(VALUE obj, int sens)
|
1297
1228
|
{
|
1298
1229
|
bdb1_DB *dbst;
|
1299
1230
|
DBT key, data;
|
@@ -1315,13 +1246,20 @@ bdb1_each_keyc(obj, sens)
|
|
1315
1246
|
return obj;
|
1316
1247
|
}
|
1317
1248
|
|
1318
|
-
VALUE
|
1319
|
-
|
1249
|
+
VALUE
|
1250
|
+
bdb1_each_key(VALUE obj)
|
1251
|
+
{
|
1252
|
+
return bdb1_each_keyc(obj, DB_NEXT);
|
1253
|
+
}
|
1320
1254
|
|
1321
1255
|
static VALUE
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1256
|
+
bdb1_each_yek(VALUE obj)
|
1257
|
+
{
|
1258
|
+
return bdb1_each_keyc(obj, DB_PREV);
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
static VALUE
|
1262
|
+
bdb1_each_common(VALUE obj, int sens)
|
1325
1263
|
{
|
1326
1264
|
bdb1_DB *dbst;
|
1327
1265
|
DBT key, data;
|
@@ -1343,12 +1281,20 @@ bdb1_each_common(obj, sens)
|
|
1343
1281
|
return obj;
|
1344
1282
|
}
|
1345
1283
|
|
1346
|
-
static VALUE
|
1347
|
-
|
1284
|
+
static VALUE
|
1285
|
+
bdb1_each_pair(VALUE obj)
|
1286
|
+
{
|
1287
|
+
return bdb1_each_common(obj, DB_NEXT);
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
static VALUE
|
1291
|
+
bdb1_each_riap(VALUE obj)
|
1292
|
+
{
|
1293
|
+
return bdb1_each_common(obj, DB_PREV);
|
1294
|
+
}
|
1348
1295
|
|
1349
1296
|
VALUE
|
1350
|
-
bdb1_to_type(obj, result, flag)
|
1351
|
-
VALUE obj, result, flag;
|
1297
|
+
bdb1_to_type(VALUE obj, VALUE result, VALUE flag)
|
1352
1298
|
{
|
1353
1299
|
bdb1_DB *dbst;
|
1354
1300
|
DBT key, data;
|
@@ -1358,7 +1304,7 @@ bdb1_to_type(obj, result, flag)
|
|
1358
1304
|
GetDB(obj, dbst);
|
1359
1305
|
INIT_RECNO(dbst, key, recno);
|
1360
1306
|
DATA_ZERO(data);
|
1361
|
-
flags = (flag
|
1307
|
+
flags = NIL_P(flag) ? DB_LAST : DB_FIRST;
|
1362
1308
|
do {
|
1363
1309
|
ret = bdb1_test_error(dbst->dbp->seq(dbst->dbp, &key, &data, flags));
|
1364
1310
|
if (ret == DB_NOTFOUND) {
|
@@ -1366,7 +1312,7 @@ bdb1_to_type(obj, result, flag)
|
|
1366
1312
|
}
|
1367
1313
|
switch (TYPE(result)) {
|
1368
1314
|
case T_ARRAY:
|
1369
|
-
if (flag
|
1315
|
+
if (RTEST(flag)) {
|
1370
1316
|
rb_ary_push(result, bdb1_assoc(obj, &key, &data));
|
1371
1317
|
}
|
1372
1318
|
else {
|
@@ -1374,7 +1320,7 @@ bdb1_to_type(obj, result, flag)
|
|
1374
1320
|
}
|
1375
1321
|
break;
|
1376
1322
|
case T_HASH:
|
1377
|
-
if (flag
|
1323
|
+
if (RTEST(flag)) {
|
1378
1324
|
rb_hash_aset(result, test_load_key(obj, &key),
|
1379
1325
|
bdb1_test_load(obj, &data, FILTER_VALUE));
|
1380
1326
|
}
|
@@ -1383,35 +1329,31 @@ bdb1_to_type(obj, result, flag)
|
|
1383
1329
|
test_load_key(obj, &key));
|
1384
1330
|
}
|
1385
1331
|
}
|
1386
|
-
flags = (flag
|
1332
|
+
flags = NIL_P(flag) ? DB_PREV : DB_NEXT;
|
1387
1333
|
} while (1);
|
1388
1334
|
return result;
|
1389
1335
|
}
|
1390
1336
|
|
1391
1337
|
static VALUE
|
1392
|
-
bdb1_to_a(obj)
|
1393
|
-
VALUE obj;
|
1338
|
+
bdb1_to_a(VALUE obj)
|
1394
1339
|
{
|
1395
1340
|
return bdb1_to_type(obj, rb_ary_new(), Qtrue);
|
1396
1341
|
}
|
1397
1342
|
|
1398
1343
|
static VALUE
|
1399
|
-
bdb1_invert(obj)
|
1400
|
-
VALUE obj;
|
1344
|
+
bdb1_invert(VALUE obj)
|
1401
1345
|
{
|
1402
1346
|
return bdb1_to_type(obj, rb_hash_new(), Qfalse);
|
1403
1347
|
}
|
1404
1348
|
|
1405
1349
|
static VALUE
|
1406
|
-
bdb1_to_hash(obj)
|
1407
|
-
VALUE obj;
|
1350
|
+
bdb1_to_hash(VALUE obj)
|
1408
1351
|
{
|
1409
1352
|
return bdb1_to_type(obj, rb_hash_new(), Qtrue);
|
1410
1353
|
}
|
1411
1354
|
|
1412
1355
|
static VALUE
|
1413
|
-
bdb1_each_kv(obj, a, result, flag)
|
1414
|
-
VALUE obj, a, result, flag;
|
1356
|
+
bdb1_each_kv(VALUE obj, VALUE a, VALUE result, VALUE flag)
|
1415
1357
|
{
|
1416
1358
|
bdb1_DB *dbst;
|
1417
1359
|
DBT keys, key, data;
|
@@ -1429,7 +1371,7 @@ bdb1_each_kv(obj, a, result, flag)
|
|
1429
1371
|
ret = bdb1_test_error(dbst->dbp->seq(dbst->dbp, &key, &data, flags));
|
1430
1372
|
if (ret == DB_NOTFOUND || keys.size != key.size ||
|
1431
1373
|
memcmp(keys.data, key.data, key.size) != 0) {
|
1432
|
-
return (result
|
1374
|
+
return NIL_P(result)?obj:result;
|
1433
1375
|
}
|
1434
1376
|
k = bdb1_test_load(obj, &data, FILTER_VALUE);
|
1435
1377
|
if (RTEST(flag)) {
|
@@ -1455,9 +1397,7 @@ bdb1_each_kv(obj, a, result, flag)
|
|
1455
1397
|
* If +assoc+ is +false+ return only the values.
|
1456
1398
|
*/
|
1457
1399
|
static VALUE
|
1458
|
-
bdb1_bt_duplicates(argc, argv, obj)
|
1459
|
-
int argc;
|
1460
|
-
VALUE *argv, obj;
|
1400
|
+
bdb1_bt_duplicates(int argc, VALUE *argv, VALUE obj)
|
1461
1401
|
{
|
1462
1402
|
VALUE a, b;
|
1463
1403
|
|
@@ -1474,8 +1414,7 @@ bdb1_bt_duplicates(argc, argv, obj)
|
|
1474
1414
|
* Iterates over duplicate associations for the +key+.
|
1475
1415
|
*/
|
1476
1416
|
static VALUE
|
1477
|
-
bdb1_bt_dup(obj, a)
|
1478
|
-
VALUE a, obj;
|
1417
|
+
bdb1_bt_dup(VALUE obj, VALUE a)
|
1479
1418
|
{
|
1480
1419
|
return bdb1_each_kv(obj, a, Qnil, Qtrue);
|
1481
1420
|
}
|
@@ -1487,22 +1426,19 @@ bdb1_bt_dup(obj, a)
|
|
1487
1426
|
* Iterates over duplicate values for the +key+.
|
1488
1427
|
*/
|
1489
1428
|
static VALUE
|
1490
|
-
bdb1_bt_dupval(obj, a)
|
1491
|
-
VALUE a, obj;
|
1429
|
+
bdb1_bt_dupval(VALUE obj, VALUE a)
|
1492
1430
|
{
|
1493
1431
|
return bdb1_each_kv(obj, a, Qnil, Qfalse);
|
1494
1432
|
}
|
1495
1433
|
|
1496
1434
|
static VALUE
|
1497
|
-
bdb1_reject(obj)
|
1498
|
-
VALUE obj;
|
1435
|
+
bdb1_reject(VALUE obj)
|
1499
1436
|
{
|
1500
1437
|
return rb_hash_delete_if(bdb1_to_hash(obj));
|
1501
1438
|
}
|
1502
1439
|
|
1503
1440
|
static VALUE
|
1504
|
-
bdb1_values(obj)
|
1505
|
-
VALUE obj;
|
1441
|
+
bdb1_values(VALUE obj)
|
1506
1442
|
{
|
1507
1443
|
bdb1_DB *dbst;
|
1508
1444
|
DBT key, data;
|
@@ -1528,9 +1464,7 @@ bdb1_values(obj)
|
|
1528
1464
|
}
|
1529
1465
|
|
1530
1466
|
VALUE
|
1531
|
-
bdb1_internal_value(obj, a, b, sens)
|
1532
|
-
VALUE obj, a, b;
|
1533
|
-
int sens;
|
1467
|
+
bdb1_internal_value(VALUE obj, VALUE a, VALUE b, int sens)
|
1534
1468
|
{
|
1535
1469
|
bdb1_DB *dbst;
|
1536
1470
|
DBT key, data;
|
@@ -1541,64 +1475,38 @@ bdb1_internal_value(obj, a, b, sens)
|
|
1541
1475
|
INIT_RECNO(dbst, key, recno);
|
1542
1476
|
DATA_ZERO(data);
|
1543
1477
|
flags = (sens == DB_NEXT)?DB_FIRST:DB_LAST;
|
1544
|
-
|
1478
|
+
for (;;) {
|
1545
1479
|
ret = bdb1_test_error(dbst->dbp->seq(dbst->dbp, &key, &data, flags));
|
1546
1480
|
if (ret == DB_NOTFOUND) {
|
1547
|
-
return (b
|
1481
|
+
return RTEST(b) ? Qnil : Qfalse;
|
1548
1482
|
}
|
1549
1483
|
flags = sens;
|
1550
|
-
if (rb_equal(a, bdb1_test_load(obj, &data, FILTER_VALUE))
|
1484
|
+
if (RTEST(rb_equal(a, bdb1_test_load(obj, &data, FILTER_VALUE)))) {
|
1551
1485
|
VALUE d;
|
1552
1486
|
|
1553
|
-
d = (b
|
1487
|
+
d = RTEST(b) ? test_load_key(obj, &key) : Qtrue;
|
1554
1488
|
FREE_KEY(dbst, key);
|
1555
1489
|
return d;
|
1556
1490
|
}
|
1557
1491
|
FREE_KEY(dbst, key);
|
1558
|
-
}
|
1559
|
-
return (b
|
1492
|
+
}
|
1493
|
+
return RTEST(b) ? Qnil : Qfalse;
|
1560
1494
|
}
|
1561
1495
|
|
1562
1496
|
VALUE
|
1563
|
-
|
1564
|
-
VALUE obj, a;
|
1497
|
+
bdb1_key(VALUE obj, VALUE a)
|
1565
1498
|
{
|
1566
1499
|
return bdb1_internal_value(obj, a, Qtrue, DB_NEXT);
|
1567
1500
|
}
|
1568
1501
|
|
1569
|
-
static VALUE
|
1570
|
-
bdb1_indexes(argc, argv, obj)
|
1571
|
-
int argc;
|
1572
|
-
VALUE obj, *argv;
|
1573
|
-
{
|
1574
|
-
VALUE indexes;
|
1575
|
-
int i;
|
1576
|
-
|
1577
|
-
#if HAVE_RB_ARY_VALUES_AT
|
1578
|
-
rb_warn("BDB1#%s is deprecated; use BDB1#values_at",
|
1579
|
-
#if HAVE_RB_FRAME_THIS_FUNC
|
1580
|
-
rb_id2name(rb_frame_this_func()));
|
1581
|
-
#else
|
1582
|
-
rb_id2name(rb_frame_last_func()));
|
1583
|
-
#endif
|
1584
|
-
#endif
|
1585
|
-
indexes = rb_ary_new2(argc);
|
1586
|
-
for (i = 0; i < argc; i++) {
|
1587
|
-
rb_ary_push(indexes, bdb1_get(1, argv + i, obj));
|
1588
|
-
}
|
1589
|
-
return indexes;
|
1590
|
-
}
|
1591
|
-
|
1592
1502
|
VALUE
|
1593
|
-
bdb1_has_value(obj, a)
|
1594
|
-
VALUE obj, a;
|
1503
|
+
bdb1_has_value(VALUE obj, VALUE a)
|
1595
1504
|
{
|
1596
1505
|
return bdb1_internal_value(obj, a, Qfalse, DB_NEXT);
|
1597
1506
|
}
|
1598
1507
|
|
1599
1508
|
static VALUE
|
1600
|
-
bdb1_keys(obj)
|
1601
|
-
VALUE obj;
|
1509
|
+
bdb1_keys(VALUE obj)
|
1602
1510
|
{
|
1603
1511
|
bdb1_DB *dbst;
|
1604
1512
|
DBT key, data;
|
@@ -1624,8 +1532,7 @@ bdb1_keys(obj)
|
|
1624
1532
|
}
|
1625
1533
|
|
1626
1534
|
static VALUE
|
1627
|
-
bdb1_sync(obj)
|
1628
|
-
VALUE obj;
|
1535
|
+
bdb1_sync(VALUE obj)
|
1629
1536
|
{
|
1630
1537
|
bdb1_DB *dbst;
|
1631
1538
|
|
@@ -1636,12 +1543,8 @@ bdb1_sync(obj)
|
|
1636
1543
|
return Qtrue;
|
1637
1544
|
}
|
1638
1545
|
|
1639
|
-
#if HAVE_RB_ARY_VALUES_AT
|
1640
|
-
|
1641
1546
|
static VALUE
|
1642
|
-
bdb1_values_at(argc, argv, obj)
|
1643
|
-
int argc;
|
1644
|
-
VALUE *argv, obj;
|
1547
|
+
bdb1_values_at(int argc, VALUE *argv, VALUE obj)
|
1645
1548
|
{
|
1646
1549
|
VALUE result = rb_ary_new2(argc);
|
1647
1550
|
long i;
|
@@ -1652,34 +1555,19 @@ bdb1_values_at(argc, argv, obj)
|
|
1652
1555
|
return result;
|
1653
1556
|
}
|
1654
1557
|
|
1655
|
-
#endif
|
1656
|
-
|
1657
|
-
#if HAVE_RB_ARY_SELECT
|
1658
|
-
|
1659
1558
|
static VALUE
|
1660
|
-
bdb1_select(
|
1661
|
-
int argc;
|
1662
|
-
VALUE *argv, obj;
|
1559
|
+
bdb1_select(VALUE obj)
|
1663
1560
|
{
|
1664
1561
|
VALUE result = rb_ary_new();
|
1665
|
-
long i;
|
1666
1562
|
|
1667
1563
|
if (rb_block_given_p()) {
|
1668
|
-
if (argc > 0) {
|
1669
|
-
rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
|
1670
|
-
}
|
1671
1564
|
return bdb1_each_valuec(obj, DB_NEXT, result);
|
1672
1565
|
}
|
1673
|
-
|
1674
|
-
return bdb1_values_at(argc, argv, obj);
|
1566
|
+
rb_raise(rb_eArgError, "block is not given");
|
1675
1567
|
}
|
1676
1568
|
|
1677
|
-
#endif
|
1678
|
-
|
1679
1569
|
VALUE
|
1680
|
-
bdb1_each_vc(obj, replace, rtest)
|
1681
|
-
VALUE obj;
|
1682
|
-
int replace, rtest;
|
1570
|
+
bdb1_each_vc(VALUE obj, int replace, int rtest)
|
1683
1571
|
{
|
1684
1572
|
bdb1_DB *dbst;
|
1685
1573
|
DBT key, data;
|
@@ -1709,7 +1597,7 @@ bdb1_each_vc(obj, replace, rtest)
|
|
1709
1597
|
else {
|
1710
1598
|
rb_ary_push(result, res);
|
1711
1599
|
}
|
1712
|
-
if (replace
|
1600
|
+
if (RTEST(replace)) {
|
1713
1601
|
DATA_ZERO(data);
|
1714
1602
|
res = test_dump(obj, &data, res, FILTER_VALUE);
|
1715
1603
|
bdb1_test_error(dbst->dbp->put(dbst->dbp, &key, &data, 0));
|
@@ -1749,7 +1637,7 @@ bdb1_each_vc(obj, replace, rtest)
|
|
1749
1637
|
*
|
1750
1638
|
*/
|
1751
1639
|
void
|
1752
|
-
Init_bdb1()
|
1640
|
+
Init_bdb1(void)
|
1753
1641
|
{
|
1754
1642
|
bdb1_mMarshal = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
1755
1643
|
id_dump = rb_intern("dump");
|
@@ -1789,11 +1677,7 @@ Init_bdb1()
|
|
1789
1677
|
bdb1_cCommon = rb_define_class_under(bdb1_mDb, "Common", rb_cObject);
|
1790
1678
|
rb_define_method(bdb1_cCommon, "initialize", bdb1_init, -1);
|
1791
1679
|
rb_include_module(bdb1_cCommon, rb_mEnumerable);
|
1792
|
-
#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
|
1793
1680
|
rb_define_alloc_func(bdb1_cCommon, bdb1_s_alloc);
|
1794
|
-
#else
|
1795
|
-
rb_define_singleton_method(bdb1_cCommon, "allocate", bdb1_s_alloc, 0);
|
1796
|
-
#endif
|
1797
1681
|
rb_define_singleton_method(bdb1_cCommon, "create", bdb1_s_create, -1);
|
1798
1682
|
rb_define_singleton_method(bdb1_cCommon, "open", bdb1_s_open, -1);
|
1799
1683
|
rb_define_singleton_method(bdb1_cCommon, "[]", bdb1_s_aref, -1);
|
@@ -1841,15 +1725,10 @@ Init_bdb1()
|
|
1841
1725
|
rb_define_method(bdb1_cCommon, "empty?", bdb1_empty, 0);
|
1842
1726
|
rb_define_method(bdb1_cCommon, "length", bdb1_length, 0);
|
1843
1727
|
rb_define_alias(bdb1_cCommon, "size", "length");
|
1844
|
-
rb_define_method(bdb1_cCommon, "
|
1845
|
-
rb_define_method(bdb1_cCommon, "
|
1846
|
-
rb_define_method(bdb1_cCommon, "
|
1847
|
-
#if HAVE_RB_ARY_SELECT
|
1848
|
-
rb_define_method(bdb1_cCommon, "select", bdb1_select, -1);
|
1849
|
-
#endif
|
1850
|
-
#if HAVE_RB_ARY_VALUES_AT
|
1728
|
+
rb_define_method(bdb1_cCommon, "key", bdb1_key, 1);
|
1729
|
+
rb_define_method(bdb1_cCommon, "index", bdb1_key, 1);
|
1730
|
+
rb_define_method(bdb1_cCommon, "select", bdb1_select, 0);
|
1851
1731
|
rb_define_method(bdb1_cCommon, "values_at", bdb1_values_at, -1);
|
1852
|
-
#endif
|
1853
1732
|
bdb1_cBtree = rb_define_class_under(bdb1_mDb, "Btree", bdb1_cCommon);
|
1854
1733
|
rb_define_method(bdb1_cBtree, "duplicates", bdb1_bt_duplicates, -1);
|
1855
1734
|
rb_define_method(bdb1_cBtree, "each_dup", bdb1_bt_dup, 1);
|