Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

dbm.c
Go to the documentation of this file.
1 /************************************************
2
3 dbm.c -
4
5 $Author: nobu $
6 created at: Mon Jan 24 15:59:52 JST 1994
7
8 Copyright (C) 1995-2001 Yukihiro Matsumoto
9
10 ************************************************/
11
12 #include "ruby.h"
13
14 #ifdef HAVE_CDEFS_H
15 # include <cdefs.h>
16 #endif
17 #ifdef HAVE_SYS_CDEFS_H
18 # include <sys/cdefs.h>
19 #endif
20 #include DBM_HDR
21 #include <fcntl.h>
22 #include <errno.h>
23
24 #define DSIZE_TYPE TYPEOF_DATUM_DSIZE
25 #if SIZEOF_DATUM_DSIZE > SIZEOF_INT
26 # define RSTRING_DSIZE(s) RSTRING_LEN(s)
27 # define TOO_LONG(n) 0
28 #else
29 # define RSTRING_DSIZE(s) RSTRING_LENINT(s)
30 # define TOO_LONG(n) ((long)(+(DSIZE_TYPE)(n)) != (n))
31 #endif
32
33 static VALUE rb_cDBM, rb_eDBMError;
34
35 #define RUBY_DBM_RW_BIT 0x20000000
36
37 struct dbmdata {
38 long di_size;
39 DBM *di_dbm;
40 };
41
42 static void
43 closed_dbm(void)
44 {
45 rb_raise(rb_eDBMError, "closed DBM file");
46 }
47
48 #define GetDBM(obj, dbmp) {\
49 Data_Get_Struct((obj), struct dbmdata, (dbmp));\
50 if ((dbmp) == 0) closed_dbm();\
51 if ((dbmp)->di_dbm == 0) closed_dbm();\
52 }
53
54 #define GetDBM2(obj, data, dbm) {\
55 GetDBM((obj), (data));\
56 (dbm) = dbmp->di_dbm;\
57 }
58
59 static void
60 free_dbm(struct dbmdata *dbmp)
61 {
62 if (dbmp) {
63 if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
64 xfree(dbmp);
65 }
66 }
67
68 /*
69 * call-seq:
70 * dbm.close
71 *
72 * Closes the database.
73 */
74 static VALUE
75 fdbm_close(VALUE obj)
76 {
77 struct dbmdata *dbmp;
78
79 GetDBM(obj, dbmp);
80 dbm_close(dbmp->di_dbm);
81 dbmp->di_dbm = 0;
82
83 return Qnil;
84 }
85
86 /*
87 * call-seq:
88 * dbm.closed? -> true or false
89 *
90 * Returns true if the database is closed, false otherwise.
91 */
92 static VALUE
93 fdbm_closed(VALUE obj)
94 {
95 struct dbmdata *dbmp;
96
97 Data_Get_Struct(obj, struct dbmdata, dbmp);
98 if (dbmp == 0)
99 return Qtrue;
100 if (dbmp->di_dbm == 0)
101 return Qtrue;
102
103 return Qfalse;
104 }
105
106 static VALUE
107 fdbm_alloc(VALUE klass)
108 {
109 return Data_Wrap_Struct(klass, 0, free_dbm, 0);
110 }
111
112 /*
113 * call-seq:
114 * DBM.new(filename[, mode[, flags]]) -> dbm
115 *
116 * Open a dbm database with the specified name, which can include a directory
117 * path. Any file extensions needed will be supplied automatically by the dbm
118 * library. For example, Berkeley DB appends '.db', and GNU gdbm uses two
119 * physical files with extensions '.dir' and '.pag'.
120 *
121 * The mode should be an integer, as for Unix chmod.
122 *
123 * Flags should be one of READER, WRITER, WRCREAT or NEWDB.
124 */
125 static VALUE
126 fdbm_initialize(int argc, VALUE *argv, VALUE obj)
127 {
128 volatile VALUE file;
129 VALUE vmode, vflags;
130 DBM *dbm;
131 struct dbmdata *dbmp;
132 int mode, flags = 0;
133
134 if (rb_scan_args(argc, argv, "12", &file, &vmode, &vflags) == 1) {
135 mode = 0666; /* default value */
136 }
137 else if (NIL_P(vmode)) {
138 mode = -1; /* return nil if DB not exist */
139 }
140 else {
141 mode = NUM2INT(vmode);
142 }
143
144 if (!NIL_P(vflags))
145 flags = NUM2INT(vflags);
146
147 FilePathValue(file);
148
149 /*
150 * Note:
151 * gdbm 1.10 works with O_CLOEXEC. gdbm 1.9.1 silently ignore it.
152 */
153 #ifndef O_CLOEXEC
154 # define O_CLOEXEC 0
155 #endif
156
157 if (flags & RUBY_DBM_RW_BIT) {
158 flags &= ~RUBY_DBM_RW_BIT;
159 dbm = dbm_open(RSTRING_PTR(file), flags|O_CLOEXEC, mode);
160 }
161 else {
162 dbm = 0;
163 if (mode >= 0) {
164 dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT|O_CLOEXEC, mode);
165 }
166 if (!dbm) {
167 dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CLOEXEC, 0);
168 }
169 if (!dbm) {
170 dbm = dbm_open(RSTRING_PTR(file), O_RDONLY|O_CLOEXEC, 0);
171 }
172 }
173
174 if (dbm) {
175 /*
176 * History of dbm_pagfno() and dbm_dirfno() in ndbm and its compatibles.
177 * (dbm_pagfno() and dbm_dirfno() is not standardized.)
178 *
179 * 1986: 4.3BSD provides ndbm.
180 * It provides dbm_pagfno() and dbm_dirfno() as macros.
181 * 1991: gdbm-1.5 provides them as functions.
182 * They returns a same descriptor.
183 * (Earlier releases may have the functions too.)
184 * 1991: Net/2 provides Berkeley DB.
185 * It doesn't provide dbm_pagfno() and dbm_dirfno().
186 * 1992: 4.4BSD Alpha provides Berkeley DB with dbm_dirfno() as a function.
187 * dbm_pagfno() is a macro as DBM_PAGFNO_NOT_AVAILABLE.
188 * 1997: Berkeley DB 2.0 is released by Sleepycat Software, Inc.
189 * It defines dbm_pagfno() and dbm_dirfno() as macros.
190 * 2011: gdbm-1.9 creates a separate dir file.
191 * dbm_pagfno() and dbm_dirfno() returns different descriptors.
192 */
193 #if defined(HAVE_DBM_PAGFNO)
194 rb_fd_fix_cloexec(dbm_pagfno(dbm));
195 #endif
196 #if defined(HAVE_DBM_DIRFNO)
197 rb_fd_fix_cloexec(dbm_dirfno(dbm));
198 #endif
199
200 #if defined(RUBYDBM_DB_HEADER) && defined(HAVE_TYPE_DBC)
201 /* Disable Berkeley DB error messages such as:
202 * DB->put: attempt to modify a read-only database */
203 ((DBC*)dbm)->dbp->set_errfile(((DBC*)dbm)->dbp, NULL);
204 #endif
205 }
206
207 if (!dbm) {
208 if (mode == -1) return Qnil;
209 rb_sys_fail_str(file);
210 }
211
212 dbmp = ALLOC(struct dbmdata);
213 DATA_PTR(obj) = dbmp;
214 dbmp->di_dbm = dbm;
215 dbmp->di_size = -1;
216
217 return obj;
218 }
219
220 /*
221 * call-seq:
222 * DBM.open(filename[, mode[, flags]]) -> dbm
223 * DBM.open(filename[, mode[, flags]]) {|dbm| block}
224 *
225 * Open a dbm database and yields it if a block is given. See also
226 * <code>DBM.new</code>.
227 */
228 static VALUE
229 fdbm_s_open(int argc, VALUE *argv, VALUE klass)
230 {
231 VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
232
233 if (NIL_P(fdbm_initialize(argc, argv, obj))) {
234 return Qnil;
235 }
236
237 if (rb_block_given_p()) {
238 return rb_ensure(rb_yield, obj, fdbm_close, obj);
239 }
240
241 return obj;
242 }
243
244 static VALUE
245 fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
246 {
247 datum key, value;
248 struct dbmdata *dbmp;
249 DBM *dbm;
250 long len;
251
252 ExportStringValue(keystr);
253 len = RSTRING_LEN(keystr);
254 if (TOO_LONG(len)) goto not_found;
255 key.dptr = RSTRING_PTR(keystr);
256 key.dsize = (DSIZE_TYPE)len;
257
258 GetDBM2(obj, dbmp, dbm);
259 value = dbm_fetch(dbm, key);
260 if (value.dptr == 0) {
261 not_found:
262 if (ifnone == Qnil && rb_block_given_p())
263 return rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
264 return ifnone;
265 }
266 return rb_tainted_str_new(value.dptr, value.dsize);
267 }
268
269 /*
270 * call-seq:
271 * dbm[key] -> string value or nil
272 *
273 * Return a value from the database by locating the key string
274 * provided. If the key is not found, returns nil.
275 */
276 static VALUE
277 fdbm_aref(VALUE obj, VALUE keystr)
278 {
279 return fdbm_fetch(obj, keystr, Qnil);
280 }
281
282 /*
283 * call-seq:
284 * dbm.fetch(key[, ifnone]) -> value
285 *
286 * Return a value from the database by locating the key string
287 * provided. If the key is not found, returns +ifnone+. If +ifnone+
288 * is not given, raises IndexError.
289 */
290 static VALUE
291 fdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
292 {
293 VALUE keystr, valstr, ifnone;
294
295 rb_scan_args(argc, argv, "11", &keystr, &ifnone);
296 valstr = fdbm_fetch(obj, keystr, ifnone);
297 if (argc == 1 && !rb_block_given_p() && NIL_P(valstr))
298 rb_raise(rb_eIndexError, "key not found");
299
300 return valstr;
301 }
302
303 /*
304 * call-seq:
305 * dbm.key(value) -> string
306 *
307 * Returns the key for the specified value.
308 */
309 static VALUE
310 fdbm_key(VALUE obj, VALUE valstr)
311 {
312 datum key, val;
313 struct dbmdata *dbmp;
314 DBM *dbm;
315 long len;
316
317 ExportStringValue(valstr);
318 len = RSTRING_LEN(valstr);
319 if (TOO_LONG(len)) return Qnil;
320 val.dptr = RSTRING_PTR(valstr);
321 val.dsize = (DSIZE_TYPE)len;
322
323 GetDBM2(obj, dbmp, dbm);
324 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
325 val = dbm_fetch(dbm, key);
326 if ((long)val.dsize == RSTRING_LEN(valstr) &&
327 memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0) {
328 return rb_tainted_str_new(key.dptr, key.dsize);
329 }
330 }
331 return Qnil;
332 }
333
334 /* :nodoc: */
335 static VALUE
336 fdbm_index(VALUE hash, VALUE value)
337 {
338 rb_warn("DBM#index is deprecated; use DBM#key");
339 return fdbm_key(hash, value);
340 }
341
342 /*
343 * call-seq:
344 * dbm.select {|key, value| block} -> array
345 *
346 * Returns a new array consisting of the [key, value] pairs for which the code
347 * block returns true.
348 */
349 static VALUE
350 fdbm_select(VALUE obj)
351 {
352 VALUE new = rb_ary_new();
353 datum key, val;
354 DBM *dbm;
355 struct dbmdata *dbmp;
356
357 GetDBM2(obj, dbmp, dbm);
358 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
359 VALUE assoc, v;
360 val = dbm_fetch(dbm, key);
361 assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
362 rb_tainted_str_new(val.dptr, val.dsize));
363 v = rb_yield(assoc);
364 if (RTEST(v)) {
365 rb_ary_push(new, assoc);
366 }
367 GetDBM2(obj, dbmp, dbm);
368 }
369
370 return new;
371 }
372
373 /*
374 * call-seq:
375 * dbm.values_at(key, ...) -> Array
376 *
377 * Returns an array containing the values associated with the given keys.
378 */
379 static VALUE
380 fdbm_values_at(int argc, VALUE *argv, VALUE obj)
381 {
382 VALUE new = rb_ary_new2(argc);
383 int i;
384
385 for (i=0; i<argc; i++) {
386 rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
387 }
388
389 return new;
390 }
391
392 static void
393 fdbm_modify(VALUE obj)
394 {
395 rb_secure(4);
396 if (OBJ_FROZEN(obj)) rb_error_frozen("DBM");
397 }
398
399 /*
400 * call-seq:
401 * dbm.delete(key)
402 *
403 * Deletes an entry from the database.
404 */
405 static VALUE
406 fdbm_delete(VALUE obj, VALUE keystr)
407 {
408 datum key, value;
409 struct dbmdata *dbmp;
410 DBM *dbm;
411 VALUE valstr;
412 long len;
413
414 fdbm_modify(obj);
415 ExportStringValue(keystr);
416 len = RSTRING_LEN(keystr);
417 if (TOO_LONG(len)) goto not_found;
418 key.dptr = RSTRING_PTR(keystr);
419 key.dsize = (DSIZE_TYPE)len;
420
421 GetDBM2(obj, dbmp, dbm);
422
423 value = dbm_fetch(dbm, key);
424 if (value.dptr == 0) {
425 not_found:
426 if (rb_block_given_p()) return rb_yield(keystr);
427 return Qnil;
428 }
429
430 /* need to save value before dbm_delete() */
431 valstr = rb_tainted_str_new(value.dptr, value.dsize);
432
433 if (dbm_delete(dbm, key)) {
434 dbmp->di_size = -1;
435 rb_raise(rb_eDBMError, "dbm_delete failed");
436 }
437 else if (dbmp->di_size >= 0) {
438 dbmp->di_size--;
439 }
440 return valstr;
441 }
442
443 /*
444 * call-seq:
445 * dbm.shift() -> [key, value]
446 *
447 * Removes a [key, value] pair from the database, and returns it.
448 * If the database is empty, returns nil.
449 * The order in which values are removed/returned is not guaranteed.
450 */
451 static VALUE
452 fdbm_shift(VALUE obj)
453 {
454 datum key, val;
455 struct dbmdata *dbmp;
456 DBM *dbm;
457 VALUE keystr, valstr;
458
459 fdbm_modify(obj);
460 GetDBM2(obj, dbmp, dbm);
461 dbmp->di_size = -1;
462
463 key = dbm_firstkey(dbm);
464 if (!key.dptr) return Qnil;
465 val = dbm_fetch(dbm, key);
466 keystr = rb_tainted_str_new(key.dptr, key.dsize);
467 valstr = rb_tainted_str_new(val.dptr, val.dsize);
468 dbm_delete(dbm, key);
469
470 return rb_assoc_new(keystr, valstr);
471 }
472
473 /*
474 * call-seq:
475 * dbm.reject! {|key, value| block} -> self
476 * dbm.delete_if {|key, value| block} -> self
477 *
478 * Deletes all entries for which the code block returns true.
479 * Returns self.
480 */
481 static VALUE
482 fdbm_delete_if(VALUE obj)
483 {
484 datum key, val;
485 struct dbmdata *dbmp;
486 DBM *dbm;
487 VALUE keystr, valstr;
488 VALUE ret, ary = rb_ary_tmp_new(0);
489 int i, status = 0;
490 long n;
491
492 fdbm_modify(obj);
493 GetDBM2(obj, dbmp, dbm);
494 n = dbmp->di_size;
495 dbmp->di_size = -1;
496
497 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
498 val = dbm_fetch(dbm, key);
499 keystr = rb_tainted_str_new(key.dptr, key.dsize);
500 OBJ_FREEZE(keystr);
501 valstr = rb_tainted_str_new(val.dptr, val.dsize);
502 ret = rb_protect(rb_yield, rb_assoc_new(rb_str_dup(keystr), valstr), &status);
503 if (status != 0) break;
504 if (RTEST(ret)) rb_ary_push(ary, keystr);
505 GetDBM2(obj, dbmp, dbm);
506 }
507
508 for (i = 0; i < RARRAY_LEN(ary); i++) {
509 keystr = RARRAY_PTR(ary)[i];
510 key.dptr = RSTRING_PTR(keystr);
511 key.dsize = (DSIZE_TYPE)RSTRING_LEN(keystr);
512 if (dbm_delete(dbm, key)) {
513 rb_raise(rb_eDBMError, "dbm_delete failed");
514 }
515 }
516 if (status) rb_jump_tag(status);
517 if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
518 rb_ary_clear(ary);
519
520 return obj;
521 }
522
523 /*
524 * call-seq:
525 * dbm.clear
526 *
527 * Deletes all data from the database.
528 */
529 static VALUE
530 fdbm_clear(VALUE obj)
531 {
532 datum key;
533 struct dbmdata *dbmp;
534 DBM *dbm;
535
536 fdbm_modify(obj);
537 GetDBM2(obj, dbmp, dbm);
538 dbmp->di_size = -1;
539 while (key = dbm_firstkey(dbm), key.dptr) {
540 if (dbm_delete(dbm, key)) {
541 rb_raise(rb_eDBMError, "dbm_delete failed");
542 }
543 }
544 dbmp->di_size = 0;
545
546 return obj;
547 }
548
549 /*
550 * call-seq:
551 * dbm.invert -> hash
552 *
553 * Returns a Hash (not a DBM database) created by using each value in the
554 * database as a key, with the corresponding key as its value.
555 */
556 static VALUE
557 fdbm_invert(VALUE obj)
558 {
559 datum key, val;
560 struct dbmdata *dbmp;
561 DBM *dbm;
562 VALUE keystr, valstr;
563 VALUE hash = rb_hash_new();
564
565 GetDBM2(obj, dbmp, dbm);
566 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
567 val = dbm_fetch(dbm, key);
568 keystr = rb_tainted_str_new(key.dptr, key.dsize);
569 valstr = rb_tainted_str_new(val.dptr, val.dsize);
570 rb_hash_aset(hash, valstr, keystr);
571 }
572 return hash;
573 }
574
575 static VALUE fdbm_store(VALUE,VALUE,VALUE);
576
577 static VALUE
578 update_i(VALUE pair, VALUE dbm)
579 {
580 Check_Type(pair, T_ARRAY);
581 if (RARRAY_LEN(pair) < 2) {
582 rb_raise(rb_eArgError, "pair must be [key, value]");
583 }
584 fdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
585 return Qnil;
586 }
587
588 /*
589 * call-seq:
590 * dbm.update(obj)
591 *
592 * Updates the database with multiple values from the specified object.
593 * Takes any object which implements the each_pair method, including
594 * Hash and DBM objects.
595 */
596 static VALUE
597 fdbm_update(VALUE obj, VALUE other)
598 {
599 rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
600 return obj;
601 }
602
603 /*
604 * call-seq:
605 * dbm.replace(obj)
606 *
607 * Replaces the contents of the database with the contents of the specified
608 * object. Takes any object which implements the each_pair method, including
609 * Hash and DBM objects.
610 */
611 static VALUE
612 fdbm_replace(VALUE obj, VALUE other)
613 {
614 fdbm_clear(obj);
615 rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
616 return obj;
617 }
618
619 /*
620 * call-seq:
621 * dbm.store(key, value) -> value
622 * dbm[key] = value
623 *
624 * Stores the specified string value in the database, indexed via the
625 * string key provided.
626 */
627 static VALUE
628 fdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
629 {
630 datum key, val;
631 struct dbmdata *dbmp;
632 DBM *dbm;
633
634 fdbm_modify(obj);
635 keystr = rb_obj_as_string(keystr);
636 valstr = rb_obj_as_string(valstr);
637
638 key.dptr = RSTRING_PTR(keystr);
639 key.dsize = RSTRING_DSIZE(keystr);
640
641 val.dptr = RSTRING_PTR(valstr);
642 val.dsize = RSTRING_DSIZE(valstr);
643
644 GetDBM2(obj, dbmp, dbm);
645 dbmp->di_size = -1;
646 if (dbm_store(dbm, key, val, DBM_REPLACE)) {
647 dbm_clearerr(dbm);
648 if (errno == EPERM) rb_sys_fail(0);
649 rb_raise(rb_eDBMError, "dbm_store failed");
650 }
651
652 return valstr;
653 }
654
655 /*
656 * call-seq:
657 * dbm.length -> integer
658 *
659 * Returns the number of entries in the database.
660 */
661 static VALUE
662 fdbm_length(VALUE obj)
663 {
664 datum key;
665 struct dbmdata *dbmp;
666 DBM *dbm;
667 int i = 0;
668
669 GetDBM2(obj, dbmp, dbm);
670 if (dbmp->di_size > 0) return INT2FIX(dbmp->di_size);
671
672 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
673 i++;
674 }
675 dbmp->di_size = i;
676
677 return INT2FIX(i);
678 }
679
680 /*
681 * call-seq:
682 * dbm.empty?
683 *
684 * Returns true if the database is empty, false otherwise.
685 */
686 static VALUE
687 fdbm_empty_p(VALUE obj)
688 {
689 datum key;
690 struct dbmdata *dbmp;
691 DBM *dbm;
692
693 GetDBM2(obj, dbmp, dbm);
694 if (dbmp->di_size < 0) {
695 dbm = dbmp->di_dbm;
696
697 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
698 return Qfalse;
699 }
700 }
701 else {
702 if (dbmp->di_size)
703 return Qfalse;
704 }
705 return Qtrue;
706 }
707
708 /*
709 * call-seq:
710 * dbm.each_value {|value| block} -> self
711 *
712 * Calls the block once for each value string in the database. Returns self.
713 */
714 static VALUE
715 fdbm_each_value(VALUE obj)
716 {
717 datum key, val;
718 struct dbmdata *dbmp;
719 DBM *dbm;
720
721 RETURN_ENUMERATOR(obj, 0, 0);
722
723 GetDBM2(obj, dbmp, dbm);
724 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
725 val = dbm_fetch(dbm, key);
726 rb_yield(rb_tainted_str_new(val.dptr, val.dsize));
727 GetDBM2(obj, dbmp, dbm);
728 }
729 return obj;
730 }
731
732 /*
733 * call-seq:
734 * dbm.each_key {|key| block} -> self
735 *
736 * Calls the block once for each key string in the database. Returns self.
737 */
738 static VALUE
739 fdbm_each_key(VALUE obj)
740 {
741 datum key;
742 struct dbmdata *dbmp;
743 DBM *dbm;
744
745 RETURN_ENUMERATOR(obj, 0, 0);
746
747 GetDBM2(obj, dbmp, dbm);
748 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
749 rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
750 GetDBM2(obj, dbmp, dbm);
751 }
752 return obj;
753 }
754
755 /*
756 * call-seq:
757 * dbm.each_pair {|key,value| block} -> self
758 *
759 * Calls the block once for each [key, value] pair in the database.
760 * Returns self.
761 */
762 static VALUE
763 fdbm_each_pair(VALUE obj)
764 {
765 datum key, val;
766 DBM *dbm;
767 struct dbmdata *dbmp;
768 VALUE keystr, valstr;
769
770 RETURN_ENUMERATOR(obj, 0, 0);
771
772 GetDBM2(obj, dbmp, dbm);
773
774 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
775 val = dbm_fetch(dbm, key);
776 keystr = rb_tainted_str_new(key.dptr, key.dsize);
777 valstr = rb_tainted_str_new(val.dptr, val.dsize);
778 rb_yield(rb_assoc_new(keystr, valstr));
779 GetDBM2(obj, dbmp, dbm);
780 }
781
782 return obj;
783 }
784
785 /*
786 * call-seq:
787 * dbm.keys -> array
788 *
789 * Returns an array of all the string keys in the database.
790 */
791 static VALUE
792 fdbm_keys(VALUE obj)
793 {
794 datum key;
795 struct dbmdata *dbmp;
796 DBM *dbm;
797 VALUE ary;
798
799 GetDBM2(obj, dbmp, dbm);
800
801 ary = rb_ary_new();
802 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
803 rb_ary_push(ary, rb_tainted_str_new(key.dptr, key.dsize));
804 }
805
806 return ary;
807 }
808
809 /*
810 * call-seq:
811 * dbm.values -> array
812 *
813 * Returns an array of all the string values in the database.
814 */
815 static VALUE
816 fdbm_values(VALUE obj)
817 {
818 datum key, val;
819 struct dbmdata *dbmp;
820 DBM *dbm;
821 VALUE ary;
822
823 GetDBM2(obj, dbmp, dbm);
824 ary = rb_ary_new();
825 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
826 val = dbm_fetch(dbm, key);
827 rb_ary_push(ary, rb_tainted_str_new(val.dptr, val.dsize));
828 }
829
830 return ary;
831 }
832
833 /*
834 * call-seq:
835 * dbm.has_key?(key) -> boolean
836 *
837 * Returns true if the database contains the specified key, false otherwise.
838 */
839 static VALUE
840 fdbm_has_key(VALUE obj, VALUE keystr)
841 {
842 datum key, val;
843 struct dbmdata *dbmp;
844 DBM *dbm;
845 long len;
846
847 ExportStringValue(keystr);
848 len = RSTRING_LEN(keystr);
849 if (TOO_LONG(len)) return Qfalse;
850 key.dptr = RSTRING_PTR(keystr);
851 key.dsize = (DSIZE_TYPE)len;
852
853 GetDBM2(obj, dbmp, dbm);
854 val = dbm_fetch(dbm, key);
855 if (val.dptr) return Qtrue;
856 return Qfalse;
857 }
858
859 /*
860 * call-seq:
861 * dbm.has_value?(value) -> boolean
862 *
863 * Returns true if the database contains the specified string value, false
864 * otherwise.
865 */
866 static VALUE
867 fdbm_has_value(VALUE obj, VALUE valstr)
868 {
869 datum key, val;
870 struct dbmdata *dbmp;
871 DBM *dbm;
872 long len;
873
874 ExportStringValue(valstr);
875 len = RSTRING_LEN(valstr);
876 if (TOO_LONG(len)) return Qfalse;
877 val.dptr = RSTRING_PTR(valstr);
878 val.dsize = (DSIZE_TYPE)len;
879
880 GetDBM2(obj, dbmp, dbm);
881 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
882 val = dbm_fetch(dbm, key);
883 if ((DSIZE_TYPE)val.dsize == (DSIZE_TYPE)RSTRING_LEN(valstr) &&
884 memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
885 return Qtrue;
886 }
887 return Qfalse;
888 }
889
890 /*
891 * call-seq:
892 * dbm.to_a -> array
893 *
894 * Converts the contents of the database to an array of [key, value] arrays,
895 * and returns it.
896 */
897 static VALUE
898 fdbm_to_a(VALUE obj)
899 {
900 datum key, val;
901 struct dbmdata *dbmp;
902 DBM *dbm;
903 VALUE ary;
904
905 GetDBM2(obj, dbmp, dbm);
906 ary = rb_ary_new();
907 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
908 val = dbm_fetch(dbm, key);
909 rb_ary_push(ary, rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
910 rb_tainted_str_new(val.dptr, val.dsize)));
911 }
912
913 return ary;
914 }
915
916 /*
917 * call-seq:
918 * dbm.to_hash -> hash
919 *
920 * Converts the contents of the database to an in-memory Hash object, and
921 * returns it.
922 */
923 static VALUE
924 fdbm_to_hash(VALUE obj)
925 {
926 datum key, val;
927 struct dbmdata *dbmp;
928 DBM *dbm;
929 VALUE hash;
930
931 GetDBM2(obj, dbmp, dbm);
932 hash = rb_hash_new();
933 for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
934 val = dbm_fetch(dbm, key);
935 rb_hash_aset(hash, rb_tainted_str_new(key.dptr, key.dsize),
936 rb_tainted_str_new(val.dptr, val.dsize));
937 }
938
939 return hash;
940 }
941
942 /*
943 * call-seq:
944 * dbm.reject {|key,value| block} -> Hash
945 *
946 * Converts the contents of the database to an in-memory Hash, then calls
947 * Hash#reject with the specified code block, returning a new Hash.
948 */
949 static VALUE
950 fdbm_reject(VALUE obj)
951 {
952 return rb_hash_delete_if(fdbm_to_hash(obj));
953 }
954
955 /*
956 * Documented by mathew meta@pobox.com.
957 * = Introduction
958 *
959 * The DBM class provides a wrapper to a Unix-style
960 * {dbm}[http://en.wikipedia.org/wiki/Dbm] or Database Manager library.
961 *
962 * Dbm databases do not have tables or columns; they are simple key-value
963 * data stores, like a Ruby Hash except not resident in RAM. Keys and values
964 * must be strings.
965 *
966 * The exact library used depends on how Ruby was compiled. It could be any
967 * of the following:
968 *
969 * - The original ndbm library is released in 4.3BSD.
970 * It is based on dbm library in Unix Version 7 but has different API to
971 * support multiple databases in a process.
972 * - {Berkeley DB}[http://en.wikipedia.org/wiki/Berkeley_DB] versions
973 * 1 thru 5, also known as BDB and Sleepycat DB, now owned by Oracle
974 * Corporation.
975 * - Berkeley DB 1.x, still found in 4.4BSD derivatives (FreeBSD, OpenBSD, etc).
976 * - {gdbm}[http://www.gnu.org/software/gdbm/], the GNU implementation of dbm.
977 * - {qdbm}[http://fallabs.com/qdbm/index.html], another open source
978 * reimplementation of dbm.
979 *
980 * All of these dbm implementations have their own Ruby interfaces
981 * available, which provide richer (but varying) APIs.
982 *
983 * = Cautions
984 *
985 * Before you decide to use DBM, there are some issues you should consider:
986 *
987 * - Each implementation of dbm has its own file format. Generally, dbm
988 * libraries will not read each other's files. This makes dbm files
989 * a bad choice for data exchange.
990 *
991 * - Even running the same OS and the same dbm implementation, the database
992 * file format may depend on the CPU architecture. For example, files may
993 * not be portable between PowerPC and 386, or between 32 and 64 bit Linux.
994 *
995 * - Different versions of Berkeley DB use different file formats. A change to
996 * the OS may therefore break DBM access to existing files.
997 *
998 * - Data size limits vary between implementations. Original Berkeley DB was
999 * limited to 2GB of data. Dbm libraries also sometimes limit the total
1000 * size of a key/value pair, and the total size of all the keys that hash
1001 * to the same value. These limits can be as little as 512 bytes. That said,
1002 * gdbm and recent versions of Berkeley DB do away with these limits.
1003 *
1004 * Given the above cautions, DBM is not a good choice for long term storage of
1005 * important data. It is probably best used as a fast and easy alternative
1006 * to a Hash for processing large amounts of data.
1007 *
1008 * = Example
1009 *
1010 * require 'dbm'
1011 * db = DBM.open('rfcs', 666, DBM::CREATRW)
1012 * db['822'] = 'Standard for the Format of ARPA Internet Text Messages'
1013 * db['1123'] = 'Requirements for Internet Hosts - Application and Support'
1014 * db['3068'] = 'An Anycast Prefix for 6to4 Relay Routers'
1015 * puts db['822']
1016 */
1017 void
1018 Init_dbm(void)
1019 {
1020 rb_cDBM = rb_define_class("DBM", rb_cObject);
1021 /* Document-class: DBMError
1022 * Exception class used to return errors from the dbm library.
1023 */
1024 rb_eDBMError = rb_define_class("DBMError", rb_eStandardError);
1025 rb_include_module(rb_cDBM, rb_mEnumerable);
1026
1027 rb_define_alloc_func(rb_cDBM, fdbm_alloc);
1028 rb_define_singleton_method(rb_cDBM, "open", fdbm_s_open, -1);
1029
1030 rb_define_method(rb_cDBM, "initialize", fdbm_initialize, -1);
1031 rb_define_method(rb_cDBM, "close", fdbm_close, 0);
1032 rb_define_method(rb_cDBM, "closed?", fdbm_closed, 0);
1033 rb_define_method(rb_cDBM, "[]", fdbm_aref, 1);
1034 rb_define_method(rb_cDBM, "fetch", fdbm_fetch_m, -1);
1035 rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
1036 rb_define_method(rb_cDBM, "store", fdbm_store, 2);
1037 rb_define_method(rb_cDBM, "index", fdbm_index, 1);
1038 rb_define_method(rb_cDBM, "key", fdbm_key, 1);
1039 rb_define_method(rb_cDBM, "select", fdbm_select, 0);
1040 rb_define_method(rb_cDBM, "values_at", fdbm_values_at, -1);
1041 rb_define_method(rb_cDBM, "length", fdbm_length, 0);
1042 rb_define_method(rb_cDBM, "size", fdbm_length, 0);
1043 rb_define_method(rb_cDBM, "empty?", fdbm_empty_p, 0);
1044 rb_define_method(rb_cDBM, "each", fdbm_each_pair, 0);
1045 rb_define_method(rb_cDBM, "each_value", fdbm_each_value, 0);
1046 rb_define_method(rb_cDBM, "each_key", fdbm_each_key, 0);
1047 rb_define_method(rb_cDBM, "each_pair", fdbm_each_pair, 0);
1048 rb_define_method(rb_cDBM, "keys", fdbm_keys, 0);
1049 rb_define_method(rb_cDBM, "values", fdbm_values, 0);
1050 rb_define_method(rb_cDBM, "shift", fdbm_shift, 0);
1051 rb_define_method(rb_cDBM, "delete", fdbm_delete, 1);
1052 rb_define_method(rb_cDBM, "delete_if", fdbm_delete_if, 0);
1053 rb_define_method(rb_cDBM, "reject!", fdbm_delete_if, 0);
1054 rb_define_method(rb_cDBM, "reject", fdbm_reject, 0);
1055 rb_define_method(rb_cDBM, "clear", fdbm_clear, 0);
1056 rb_define_method(rb_cDBM, "invert", fdbm_invert, 0);
1057 rb_define_method(rb_cDBM, "update", fdbm_update, 1);
1058 rb_define_method(rb_cDBM, "replace", fdbm_replace, 1);
1059
1060 rb_define_method(rb_cDBM, "include?", fdbm_has_key, 1);
1061 rb_define_method(rb_cDBM, "has_key?", fdbm_has_key, 1);
1062 rb_define_method(rb_cDBM, "member?", fdbm_has_key, 1);
1063 rb_define_method(rb_cDBM, "has_value?", fdbm_has_value, 1);
1064 rb_define_method(rb_cDBM, "key?", fdbm_has_key, 1);
1065 rb_define_method(rb_cDBM, "value?", fdbm_has_value, 1);
1066
1067 rb_define_method(rb_cDBM, "to_a", fdbm_to_a, 0);
1068 rb_define_method(rb_cDBM, "to_hash", fdbm_to_hash, 0);
1069
1070 /* Indicates that dbm_open() should open the database in read-only mode */
1071 rb_define_const(rb_cDBM, "READER", INT2FIX(O_RDONLY|RUBY_DBM_RW_BIT));
1072
1073 /* Indicates that dbm_open() should open the database in read/write mode */
1074 rb_define_const(rb_cDBM, "WRITER", INT2FIX(O_RDWR|RUBY_DBM_RW_BIT));
1075
1076 /* Indicates that dbm_open() should open the database in read/write mode,
1077 * and create it if it does not already exist
1078 */
1079 rb_define_const(rb_cDBM, "WRCREAT", INT2FIX(O_RDWR|O_CREAT|RUBY_DBM_RW_BIT));
1080
1081 /* Indicates that dbm_open() should open the database in read/write mode,
1082 * create it if it does not already exist, and delete all contents if it
1083 * does already exist.
1084 */
1085 rb_define_const(rb_cDBM, "NEWDB", INT2FIX(O_RDWR|O_CREAT|O_TRUNC|RUBY_DBM_RW_BIT));
1086
1087 {
1088 VALUE version;
1089 #if defined(_DBM_IOERR)
1090 version = rb_str_new2("ndbm (4.3BSD)");
1091 #elif defined(RUBYDBM_GDBM_HEADER)
1092 # if defined(HAVE_DECLARED_LIBVAR_GDBM_VERSION)
1093 /* since gdbm 1.9 */
1094 version = rb_str_new2(gdbm_version);
1095 # elif defined(HAVE_UNDECLARED_LIBVAR_GDBM_VERSION)
1096 /* ndbm.h doesn't declare gdbm_version until gdbm 1.8.3.
1097 * See extconf.rb for more information. */
1098 RUBY_EXTERN char *gdbm_version;
1099 version = rb_str_new2(gdbm_version);
1100 # else
1101 version = rb_str_new2("GDBM (unknown)");
1102 # endif
1103 #elif defined(RUBYDBM_DB_HEADER)
1104 # if defined(HAVE_DB_VERSION)
1105 /* The version of the dbm library, if using Berkeley DB */
1106 version = rb_str_new2(db_version(NULL, NULL, NULL));
1107 # else
1108 version = rb_str_new2("Berkeley DB (unknown)");
1109 # endif
1110 #elif defined(_RELIC_H)
1111 # if defined(HAVE_DPVERSION)
1112 version = rb_sprintf("QDBM %s", dpversion);
1113 # else
1114 version = rb_str_new2("QDBM (unknown)");
1115 # endif
1116 #else
1117 version = rb_str_new2("ndbm (unknown)");
1118 #endif
1119 /*
1120 * Identifies ndbm library version.
1121 *
1122 * Examples:
1123 *
1124 * - "ndbm (4.3BSD)"
1125 * - "Berkeley DB 4.8.30: (April 9, 2010)"
1126 * - "Berkeley DB (unknown)" (4.4BSD, maybe)
1127 * - "GDBM version 1.8.3. 10/15/2002 (built Jul 1 2011 12:32:45)"
1128 * - "QDBM 1.8.78"
1129 *
1130 */
1131 rb_define_const(rb_cDBM, "VERSION", version);
1132 }
1133 }
RARRAY_PTR
RARRAY_PTR(q->result)[0]
dbmdata::di_dbm
DBM * di_dbm
Definition: dbm.c:39
ALLOC
#define ALLOC(type)
fdbm_delete
static VALUE fdbm_delete(VALUE obj, VALUE keystr)
Definition: dbm.c:406
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:509
FilePathValue
#define FilePathValue(v)
n
ssize_t n
Definition: bigdecimal.c:5655
fdbm_length
static VALUE fdbm_length(VALUE obj)
Definition: dbm.c:662
ary
volatile VALUE ary
Definition: tcltklib.c:9713
fdbm_s_open
static VALUE fdbm_s_open(int argc, VALUE *argv, VALUE klass)
Definition: dbm.c:229
pair
volatile VALUE pair
Definition: tkutil.c:554
fdbm_store
static VALUE fdbm_store(VALUE, VALUE, VALUE)
Definition: dbm.c:628
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1497
rb_secure
void rb_secure(int)
Definition: safe.c:79
fdbm_index
static VALUE fdbm_index(VALUE hash, VALUE value)
Definition: dbm.c:336
i
ssize_t i
Definition: bigdecimal.c:5655
rb_error_frozen
void rb_error_frozen(const char *what)
Definition: error.c:1972
fdbm_values
static VALUE fdbm_values(VALUE obj)
Definition: dbm.c:816
ruby.h
ret
int ret
Definition: tcltklib.c:280
status
int status
Definition: tcltklib.c:2197
OBJ_FREEZE
#define OBJ_FREEZE(x)
rb_define_alloc_func
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
fdbm_replace
static VALUE fdbm_replace(VALUE obj, VALUE other)
Definition: dbm.c:612
dbmdata::di_size
long di_size
Definition: dbm.c:38
rb_ary_tmp_new
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:465
RSTRING_PTR
#define RSTRING_PTR(str)
NIL_P
NIL_P(eventloop_thread)
Definition: tcltklib.c:4068
T_ARRAY
#define T_ARRAY
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:771
xfree
#define xfree
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1780
Qtrue
return Qtrue
Definition: tcltklib.c:9610
RETURN_ENUMERATOR
#define RETURN_ENUMERATOR(obj, argc, argv)
rb_ary_clear
VALUE rb_ary_clear(VALUE ary)
Definition: array.c:3220
dbmdata
Definition: dbm.c:37
GetDBM2
#define GetDBM2(obj, data, dbm)
Definition: dbm.c:54
rb_include_module
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:695
datum::dptr
char * dptr
Definition: sdbm.h:51
DSIZE_TYPE
#define DSIZE_TYPE
Definition: dbm.c:24
rb_str_new2
#define rb_str_new2
TOO_LONG
#define TOO_LONG(n)
Definition: dbm.c:30
fdbm_has_key
static VALUE fdbm_has_key(VALUE obj, VALUE keystr)
Definition: dbm.c:840
free_dbm
static void free_dbm(struct dbmdata *dbmp)
Definition: dbm.c:60
rb_fd_fix_cloexec
void rb_fd_fix_cloexec(int fd)
Definition: io.c:202
fdbm_values_at
static VALUE fdbm_values_at(int argc, VALUE *argv, VALUE obj)
Definition: dbm.c:380
fdbm_empty_p
static VALUE fdbm_empty_p(VALUE obj)
Definition: dbm.c:687
RSTRING_DSIZE
#define RSTRING_DSIZE(s)
Definition: dbm.c:29
fdbm_reject
static VALUE fdbm_reject(VALUE obj)
Definition: dbm.c:950
hash
VALUE hash
Definition: tkutil.c:267
O_CLOEXEC
#define O_CLOEXEC
Data_Wrap_Struct
return Data_Wrap_Struct(CLASS_OF(interp), 0, ip_free, slave)
Qfalse
return Qfalse
Definition: tcltklib.c:6779
datum
Definition: sdbm.h:50
rb_block_given_p
int rb_block_given_p(void)
Definition: eval.c:672
DBM_REPLACE
#define DBM_REPLACE
Definition: sdbm.h:67
RARRAY_LEN
#define RARRAY_LEN(a)
Qnil
#define Qnil
Definition: tcltklib.c:1896
val
#define val
Definition: tcltklib.c:1949
fdbm_aref
static VALUE fdbm_aref(VALUE obj, VALUE keystr)
Definition: dbm.c:277
fdbm_to_a
static VALUE fdbm_to_a(VALUE obj)
Definition: dbm.c:898
fdbm_select
static VALUE fdbm_select(VALUE obj)
Definition: dbm.c:350
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:424
fdbm_close
static VALUE fdbm_close(VALUE obj)
Definition: dbm.c:75
Check_Type
#define Check_Type(v, t)
flags
int flags
Definition: tcltklib.c:3023
fdbm_modify
static void fdbm_modify(VALUE obj)
Definition: dbm.c:393
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2202
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:499
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
RSTRING_LEN
#define RSTRING_LEN(str)
INT2FIX
#define INT2FIX(i)
rb_sys_fail_str
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:1905
RUBY_DBM_RW_BIT
#define RUBY_DBM_RW_BIT
Definition: dbm.c:35
fdbm_shift
static VALUE fdbm_shift(VALUE obj)
Definition: dbm.c:452
Init_dbm
void Init_dbm(void)
Definition: dbm.c:1018
assoc
static VALUE VALUE assoc
Definition: tkutil.c:545
rb_eIndexError
VALUE rb_eIndexError
Definition: error.c:513
key
static int VALUE key
Definition: tkutil.c:265
fdbm_each_key
static VALUE fdbm_each_key(VALUE obj)
Definition: dbm.c:739
rb_str_dup
VALUE rb_str_dup(VALUE)
Definition: string.c:946
ExportStringValue
#define ExportStringValue(v)
rb_obj_as_string
VALUE rb_obj_as_string(VALUE)
Definition: string.c:895
argv
VALUE * argv
Definition: tcltklib.c:1971
rb_hash_aset
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
rb_yield
VALUE rb_yield(VALUE)
Definition: vm_eval.c:934
rb_tainted_str_new
VALUE rb_tainted_str_new(const char *, long)
RTEST
#define RTEST(v)
fdbm_clear
static VALUE fdbm_clear(VALUE obj)
Definition: dbm.c:530
errno
int errno
rb_mEnumerable
VALUE rb_mEnumerable
Definition: enum.c:20
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1270
value
volatile VALUE value
Definition: tcltklib.c:9442
DBM
Definition: sdbm.h:20
mode
VALUE mode
Definition: tcltklib.c:1664
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
rb_block_call
VALUE rb_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
Definition: vm_eval.c:1131
rb_assoc_new
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Definition: array.c:545
OBJ_FROZEN
#define OBJ_FROZEN(x)
fdbm_to_hash
static VALUE fdbm_to_hash(VALUE obj)
Definition: dbm.c:924
datum::dsize
int dsize
Definition: sdbm.h:52
argc
int argc
Definition: tcltklib.c:1970
EPERM
#define EPERM
Definition: _sdbm.c:94
rb_ensure
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:804
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
rb_sys_fail
void rb_sys_fail(const char *mesg)
Definition: error.c:1899
rb_jump_tag
void rb_jump_tag(int tag)
Definition: eval.c:666
rb_eDBMError
static VALUE rb_eDBMError
Definition: dbm.c:33
fdbm_alloc
static VALUE fdbm_alloc(VALUE klass)
Definition: dbm.c:107
rb_cDBM
static VALUE rb_cDBM
Definition: dbm.c:33
fdbm_fetch
static VALUE fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
Definition: dbm.c:245
fdbm_initialize
static VALUE fdbm_initialize(int argc, VALUE *argv, VALUE obj)
Definition: dbm.c:126
DATA_PTR
DATA_PTR(self)
update_i
static VALUE update_i(VALUE pair, VALUE dbm)
Definition: dbm.c:578
fdbm_closed
static VALUE fdbm_closed(VALUE obj)
Definition: dbm.c:93
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
fdbm_each_value
static VALUE fdbm_each_value(VALUE obj)
Definition: dbm.c:715
fdbm_keys
static VALUE fdbm_keys(VALUE obj)
Definition: dbm.c:792
klass
klass
Definition: tcltklib.c:3504
Data_Get_Struct
#define Data_Get_Struct(obj, type, sval)
fdbm_update
static VALUE fdbm_update(VALUE obj, VALUE other)
Definition: dbm.c:597
fdbm_invert
static VALUE fdbm_invert(VALUE obj)
Definition: dbm.c:557
RUBY_EXTERN
#define RUBY_EXTERN
Definition: defines.h:188
rb_ary_new2
VALUE rb_ary_new2(long capa)
Definition: array.c:417
fdbm_has_value
static VALUE fdbm_has_value(VALUE obj, VALUE valstr)
Definition: dbm.c:867
rb_hash_delete_if
VALUE rb_hash_delete_if(VALUE)
Definition: hash.c:959
closed_dbm
static void closed_dbm(void)
Definition: dbm.c:43
NUM2INT
#define NUM2INT(x)
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:234
GetDBM
#define GetDBM(obj, dbmp)
Definition: dbm.c:48
VALUE
unsigned long VALUE
Definition: ripper.y:104
version
static void version(void)
Definition: nkf.c:898
rb_intern
#define rb_intern(str)
v
BDIGIT v
Definition: bigdecimal.c:5656
NULL
#define NULL
Definition: _sdbm.c:103
fdbm_key
static VALUE fdbm_key(VALUE obj, VALUE valstr)
Definition: dbm.c:310
fdbm_delete_if
static VALUE fdbm_delete_if(VALUE obj)
Definition: dbm.c:482
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:216
fdbm_each_pair
static VALUE fdbm_each_pair(VALUE obj)
Definition: dbm.c:763
rb_eArgError
VALUE rb_eArgError
Definition: error.c:512
fdbm_fetch_m
static VALUE fdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
Definition: dbm.c:291
len
size_t len
Definition: tcltklib.c:3568