17 #ifdef HAVE_SYS_CDEFS_H 18 # include <sys/cdefs.h> 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) ((void)(n),0) 29 # define RSTRING_DSIZE(s) RSTRING_LENINT(s) 30 # define TOO_LONG(n) ((long)(+(DSIZE_TYPE)(n)) != (n)) 33 static VALUE rb_cDBM, rb_eDBMError;
35 #define RUBY_DBM_RW_BIT 0x20000000 45 rb_raise(rb_eDBMError,
"closed DBM file");
48 #define GetDBM(obj, dbmp) do {\ 49 TypedData_Get_Struct((obj), struct dbmdata, &dbm_type, (dbmp));\ 50 if ((dbmp) == 0) closed_dbm();\ 51 if ((dbmp)->di_dbm == 0) closed_dbm();\ 54 #define GetDBM2(obj, dbmp, dbm) do {\ 55 GetDBM((obj), (dbmp));\ 56 (dbm) = (dbmp)->di_dbm;\ 70 memsize_dbm(
const void *ptr)
73 const struct dbmdata *dbmp = ptr;
75 size +=
sizeof(*dbmp);
76 if (dbmp->
di_dbm) size += DBM_SIZEOF_DBM;
83 {0, free_dbm, memsize_dbm,},
113 fdbm_closed(
VALUE obj)
127 fdbm_alloc(
VALUE klass)
148 VALUE file, vmode, vflags;
156 else if (
NIL_P(vmode)) {
177 flags &= ~RUBY_DBM_RW_BIT;
212 #if defined(HAVE_DBM_PAGFNO) 215 #if defined(HAVE_DBM_DIRFNO) 219 #if defined(RUBYDBM_DB_HEADER) && defined(HAVE_TYPE_DBC) 222 ((DBC*)dbm)->dbp->set_errfile(((DBC*)dbm)->dbp,
NULL);
227 if (mode == -1)
return Qnil;
250 VALUE obj = fdbm_alloc(klass);
278 value = dbm_fetch(dbm, key);
279 if (value.
dptr == 0) {
301 return fdbm_fetch(obj, keystr,
Qnil);
315 VALUE keystr, valstr, ifnone;
318 valstr = fdbm_fetch(obj, keystr, ifnone);
344 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
345 val = dbm_fetch(dbm, key);
358 rb_warn(
"DBM#index is deprecated; use DBM#key");
359 return fdbm_key(hash, value);
370 fdbm_select(
VALUE obj)
378 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
380 val = dbm_fetch(dbm, key);
405 for (i=0; i<
argc; i++) {
413 fdbm_modify(
VALUE obj)
442 value = dbm_fetch(dbm, key);
443 if (value.
dptr == 0) {
452 if (dbm_delete(dbm, key)) {
454 rb_raise(rb_eDBMError,
"dbm_delete failed");
471 fdbm_shift(
VALUE obj)
476 VALUE keystr, valstr;
482 key = dbm_firstkey(dbm);
484 val = dbm_fetch(dbm, key);
487 dbm_delete(dbm, key);
501 fdbm_delete_if(
VALUE obj)
506 VALUE keystr, valstr;
516 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
517 val = dbm_fetch(dbm, key);
522 if (status != 0)
break;
531 if (dbm_delete(dbm, key)) {
532 rb_raise(rb_eDBMError,
"dbm_delete failed");
549 fdbm_clear(
VALUE obj)
558 while (key = dbm_firstkey(dbm), key.
dptr) {
559 if (dbm_delete(dbm, key)) {
560 rb_raise(rb_eDBMError,
"dbm_delete failed");
576 fdbm_invert(
VALUE obj)
581 VALUE keystr, valstr;
585 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
586 val = dbm_fetch(dbm, key);
605 fdbm_store(dbm, ptr[0], ptr[1]);
670 rb_raise(rb_eDBMError,
"dbm_store failed");
684 fdbm_length(
VALUE obj)
694 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
709 fdbm_empty_p(
VALUE obj)
719 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
737 fdbm_each_value(
VALUE obj)
746 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
747 val = dbm_fetch(dbm, key);
761 fdbm_each_key(
VALUE obj)
770 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
785 fdbm_each_pair(
VALUE obj)
790 VALUE keystr, valstr;
796 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
797 val = dbm_fetch(dbm, key);
824 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
838 fdbm_values(
VALUE obj)
847 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
848 val = dbm_fetch(dbm, key);
879 val = dbm_fetch(dbm, key);
907 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
908 val = dbm_fetch(dbm, key);
933 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
934 val = dbm_fetch(dbm, key);
950 fdbm_to_hash(
VALUE obj)
959 for (key = dbm_firstkey(dbm); key.
dptr; key = dbm_nextkey(dbm)) {
960 val = dbm_fetch(dbm, key);
976 fdbm_reject(
VALUE obj)
1114 #if defined(_DBM_IOERR) 1116 #elif defined(RUBYDBM_GDBM_HEADER) 1117 # if defined(HAVE_DECLARED_LIBVAR_GDBM_VERSION) 1120 # elif defined(HAVE_UNDECLARED_LIBVAR_GDBM_VERSION) 1128 #elif defined(RUBYDBM_DB_HEADER) 1129 # if defined(HAVE_DB_VERSION) 1135 #elif defined(_RELIC_H) 1136 # if defined(HAVE_DPVERSION)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
void rb_warn(const char *fmt,...)
#define RUBY_TYPED_FREE_IMMEDIATELY
#define GetDBM2(obj, dbmp, dbm)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_raise(VALUE exc, const char *fmt,...)
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
#define TypedData_Wrap_Struct(klass, data_type, sval)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_ary_clear(VALUE ary)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_obj_as_string(VALUE)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_define_const(VALUE, const char *, VALUE)
void rb_error_frozen(const char *what)
void rb_sys_fail(const char *mesg)
#define RARRAY_CONST_PTR(a)
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
int memcmp(const void *s1, const void *s2, size_t len)
register unsigned int len
#define ExportStringValue(v)
#define RARRAY_AREF(a, i)
void rb_fd_fix_cloexec(int fd)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define GetDBM(obj, dbmp)
VALUE rb_hash_delete_if(VALUE hash)
VALUE rb_tainted_str_new(const char *, long)
void rb_sys_fail_str(VALUE mesg)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)