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/ext/bdb1/bdb1.h
CHANGED
@@ -1,29 +1,5 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
|
3
|
-
#ifndef StringValue
|
4
|
-
#define StringValue(x,y) do { \
|
5
|
-
if (TYPE(x) != T_STRING) x = rb_str_to_str(x); \
|
6
|
-
} while(0)
|
7
|
-
#endif
|
8
|
-
|
9
|
-
#ifndef StringValuePtr
|
10
|
-
#define StringValuePtr(x) STR2CSTR(x)
|
11
|
-
#endif
|
12
|
-
|
13
|
-
#ifndef SafeStringValue
|
14
|
-
#define SafeStringValue(x) Check_SafeStr(x)
|
15
|
-
#endif
|
16
|
-
|
17
|
-
#ifndef RSTRING_PTR
|
18
|
-
# define RSTRING_PTR(x_) RSTRING(x_)->ptr
|
19
|
-
# define RSTRING_LEN(x_) RSTRING(x_)->len
|
20
|
-
#endif
|
21
|
-
|
22
|
-
#ifndef RARRAY_PTR
|
23
|
-
# define RARRAY_PTR(x_) RARRAY(x_)->ptr
|
24
|
-
# define RARRAY_LEN(x_) RARRAY(x_)->len
|
25
|
-
#endif
|
26
|
-
|
27
3
|
#ifdef COMPAT185
|
28
4
|
#include <db_185.h>
|
29
5
|
#else
|
@@ -140,12 +116,12 @@ extern VALUE bdb1_init _((int, VALUE *, VALUE));
|
|
140
116
|
extern VALUE bdb1_put _((int, VALUE *, VALUE));
|
141
117
|
extern VALUE bdb1_get _((int, VALUE *, VALUE));
|
142
118
|
extern VALUE bdb1_del _((VALUE, VALUE));
|
143
|
-
extern VALUE bdb1_test_load _((VALUE, DBT *, int));
|
119
|
+
extern VALUE bdb1_test_load _((VALUE, const DBT *, int));
|
144
120
|
extern int bdb1_test_error _((int));
|
145
121
|
extern VALUE bdb1_each_value _((VALUE));
|
146
122
|
extern VALUE bdb1_each_eulav _((VALUE));
|
147
123
|
extern VALUE bdb1_each_key _((VALUE));
|
148
|
-
extern VALUE
|
124
|
+
extern VALUE bdb1_key _((VALUE, VALUE));
|
149
125
|
extern VALUE bdb1_has_value _((VALUE, VALUE));
|
150
126
|
extern VALUE bdb1_internal_value _((VALUE, VALUE, VALUE, int));
|
151
127
|
extern VALUE bdb1_to_type _((VALUE, VALUE, VALUE));
|
data/ext/bdb1/delegate.c
CHANGED
@@ -4,15 +4,13 @@ static ID id_send;
|
|
4
4
|
VALUE bdb1_cDelegate;
|
5
5
|
|
6
6
|
void
|
7
|
-
bdb1_deleg_free(delegst)
|
8
|
-
struct deleg_class *delegst;
|
7
|
+
bdb1_deleg_free(struct deleg_class *delegst)
|
9
8
|
{
|
10
9
|
free(delegst);
|
11
10
|
}
|
12
11
|
|
13
12
|
void
|
14
|
-
bdb1_deleg_mark(delegst)
|
15
|
-
struct deleg_class *delegst;
|
13
|
+
bdb1_deleg_mark(struct deleg_class *delegst)
|
16
14
|
{
|
17
15
|
bdb1_DB *dbst;
|
18
16
|
|
@@ -26,28 +24,8 @@ bdb1_deleg_mark(delegst)
|
|
26
24
|
if (delegst->obj) rb_gc_mark(delegst->obj);
|
27
25
|
}
|
28
26
|
|
29
|
-
#ifndef HAVE_RB_BLOCK_CALL
|
30
|
-
|
31
|
-
static VALUE
|
32
|
-
bdb1_deleg_each(tmp)
|
33
|
-
VALUE *tmp;
|
34
|
-
{
|
35
|
-
return rb_funcall2(tmp[0], id_send, (int)tmp[1], (VALUE *)tmp[2]);
|
36
|
-
}
|
37
|
-
|
38
27
|
static VALUE
|
39
|
-
|
40
|
-
VALUE i, res;
|
41
|
-
{
|
42
|
-
return rb_ary_push(res, rb_yield(i));
|
43
|
-
}
|
44
|
-
|
45
|
-
#endif
|
46
|
-
|
47
|
-
static VALUE
|
48
|
-
bdb1_deleg_missing(argc, argv, obj)
|
49
|
-
int argc;
|
50
|
-
VALUE *argv, obj;
|
28
|
+
bdb1_deleg_missing(int argc, VALUE *argv, VALUE obj)
|
51
29
|
{
|
52
30
|
struct deleg_class *delegst, *newst;
|
53
31
|
bdb1_DB *dbst;
|
@@ -55,17 +33,7 @@ bdb1_deleg_missing(argc, argv, obj)
|
|
55
33
|
|
56
34
|
Data_Get_Struct(obj, struct deleg_class, delegst);
|
57
35
|
if (rb_block_given_p()) {
|
58
|
-
#if HAVE_RB_BLOCK_CALL
|
59
36
|
res = rb_block_call(delegst->obj, id_send, argc, argv, rb_yield, 0);
|
60
|
-
#else
|
61
|
-
VALUE tmp[3];
|
62
|
-
|
63
|
-
tmp[0] = delegst->obj;
|
64
|
-
tmp[1] = (VALUE)argc;
|
65
|
-
tmp[2] = (VALUE)argv;
|
66
|
-
res = rb_ary_new();
|
67
|
-
rb_iterate(bdb1_deleg_each, (VALUE)tmp, bdb1_deleg_yield, res);
|
68
|
-
#endif
|
69
37
|
}
|
70
38
|
else {
|
71
39
|
res = rb_funcall2(delegst->obj, id_send, argc, argv);
|
@@ -99,29 +67,27 @@ bdb1_deleg_missing(argc, argv, obj)
|
|
99
67
|
return res;
|
100
68
|
}
|
101
69
|
|
102
|
-
#define DELEG_0(
|
103
|
-
VALUE obj; \
|
70
|
+
#define DELEG_0(meth) \
|
104
71
|
{ \
|
105
72
|
struct deleg_class *delegst; \
|
106
73
|
Data_Get_Struct(obj, struct deleg_class, delegst); \
|
107
|
-
return rb_funcall2(delegst->obj,
|
74
|
+
return rb_funcall2(delegst->obj, rb_intern(meth), 0, 0); \
|
108
75
|
}
|
109
76
|
|
110
|
-
static VALUE bdb1_deleg_inspect(obj) DELEG_0(
|
111
|
-
static VALUE bdb1_deleg_to_s(obj) DELEG_0(
|
112
|
-
static VALUE bdb1_deleg_to_str(obj) DELEG_0(
|
113
|
-
static VALUE bdb1_deleg_to_a(obj)
|
114
|
-
static VALUE bdb1_deleg_to_ary(obj) DELEG_0(
|
115
|
-
static VALUE bdb1_deleg_to_i(obj)
|
116
|
-
static VALUE bdb1_deleg_to_int(obj) DELEG_0(
|
117
|
-
static VALUE bdb1_deleg_to_f(obj)
|
118
|
-
static VALUE bdb1_deleg_to_hash(obj) DELEG_0(
|
119
|
-
static VALUE bdb1_deleg_to_io(obj) DELEG_0(
|
120
|
-
static VALUE bdb1_deleg_to_proc(obj) DELEG_0(
|
77
|
+
static VALUE bdb1_deleg_inspect(VALUE obj) DELEG_0("inspect")
|
78
|
+
static VALUE bdb1_deleg_to_s(VALUE obj) DELEG_0("to_s")
|
79
|
+
static VALUE bdb1_deleg_to_str(VALUE obj) DELEG_0("to_str")
|
80
|
+
static VALUE bdb1_deleg_to_a(VALUE obj) DELEG_0("to_a")
|
81
|
+
static VALUE bdb1_deleg_to_ary(VALUE obj) DELEG_0("to_ary")
|
82
|
+
static VALUE bdb1_deleg_to_i(VALUE obj) DELEG_0("to_i")
|
83
|
+
static VALUE bdb1_deleg_to_int(VALUE obj) DELEG_0("to_int")
|
84
|
+
static VALUE bdb1_deleg_to_f(VALUE obj) DELEG_0("to_f")
|
85
|
+
static VALUE bdb1_deleg_to_hash(VALUE obj) DELEG_0("to_hash")
|
86
|
+
static VALUE bdb1_deleg_to_io(VALUE obj) DELEG_0("to_io")
|
87
|
+
static VALUE bdb1_deleg_to_proc(VALUE obj) DELEG_0("to_proc")
|
121
88
|
|
122
89
|
VALUE
|
123
|
-
bdb1_deleg_to_orig(obj)
|
124
|
-
VALUE obj;
|
90
|
+
bdb1_deleg_to_orig(VALUE obj)
|
125
91
|
{
|
126
92
|
struct deleg_class *delegst;
|
127
93
|
Data_Get_Struct(obj, struct deleg_class, delegst);
|
@@ -129,15 +95,13 @@ bdb1_deleg_to_orig(obj)
|
|
129
95
|
}
|
130
96
|
|
131
97
|
static VALUE
|
132
|
-
bdb1_deleg_orig(obj)
|
133
|
-
VALUE obj;
|
98
|
+
bdb1_deleg_orig(VALUE obj)
|
134
99
|
{
|
135
100
|
return obj;
|
136
101
|
}
|
137
102
|
|
138
103
|
static VALUE
|
139
|
-
bdb1_deleg_dump(obj, limit)
|
140
|
-
VALUE obj, limit;
|
104
|
+
bdb1_deleg_dump(VALUE obj, VALUE limit)
|
141
105
|
{
|
142
106
|
struct deleg_class *delegst;
|
143
107
|
bdb1_DB *dbst;
|
@@ -147,33 +111,49 @@ bdb1_deleg_dump(obj, limit)
|
|
147
111
|
}
|
148
112
|
|
149
113
|
static VALUE
|
150
|
-
bdb1_deleg_load(obj, str)
|
151
|
-
VALUE obj, str;
|
114
|
+
bdb1_deleg_load(VALUE obj, VALUE str)
|
152
115
|
{
|
153
116
|
bdb1_DB *dbst;
|
154
117
|
|
155
|
-
if ((obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))
|
118
|
+
if (NIL_P(obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))) {
|
156
119
|
rb_raise(bdb1_eFatal, "BUG : current_db not set");
|
157
120
|
}
|
158
121
|
Data_Get_Struct(obj, bdb1_DB, dbst);
|
159
122
|
return rb_funcall(dbst->marshal, rb_intern("load"), 1, str);
|
160
123
|
}
|
161
124
|
|
162
|
-
void
|
125
|
+
void
|
126
|
+
bdb1_init_delegator(void)
|
163
127
|
{
|
164
128
|
id_send = rb_intern("send");
|
165
129
|
bdb1_cDelegate = rb_define_class_under(bdb1_mDb, "Delegate", rb_cObject);
|
166
130
|
{
|
167
131
|
VALUE ary, tmp = Qfalse;
|
168
|
-
char *method;
|
169
132
|
int i;
|
133
|
+
ID id_eq = rb_intern("=="),
|
134
|
+
id_eqq = rb_intern("==="),
|
135
|
+
id_match = rb_intern("=~"),
|
136
|
+
id_not = rb_intern("!"),
|
137
|
+
id_neq = rb_intern("!="),
|
138
|
+
id_notmatch = rb_intern("!~");
|
170
139
|
|
171
140
|
ary = rb_class_instance_methods(1, &tmp, rb_mKernel);
|
172
141
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
173
|
-
method =
|
174
|
-
|
175
|
-
|
176
|
-
|
142
|
+
VALUE method = RARRAY_PTR(ary)[i];
|
143
|
+
VALUE mid;
|
144
|
+
if (!SYMBOL_P(method)) {
|
145
|
+
Check_Type(method, T_STRING);
|
146
|
+
mid = rb_intern(RSTRING_PTR(method));
|
147
|
+
}
|
148
|
+
else
|
149
|
+
mid = SYM2ID(method);
|
150
|
+
if (mid == id_eq ||
|
151
|
+
mid == id_eqq ||
|
152
|
+
mid == id_match ||
|
153
|
+
mid == id_not ||
|
154
|
+
mid == id_neq ||
|
155
|
+
mid == id_notmatch) continue;
|
156
|
+
rb_undef_method(bdb1_cDelegate, rb_id2name(mid));
|
177
157
|
}
|
178
158
|
}
|
179
159
|
rb_define_method(bdb1_cDelegate, "method_missing", bdb1_deleg_missing, -1);
|
data/ext/bdb1/extconf.rb
CHANGED
@@ -12,22 +12,4 @@ if enable_config("shared", true)
|
|
12
12
|
$static = nil
|
13
13
|
end
|
14
14
|
|
15
|
-
%w[rb_frame_this_func rb_block_call].each do |f|
|
16
|
-
have_func(f)
|
17
|
-
end
|
18
|
-
|
19
|
-
%w[insert values_at map select].each do |f|
|
20
|
-
print "checking for Array\##{f}... "
|
21
|
-
if [].respond_to?(f)
|
22
|
-
puts "yes"
|
23
|
-
$CFLAGS += " -DHAVE_RB_ARY_#{f.upcase}"
|
24
|
-
else
|
25
|
-
puts "no"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
15
|
create_makefile("bdb1")
|
30
|
-
|
31
|
-
File.open("Makefile", "a") { |make|
|
32
|
-
make.puts "test: $(DLLIB)"
|
33
|
-
}
|
data/ext/bdb1/recnum.c
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
static ID id_cmp;
|
4
4
|
|
5
5
|
static VALUE
|
6
|
-
bdb1_recnum_init(argc, argv, obj)
|
7
|
-
int argc;
|
8
|
-
VALUE *argv, obj;
|
6
|
+
bdb1_recnum_init(int argc, VALUE *argv, VALUE obj)
|
9
7
|
{
|
10
8
|
VALUE *nargv;
|
11
9
|
VALUE array = rb_str_new2("array_base");
|
@@ -26,9 +24,7 @@ bdb1_recnum_init(argc, argv, obj)
|
|
26
24
|
}
|
27
25
|
|
28
26
|
static VALUE
|
29
|
-
bdb1_sary_subseq(obj, beg, len)
|
30
|
-
VALUE obj;
|
31
|
-
long beg, len;
|
27
|
+
bdb1_sary_subseq(VALUE obj, long beg, long len)
|
32
28
|
{
|
33
29
|
VALUE ary2, a;
|
34
30
|
bdb1_DB *dbst;
|
@@ -52,8 +48,7 @@ bdb1_sary_subseq(obj, beg, len)
|
|
52
48
|
}
|
53
49
|
|
54
50
|
static VALUE
|
55
|
-
bdb1_sary_entry(obj, position)
|
56
|
-
VALUE obj, position;
|
51
|
+
bdb1_sary_entry(VALUE obj, VALUE position)
|
57
52
|
{
|
58
53
|
bdb1_DB *dbst;
|
59
54
|
long offset;
|
@@ -81,7 +76,7 @@ bdb1_sary_entry(obj, position)
|
|
81
76
|
* Retrieves the +nth+ item from an array. Index starts from zero.
|
82
77
|
* If index is the negative, counts backward from the end of the
|
83
78
|
* array. The index of the last element is -1. Returns +nil+, if
|
84
|
-
* the +nth+ element
|
79
|
+
* the +nth+ element does not exist in the array.
|
85
80
|
*
|
86
81
|
* * db[start..end]
|
87
82
|
* Returns an array containing the objects from +start+ to +end+,
|
@@ -89,15 +84,13 @@ bdb1_sary_entry(obj, position)
|
|
89
84
|
* array, it will be rounded to the length. If +start+ is out of an
|
90
85
|
* array range , returns +nil+. And if +start+ is larger than end
|
91
86
|
* with in array range, returns empty array ([]).
|
92
|
-
|
87
|
+
*
|
93
88
|
* * db[start, length]
|
94
89
|
* Returns an array containing +length+ items from +start+. Returns
|
95
90
|
* +nil+ if +length+ is negative.
|
96
91
|
*/
|
97
92
|
static VALUE
|
98
|
-
bdb1_sary_aref(argc, argv, obj)
|
99
|
-
int argc;
|
100
|
-
VALUE *argv, obj;
|
93
|
+
bdb1_sary_aref(int argc, VALUE *argv, VALUE obj)
|
101
94
|
{
|
102
95
|
VALUE arg1, arg2;
|
103
96
|
long beg, len;
|
@@ -133,9 +126,7 @@ bdb1_sary_aref(argc, argv, obj)
|
|
133
126
|
}
|
134
127
|
|
135
128
|
static VALUE
|
136
|
-
bdb1_intern_shift_pop(obj, depart, len)
|
137
|
-
VALUE obj;
|
138
|
-
int depart, len;
|
129
|
+
bdb1_intern_shift_pop(VALUE obj, int depart, int len)
|
139
130
|
{
|
140
131
|
bdb1_DB *dbst;
|
141
132
|
DBT key, data;
|
@@ -161,9 +152,7 @@ bdb1_intern_shift_pop(obj, depart, len)
|
|
161
152
|
}
|
162
153
|
|
163
154
|
static void
|
164
|
-
bdb1_sary_replace(obj, beg, len, rpl)
|
165
|
-
VALUE obj, rpl;
|
166
|
-
long beg, len;
|
155
|
+
bdb1_sary_replace(VALUE obj, long beg, long len, VALUE rpl)
|
167
156
|
{
|
168
157
|
long i, j, rlen;
|
169
158
|
VALUE tmp[2];
|
@@ -240,26 +229,23 @@ bdb1_sary_replace(obj, beg, len, rpl)
|
|
240
229
|
*
|
241
230
|
* Element assignment - with the following syntax:
|
242
231
|
*
|
243
|
-
* * db[nth]
|
232
|
+
* * db[nth] = val
|
244
233
|
* Changes the +nth+ element of the array into +val+. If +nth+ is
|
245
234
|
* larger than array length, the array shall be extended
|
246
235
|
* automatically. Extended region shall be initialized by +nil+.
|
247
236
|
*
|
248
|
-
* * db[start..end]
|
237
|
+
* * db[start..end] = val
|
249
238
|
* Replaces the items from +start+ to +end+ with +val+. If +val+ is
|
250
239
|
* not an array, the type of +val+ will be converted into the Array
|
251
240
|
* using +to_a+ method.
|
252
241
|
*
|
253
|
-
* * db[start, length]
|
242
|
+
* * db[start, length] = val
|
254
243
|
* Replaces the +length+ items from +start+ with +val+. If +val+ is
|
255
244
|
* not an array, the type of +val+ will be converted into the Array
|
256
245
|
* using +to_a+.
|
257
246
|
*/
|
258
247
|
static VALUE
|
259
|
-
bdb1_sary_aset(argc, argv, obj)
|
260
|
-
int argc;
|
261
|
-
VALUE *argv;
|
262
|
-
VALUE obj;
|
248
|
+
bdb1_sary_aset(int argc, VALUE *argv, VALUE obj)
|
263
249
|
{
|
264
250
|
long beg, len;
|
265
251
|
bdb1_DB *dbst;
|
@@ -310,13 +296,8 @@ bdb1_sary_aset(argc, argv, obj)
|
|
310
296
|
return argv[1];
|
311
297
|
}
|
312
298
|
|
313
|
-
#if HAVE_RB_ARY_INSERT
|
314
|
-
|
315
299
|
static VALUE
|
316
|
-
bdb1_sary_insert(argc, argv, obj)
|
317
|
-
int argc;
|
318
|
-
VALUE *argv;
|
319
|
-
VALUE obj;
|
300
|
+
bdb1_sary_insert(int argc, VALUE *argv, VALUE obj)
|
320
301
|
{
|
321
302
|
long pos;
|
322
303
|
|
@@ -338,18 +319,14 @@ bdb1_sary_insert(argc, argv, obj)
|
|
338
319
|
return obj;
|
339
320
|
}
|
340
321
|
|
341
|
-
#endif
|
342
|
-
|
343
322
|
static VALUE
|
344
|
-
bdb1_sary_at(obj, pos)
|
345
|
-
VALUE obj, pos;
|
323
|
+
bdb1_sary_at(VALUE obj, VALUE pos)
|
346
324
|
{
|
347
325
|
return bdb1_sary_entry(obj, pos);
|
348
326
|
}
|
349
327
|
|
350
328
|
static VALUE
|
351
|
-
bdb1_sary_first(obj)
|
352
|
-
VALUE obj;
|
329
|
+
bdb1_sary_first(VALUE obj)
|
353
330
|
{
|
354
331
|
bdb1_DB *dbst;
|
355
332
|
VALUE tmp;
|
@@ -360,8 +337,7 @@ bdb1_sary_first(obj)
|
|
360
337
|
}
|
361
338
|
|
362
339
|
static VALUE
|
363
|
-
bdb1_sary_last(obj)
|
364
|
-
VALUE obj;
|
340
|
+
bdb1_sary_last(VALUE obj)
|
365
341
|
{
|
366
342
|
bdb1_DB *dbst;
|
367
343
|
VALUE tmp;
|
@@ -373,9 +349,7 @@ bdb1_sary_last(obj)
|
|
373
349
|
}
|
374
350
|
|
375
351
|
static VALUE
|
376
|
-
bdb1_sary_fetch(argc, argv, obj)
|
377
|
-
int argc;
|
378
|
-
VALUE *argv, obj;
|
352
|
+
bdb1_sary_fetch(int argc, VALUE *argv, VALUE obj)
|
379
353
|
{
|
380
354
|
VALUE pos, ifnone;
|
381
355
|
bdb1_DB *dbst;
|
@@ -397,8 +371,7 @@ bdb1_sary_fetch(argc, argv, obj)
|
|
397
371
|
|
398
372
|
|
399
373
|
static VALUE
|
400
|
-
bdb1_sary_concat(obj, y)
|
401
|
-
VALUE obj, y;
|
374
|
+
bdb1_sary_concat(VALUE obj, VALUE y)
|
402
375
|
{
|
403
376
|
bdb1_DB *dbst;
|
404
377
|
long i;
|
@@ -416,8 +389,7 @@ bdb1_sary_concat(obj, y)
|
|
416
389
|
}
|
417
390
|
|
418
391
|
static VALUE
|
419
|
-
bdb1_sary_push(obj, y)
|
420
|
-
VALUE obj, y;
|
392
|
+
bdb1_sary_push(VALUE obj, VALUE y)
|
421
393
|
{
|
422
394
|
bdb1_DB *dbst;
|
423
395
|
VALUE tmp[2];
|
@@ -431,9 +403,7 @@ bdb1_sary_push(obj, y)
|
|
431
403
|
}
|
432
404
|
|
433
405
|
static VALUE
|
434
|
-
bdb1_sary_push_m(argc, argv, obj)
|
435
|
-
int argc;
|
436
|
-
VALUE obj, *argv;
|
406
|
+
bdb1_sary_push_m(int argc, VALUE *argv, VALUE obj)
|
437
407
|
{
|
438
408
|
bdb1_DB *dbst;
|
439
409
|
long i;
|
@@ -455,10 +425,7 @@ bdb1_sary_push_m(argc, argv, obj)
|
|
455
425
|
}
|
456
426
|
|
457
427
|
static VALUE
|
458
|
-
bdb1_sary_s_create(argc, argv, obj)
|
459
|
-
int argc;
|
460
|
-
VALUE *argv;
|
461
|
-
VALUE obj;
|
428
|
+
bdb1_sary_s_create(int argc, VALUE *argv, VALUE obj)
|
462
429
|
{
|
463
430
|
VALUE res;
|
464
431
|
int i;
|
@@ -474,8 +441,7 @@ bdb1_sary_s_create(argc, argv, obj)
|
|
474
441
|
}
|
475
442
|
|
476
443
|
static VALUE
|
477
|
-
bdb1_sary_shift(obj)
|
478
|
-
VALUE obj;
|
444
|
+
bdb1_sary_shift(VALUE obj)
|
479
445
|
{
|
480
446
|
VALUE res;
|
481
447
|
bdb1_DB *dbst;
|
@@ -487,8 +453,7 @@ bdb1_sary_shift(obj)
|
|
487
453
|
}
|
488
454
|
|
489
455
|
static VALUE
|
490
|
-
bdb1_sary_pop(obj)
|
491
|
-
VALUE obj;
|
456
|
+
bdb1_sary_pop(VALUE obj)
|
492
457
|
{
|
493
458
|
VALUE res;
|
494
459
|
bdb1_DB *dbst;
|
@@ -500,10 +465,7 @@ bdb1_sary_pop(obj)
|
|
500
465
|
}
|
501
466
|
|
502
467
|
static VALUE
|
503
|
-
bdb1_sary_unshift_m(argc, argv, obj)
|
504
|
-
int argc;
|
505
|
-
VALUE *argv;
|
506
|
-
VALUE obj;
|
468
|
+
bdb1_sary_unshift_m(int argc, VALUE *argv, VALUE obj)
|
507
469
|
{
|
508
470
|
bdb1_DB *dbst;
|
509
471
|
VALUE tmp[3];
|
@@ -526,8 +488,7 @@ bdb1_sary_unshift_m(argc, argv, obj)
|
|
526
488
|
}
|
527
489
|
|
528
490
|
static VALUE
|
529
|
-
bdb1_sary_length(obj)
|
530
|
-
VALUE obj;
|
491
|
+
bdb1_sary_length(VALUE obj)
|
531
492
|
{
|
532
493
|
bdb1_DB *dbst;
|
533
494
|
|
@@ -537,40 +498,35 @@ bdb1_sary_length(obj)
|
|
537
498
|
}
|
538
499
|
|
539
500
|
static VALUE
|
540
|
-
bdb1_sary_empty_p(obj)
|
541
|
-
VALUE obj;
|
501
|
+
bdb1_sary_empty_p(VALUE obj)
|
542
502
|
{
|
543
503
|
bdb1_DB *dbst;
|
544
504
|
|
545
505
|
GetDB(obj, dbst);
|
546
506
|
if (dbst->len < 0) rb_raise(bdb1_eFatal, "Invalid BDB::Recnum");
|
547
|
-
return
|
507
|
+
return dbst->len == 0 ? Qtrue : Qfalse;
|
548
508
|
}
|
549
509
|
|
550
510
|
static VALUE
|
551
|
-
bdb1_sary_rindex(obj, a)
|
552
|
-
VALUE obj, a;
|
511
|
+
bdb1_sary_rindex(VALUE obj, VALUE a)
|
553
512
|
{
|
554
513
|
return bdb1_internal_value(obj, a, Qtrue, DB_PREV);
|
555
514
|
}
|
556
515
|
|
557
516
|
static VALUE
|
558
|
-
bdb1_sary_to_a(obj)
|
559
|
-
VALUE obj;
|
517
|
+
bdb1_sary_to_a(VALUE obj)
|
560
518
|
{
|
561
519
|
return bdb1_to_type(obj, rb_ary_new(), Qfalse);
|
562
520
|
}
|
563
521
|
|
564
522
|
static VALUE
|
565
|
-
bdb1_sary_reverse_m(obj)
|
566
|
-
VALUE obj;
|
523
|
+
bdb1_sary_reverse_m(VALUE obj)
|
567
524
|
{
|
568
525
|
return bdb1_to_type(obj, rb_ary_new(), Qnil);
|
569
526
|
}
|
570
527
|
|
571
528
|
static VALUE
|
572
|
-
bdb1_sary_reverse_bang(obj)
|
573
|
-
VALUE obj;
|
529
|
+
bdb1_sary_reverse_bang(VALUE obj)
|
574
530
|
{
|
575
531
|
long i, j;
|
576
532
|
bdb1_DB *dbst;
|
@@ -596,15 +552,13 @@ bdb1_sary_reverse_bang(obj)
|
|
596
552
|
}
|
597
553
|
|
598
554
|
static VALUE
|
599
|
-
bdb1_sary_collect_bang(obj)
|
600
|
-
VALUE obj;
|
555
|
+
bdb1_sary_collect_bang(VALUE obj)
|
601
556
|
{
|
602
557
|
return bdb1_each_vc(obj, Qtrue, Qfalse);
|
603
558
|
}
|
604
559
|
|
605
560
|
static VALUE
|
606
|
-
bdb1_sary_collect(obj)
|
607
|
-
VALUE obj;
|
561
|
+
bdb1_sary_collect(VALUE obj)
|
608
562
|
{
|
609
563
|
if (!rb_block_given_p()) {
|
610
564
|
return bdb1_sary_to_a(obj);
|
@@ -613,9 +567,7 @@ bdb1_sary_collect(obj)
|
|
613
567
|
}
|
614
568
|
|
615
569
|
static VALUE
|
616
|
-
bdb1_sary_values_at(argc, argv, obj)
|
617
|
-
int argc;
|
618
|
-
VALUE *argv, obj;
|
570
|
+
bdb1_sary_values_at(int argc, VALUE *argv, VALUE obj)
|
619
571
|
{
|
620
572
|
VALUE result;
|
621
573
|
long i;
|
@@ -628,60 +580,23 @@ bdb1_sary_values_at(argc, argv, obj)
|
|
628
580
|
}
|
629
581
|
|
630
582
|
static VALUE
|
631
|
-
bdb1_sary_select(
|
632
|
-
int argc;
|
633
|
-
VALUE *argv, obj;
|
583
|
+
bdb1_sary_select(VALUE obj)
|
634
584
|
{
|
635
|
-
VALUE result;
|
636
|
-
long i;
|
637
|
-
|
638
585
|
if (rb_block_given_p()) {
|
639
|
-
if (argc > 0) {
|
640
|
-
rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
|
641
|
-
}
|
642
586
|
return bdb1_each_vc(obj, Qfalse, Qtrue);
|
643
587
|
}
|
644
|
-
|
645
|
-
rb_warn("Recnum#%s is deprecated; use Recnum#values_at",
|
646
|
-
#if HAVE_RB_FRAME_THIS_FUNC
|
647
|
-
rb_id2name(rb_frame_this_func()));
|
648
|
-
#else
|
649
|
-
rb_id2name(rb_frame_last_func()));
|
650
|
-
#endif
|
651
|
-
#endif
|
652
|
-
return bdb1_sary_values_at(argc, argv, obj);
|
653
|
-
}
|
654
|
-
|
655
|
-
static VALUE
|
656
|
-
bdb1_sary_indexes(argc, argv, obj)
|
657
|
-
int argc;
|
658
|
-
VALUE obj, *argv;
|
659
|
-
{
|
660
|
-
VALUE indexes;
|
661
|
-
int i;
|
662
|
-
|
663
|
-
#if HAVE_RB_ARY_VALUES_AT
|
664
|
-
rb_warn("Recnum#%s is deprecated; use Recnum#values_at",
|
665
|
-
#if HAVE_RB_FRAME_THIS_FUNC
|
666
|
-
rb_id2name(rb_frame_this_func()));
|
667
|
-
#else
|
668
|
-
rb_id2name(rb_frame_last_func()));
|
669
|
-
#endif
|
670
|
-
#endif
|
671
|
-
return bdb1_sary_select(argc, argv, obj);
|
588
|
+
rb_raise(rb_eArgError, "block is not given");
|
672
589
|
}
|
673
590
|
|
674
591
|
static VALUE
|
675
|
-
bdb1_sary_filter(obj)
|
676
|
-
VALUE obj;
|
592
|
+
bdb1_sary_filter(VALUE obj)
|
677
593
|
{
|
678
594
|
rb_warn("BDB1::Recnum#filter is deprecated; use BDB1::Recnum#collect!");
|
679
595
|
return bdb1_sary_collect_bang(obj);
|
680
596
|
}
|
681
597
|
|
682
598
|
static VALUE
|
683
|
-
bdb1_sary_delete(obj, item)
|
684
|
-
VALUE obj, item;
|
599
|
+
bdb1_sary_delete(VALUE obj, VALUE item)
|
685
600
|
{
|
686
601
|
bdb1_DB *dbst;
|
687
602
|
long i1, i2;
|
@@ -710,8 +625,7 @@ bdb1_sary_delete(obj, item)
|
|
710
625
|
}
|
711
626
|
|
712
627
|
static VALUE
|
713
|
-
bdb1_sary_delete_at_m(obj, a)
|
714
|
-
VALUE obj, a;
|
628
|
+
bdb1_sary_delete_at_m(VALUE obj, VALUE a)
|
715
629
|
{
|
716
630
|
bdb1_DB *dbst;
|
717
631
|
long pos;
|
@@ -732,8 +646,7 @@ bdb1_sary_delete_at_m(obj, a)
|
|
732
646
|
}
|
733
647
|
|
734
648
|
static VALUE
|
735
|
-
bdb1_sary_reject_bang(obj)
|
736
|
-
VALUE obj;
|
649
|
+
bdb1_sary_reject_bang(VALUE obj)
|
737
650
|
{
|
738
651
|
bdb1_DB *dbst;
|
739
652
|
long i1, i2;
|
@@ -756,16 +669,14 @@ bdb1_sary_reject_bang(obj)
|
|
756
669
|
}
|
757
670
|
|
758
671
|
static VALUE
|
759
|
-
bdb1_sary_delete_if(obj)
|
760
|
-
VALUE obj;
|
672
|
+
bdb1_sary_delete_if(VALUE obj)
|
761
673
|
{
|
762
674
|
bdb1_sary_reject_bang(obj);
|
763
675
|
return obj;
|
764
676
|
}
|
765
677
|
|
766
678
|
static VALUE
|
767
|
-
bdb1_sary_replace_m(obj, obj2)
|
768
|
-
VALUE obj, obj2;
|
679
|
+
bdb1_sary_replace_m(VALUE obj, VALUE obj2)
|
769
680
|
{
|
770
681
|
bdb1_DB *dbst;
|
771
682
|
|
@@ -776,8 +687,7 @@ bdb1_sary_replace_m(obj, obj2)
|
|
776
687
|
}
|
777
688
|
|
778
689
|
static VALUE
|
779
|
-
bdb1_sary_clear(obj)
|
780
|
-
VALUE obj;
|
690
|
+
bdb1_sary_clear(VALUE obj)
|
781
691
|
{
|
782
692
|
bdb1_DB *dbst;
|
783
693
|
bdb1_clear(obj);
|
@@ -787,10 +697,7 @@ bdb1_sary_clear(obj)
|
|
787
697
|
}
|
788
698
|
|
789
699
|
static VALUE
|
790
|
-
bdb1_sary_fill(argc, argv, obj)
|
791
|
-
int argc;
|
792
|
-
VALUE *argv;
|
793
|
-
VALUE obj;
|
700
|
+
bdb1_sary_fill(int argc, VALUE *argv, VALUE obj)
|
794
701
|
{
|
795
702
|
VALUE item, arg1, arg2, tmp[2];
|
796
703
|
long beg, len, i;
|
@@ -827,11 +734,11 @@ bdb1_sary_fill(argc, argv, obj)
|
|
827
734
|
}
|
828
735
|
|
829
736
|
static VALUE
|
830
|
-
bdb1_sary_cmp(obj, obj2)
|
831
|
-
VALUE obj, obj2;
|
737
|
+
bdb1_sary_cmp(VALUE obj, VALUE obj2)
|
832
738
|
{
|
833
739
|
bdb1_DB *dbst, *dbst2;
|
834
|
-
VALUE a, a2, tmp
|
740
|
+
VALUE a, a2, tmp;
|
741
|
+
int ary;
|
835
742
|
long i, len;
|
836
743
|
|
837
744
|
if (obj == obj2) return INT2FIX(0);
|
@@ -842,14 +749,14 @@ bdb1_sary_cmp(obj, obj2)
|
|
842
749
|
if (len > RARRAY_LEN(obj2)) {
|
843
750
|
len = RARRAY_LEN(obj2);
|
844
751
|
}
|
845
|
-
ary =
|
752
|
+
ary = 1;
|
846
753
|
}
|
847
754
|
else {
|
848
755
|
GetDB(obj2, dbst2);
|
849
756
|
if (len > dbst2->len) {
|
850
757
|
len = dbst2->len;
|
851
758
|
}
|
852
|
-
ary =
|
759
|
+
ary = 0;
|
853
760
|
}
|
854
761
|
for (i = 0; i < len; i++) {
|
855
762
|
tmp = INT2NUM(i);
|
@@ -865,17 +772,14 @@ bdb1_sary_cmp(obj, obj2)
|
|
865
772
|
return tmp;
|
866
773
|
}
|
867
774
|
}
|
868
|
-
len = dbst->len - (ary?RARRAY_LEN(obj2):dbst2->len);
|
775
|
+
len = dbst->len - (ary ? RARRAY_LEN(obj2) : dbst2->len);
|
869
776
|
if (len == 0) return INT2FIX(0);
|
870
777
|
if (len > 0) return INT2FIX(1);
|
871
778
|
return INT2FIX(-1);
|
872
779
|
}
|
873
780
|
|
874
781
|
static VALUE
|
875
|
-
bdb1_sary_slice_bang(argc, argv, obj)
|
876
|
-
int argc;
|
877
|
-
VALUE *argv;
|
878
|
-
VALUE obj;
|
782
|
+
bdb1_sary_slice_bang(int argc, VALUE *argv, VALUE obj)
|
879
783
|
{
|
880
784
|
VALUE arg1, arg2;
|
881
785
|
long pos, len;
|
@@ -910,50 +814,43 @@ bdb1_sary_slice_bang(argc, argv, obj)
|
|
910
814
|
}
|
911
815
|
|
912
816
|
static VALUE
|
913
|
-
bdb1_sary_plus(obj, y)
|
914
|
-
VALUE obj, y;
|
817
|
+
bdb1_sary_plus(VALUE obj, VALUE y)
|
915
818
|
{
|
916
819
|
return rb_ary_plus(bdb1_sary_to_a(obj), y);
|
917
820
|
}
|
918
821
|
|
919
822
|
static VALUE
|
920
|
-
bdb1_sary_times(obj, y)
|
921
|
-
VALUE obj, y;
|
823
|
+
bdb1_sary_times(VALUE obj, VALUE y)
|
922
824
|
{
|
923
825
|
return rb_funcall(bdb1_sary_to_a(obj), rb_intern("*"), 1, y);
|
924
826
|
}
|
925
827
|
|
926
828
|
static VALUE
|
927
|
-
bdb1_sary_diff(obj, y)
|
928
|
-
VALUE obj, y;
|
829
|
+
bdb1_sary_diff(VALUE obj, VALUE y)
|
929
830
|
{
|
930
831
|
return rb_funcall(bdb1_sary_to_a(obj), rb_intern("-"), 1, y);
|
931
832
|
}
|
932
833
|
|
933
834
|
static VALUE
|
934
|
-
bdb1_sary_and(obj, y)
|
935
|
-
VALUE obj, y;
|
835
|
+
bdb1_sary_and(VALUE obj, VALUE y)
|
936
836
|
{
|
937
837
|
return rb_funcall(bdb1_sary_to_a(obj), rb_intern("&"), 1, y);
|
938
838
|
}
|
939
839
|
|
940
840
|
static VALUE
|
941
|
-
bdb1_sary_or(obj, y)
|
942
|
-
VALUE obj, y;
|
841
|
+
bdb1_sary_or(VALUE obj, VALUE y)
|
943
842
|
{
|
944
843
|
return rb_funcall(bdb1_sary_to_a(obj), rb_intern("|"), 1, y);
|
945
844
|
}
|
946
845
|
|
947
846
|
static VALUE
|
948
|
-
bdb1_sary_compact(obj)
|
949
|
-
VALUE obj;
|
847
|
+
bdb1_sary_compact(VALUE obj)
|
950
848
|
{
|
951
849
|
return rb_funcall(bdb1_sary_to_a(obj), rb_intern("compact"), 0, 0);
|
952
850
|
}
|
953
851
|
|
954
852
|
static VALUE
|
955
|
-
bdb1_sary_compact_bang(obj)
|
956
|
-
VALUE obj;
|
853
|
+
bdb1_sary_compact_bang(VALUE obj)
|
957
854
|
{
|
958
855
|
bdb1_DB *dbst;
|
959
856
|
long i, j;
|
@@ -977,8 +874,7 @@ bdb1_sary_compact_bang(obj)
|
|
977
874
|
}
|
978
875
|
|
979
876
|
static VALUE
|
980
|
-
bdb1_sary_nitems(obj)
|
981
|
-
VALUE obj;
|
877
|
+
bdb1_sary_nitems(VALUE obj)
|
982
878
|
{
|
983
879
|
bdb1_DB *dbst;
|
984
880
|
long i, j;
|
@@ -995,8 +891,7 @@ bdb1_sary_nitems(obj)
|
|
995
891
|
}
|
996
892
|
|
997
893
|
static VALUE
|
998
|
-
bdb1_sary_each_index(obj)
|
999
|
-
VALUE obj;
|
894
|
+
bdb1_sary_each_index(VALUE obj)
|
1000
895
|
{
|
1001
896
|
bdb1_DB *dbst;
|
1002
897
|
long i;
|
@@ -1008,7 +903,8 @@ bdb1_sary_each_index(obj)
|
|
1008
903
|
return obj;
|
1009
904
|
}
|
1010
905
|
|
1011
|
-
void
|
906
|
+
void
|
907
|
+
bdb1_init_recnum(void)
|
1012
908
|
{
|
1013
909
|
id_cmp = rb_intern("<=>");
|
1014
910
|
bdb1_cRecnum = rb_define_class_under(bdb1_mDb, "Recnum", bdb1_cCommon);
|
@@ -1027,32 +923,23 @@ void bdb1_init_recnum()
|
|
1027
923
|
rb_define_method(bdb1_cRecnum, "pop", bdb1_sary_pop, 0);
|
1028
924
|
rb_define_method(bdb1_cRecnum, "shift", bdb1_sary_shift, 0);
|
1029
925
|
rb_define_method(bdb1_cRecnum, "unshift", bdb1_sary_unshift_m, -1);
|
1030
|
-
#if HAVE_RB_ARY_INSERT
|
1031
926
|
rb_define_method(bdb1_cRecnum, "insert", bdb1_sary_insert, -1);
|
1032
|
-
#endif
|
1033
927
|
rb_define_method(bdb1_cRecnum, "each", bdb1_each_value, 0);
|
1034
928
|
rb_define_method(bdb1_cRecnum, "each_index", bdb1_sary_each_index, 0);
|
1035
929
|
rb_define_method(bdb1_cRecnum, "reverse_each", bdb1_each_eulav, 0);
|
1036
930
|
rb_define_method(bdb1_cRecnum, "length", bdb1_sary_length, 0);
|
1037
931
|
rb_define_alias(bdb1_cRecnum, "size", "length");
|
1038
932
|
rb_define_method(bdb1_cRecnum, "empty?", bdb1_sary_empty_p, 0);
|
1039
|
-
rb_define_method(bdb1_cRecnum, "
|
933
|
+
rb_define_method(bdb1_cRecnum, "key", bdb1_key, 1);
|
934
|
+
rb_define_method(bdb1_cRecnum, "index", bdb1_key, 1);
|
1040
935
|
rb_define_method(bdb1_cRecnum, "rindex", bdb1_sary_rindex, 1);
|
1041
|
-
rb_define_method(bdb1_cRecnum, "indexes", bdb1_sary_indexes, -1);
|
1042
|
-
rb_define_method(bdb1_cRecnum, "indices", bdb1_sary_indexes, -1);
|
1043
936
|
rb_define_method(bdb1_cRecnum, "reverse", bdb1_sary_reverse_m, 0);
|
1044
937
|
rb_define_method(bdb1_cRecnum, "reverse!", bdb1_sary_reverse_bang, 0);
|
1045
938
|
rb_define_method(bdb1_cRecnum, "collect", bdb1_sary_collect, 0);
|
1046
939
|
rb_define_method(bdb1_cRecnum, "collect!", bdb1_sary_collect_bang, 0);
|
1047
|
-
#if HAVE_RB_ARY_MAP
|
1048
940
|
rb_define_method(bdb1_cRecnum, "map", bdb1_sary_collect, 0);
|
1049
|
-
#endif
|
1050
|
-
#if HAVE_RB_ARY_VALUES_AT
|
1051
941
|
rb_define_method(bdb1_cRecnum, "values_at", bdb1_sary_values_at, -1);
|
1052
|
-
|
1053
|
-
#if HAVE_RB_ARY_SELECT
|
1054
|
-
rb_define_method(bdb1_cRecnum, "select", bdb1_sary_select, -1);
|
1055
|
-
#endif
|
942
|
+
rb_define_method(bdb1_cRecnum, "select", bdb1_sary_select, 0);
|
1056
943
|
rb_define_method(bdb1_cRecnum, "map!", bdb1_sary_collect_bang, 0);
|
1057
944
|
rb_define_method(bdb1_cRecnum, "filter", bdb1_sary_filter, 0);
|
1058
945
|
rb_define_method(bdb1_cRecnum, "delete", bdb1_sary_delete, 1);
|