Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Defines | Functions | Variables

# ext/dbm/dbm.c File Reference

`#include "ruby.h"`
`#include <fcntl.h>`
`#include <errno.h>`
Include dependency graph for dbm.c:

Go to the source code of this file.

## Data Structures
struct | dbmdata
## Defines
#define | RUBY_DBM_RW_BIT 0x20000000
#define | GetDBM(obj, dbmp)
#define | GetDBM2(obj, data, dbm)
## Functions
static void | closed_dbm (void)
static void | free_dbm (struct dbmdata *dbmp)
static VALUE | fdbm_close (VALUE obj)
static VALUE | fdbm_closed (VALUE obj)
static VALUE | fdbm_alloc (VALUE klass)
static VALUE | fdbm_initialize (int argc, VALUE *argv, VALUE obj)
static VALUE | fdbm_s_open (int argc, VALUE *argv, VALUE klass)
static VALUE | fdbm_fetch (VALUE obj, VALUE keystr, VALUE ifnone)
static VALUE | fdbm_aref (VALUE obj, VALUE keystr)
static VALUE | fdbm_fetch_m (int argc, VALUE *argv, VALUE obj)
static VALUE | fdbm_key (VALUE obj, VALUE valstr)
static VALUE | fdbm_index (VALUE hash, VALUE value)
static VALUE | fdbm_select (VALUE obj)
static VALUE | fdbm_values_at (int argc, VALUE *argv, VALUE obj)
static void | fdbm_modify (VALUE obj)
static VALUE | fdbm_delete (VALUE obj, VALUE keystr)
static VALUE | fdbm_shift (VALUE obj)
static VALUE | fdbm_delete_if (VALUE obj)
static VALUE | fdbm_clear (VALUE obj)
static VALUE | fdbm_invert (VALUE obj)
static VALUE | fdbm_store (VALUE, VALUE, VALUE)
static VALUE | update_i (VALUE pair, VALUE dbm)
static VALUE | fdbm_update (VALUE obj, VALUE other)
static VALUE | fdbm_replace (VALUE obj, VALUE other)
static VALUE | fdbm_length (VALUE obj)
static VALUE | fdbm_empty_p (VALUE obj)
static VALUE | fdbm_each_value (VALUE obj)
static VALUE | fdbm_each_key (VALUE obj)
static VALUE | fdbm_each_pair (VALUE obj)
static VALUE | fdbm_keys (VALUE obj)
static VALUE | fdbm_values (VALUE obj)
static VALUE | fdbm_has_key (VALUE obj, VALUE keystr)
static VALUE | fdbm_has_value (VALUE obj, VALUE valstr)
static VALUE | fdbm_to_a (VALUE obj)
static VALUE | fdbm_to_hash (VALUE obj)
static VALUE | fdbm_reject (VALUE obj)
void | Init_dbm (void)
## Variables
static VALUE | rb_cDBM
static VALUE | rb_eDBMError

## Define Documentation

#define GetDBM | ( |  | obj,
|  |  | dbmp
| ) |  |

Value:

    {\
        Data_Get_Struct(obj, struct dbmdata, dbmp);\
        if (dbmp == 0) closed_dbm();\
        if (dbmp->di_dbm == 0) closed_dbm();\
    }

Definition at line 39 of file dbm.c.

Referenced by fdbm_close().

#define GetDBM2 | ( |  | obj,
|  |  | data,
|  |  | dbm
| ) |  |

Value:

    {\
        GetDBM(obj, data);\
        (dbm) = dbmp->di_dbm;\
    }

Definition at line 45 of file dbm.c.

Referenced by fdbm_clear(), fdbm_delete(), fdbm_delete_if(), fdbm_each_key(), fdbm_each_pair(), fdbm_each_value(), fdbm_empty_p(), fdbm_fetch(), fdbm_has_key(), fdbm_has_value(), fdbm_invert(), fdbm_key(), fdbm_keys(), fdbm_length(), fdbm_select(), fdbm_shift(), fdbm_store(), fdbm_to_a(), fdbm_to_hash(), and fdbm_values().

#define RUBY_DBM_RW_BIT 0x20000000

Definition at line 26 of file dbm.c.

Referenced by fdbm_initialize(), and Init_dbm().

## Function Documentation

static void closed_dbm | ( | void |  | ) | `[static]`

Definition at line 34 of file dbm.c.

References rb_eDBMError, and rb_raise().

static VALUE fdbm_alloc | ( | VALUE | klass | ) | `[static]`

Definition at line 86 of file dbm.c.

References Data_Wrap_Struct, and free_dbm().

Referenced by Init_dbm().

static VALUE fdbm_aref | ( | VALUE | obj,
|  | VALUE | keystr
| ) |  | `[static]`

Definition at line 183 of file dbm.c.

References fdbm_fetch(), and Qnil.

Referenced by Init_dbm().

static VALUE fdbm_clear | ( | VALUE | obj | ) | `[static]`

Definition at line 371 of file dbm.c.

References dbmdata::di_size, datum::dptr, fdbm_modify(), GetDBM2, rb_eDBMError, and rb_raise().

Referenced by fdbm_replace(), and Init_dbm().

static VALUE fdbm_close | ( | VALUE | obj | ) | `[static]`

Definition at line 60 of file dbm.c.

References dbmdata::di_dbm, GetDBM, and Qnil.

Referenced by fdbm_s_open(), and Init_dbm().

static VALUE fdbm_closed | ( | VALUE | obj | ) | `[static]`

Definition at line 72 of file dbm.c.

References Data_Get_Struct, dbmdata::di_dbm, Qfalse, and Qtrue.

Referenced by Init_dbm().

static VALUE fdbm_delete | ( | VALUE | obj,
|  | VALUE | keystr
| ) |  | `[static]`

Definition at line 275 of file dbm.c.

References dbmdata::di_size, datum::dptr, datum::dsize, ExportStringValue, fdbm_modify(), GetDBM2, Qnil, rb_block_given_p(), rb_eDBMError, rb_raise(), rb_tainted_str_new(), rb_yield(), RSTRING_LEN, and RSTRING_PTR.

Referenced by Init_dbm().

static VALUE fdbm_delete_if | ( | VALUE | obj | ) | `[static]`

Definition at line 331 of file dbm.c.

References dbmdata::di_size, datum::dptr, datum::dsize, ExportStringValue, fdbm_modify(), GetDBM2, RARRAY_LEN, RARRAY_PTR, rb_ary_new(), rb_ary_push(), rb_assoc_new(), rb_eDBMError, rb_jump_tag(), rb_protect(), rb_raise(), rb_str_dup(), rb_tainted_str_new(), rb_yield(), RSTRING_LEN, RSTRING_PTR, and RTEST.

Referenced by Init_dbm().

static VALUE fdbm_each_key | ( | VALUE | obj | ) | `[static]`

Definition at line 528 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_tainted_str_new(), rb_yield(), and RETURN_ENUMERATOR.

Referenced by Init_dbm().

static VALUE fdbm_each_pair | ( | VALUE | obj | ) | `[static]`

Definition at line 545 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_assoc_new(), rb_tainted_str_new(), rb_yield(), and RETURN_ENUMERATOR.

Referenced by Init_dbm().

static VALUE fdbm_each_value | ( | VALUE | obj | ) | `[static]`

Definition at line 510 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_tainted_str_new(), rb_yield(), and RETURN_ENUMERATOR.

Referenced by Init_dbm().

static VALUE fdbm_empty_p | ( | VALUE | obj | ) | `[static]`

Definition at line 487 of file dbm.c.

References dbmdata::di_dbm, dbmdata::di_size, datum::dptr, GetDBM2, Qfalse, and Qtrue.

Referenced by Init_dbm().

static VALUE fdbm_fetch | ( | VALUE | obj,
|  | VALUE | keystr,
|  | VALUE | ifnone
| ) |  | `[static]`

Definition at line 162 of file dbm.c.

References datum::dptr, datum::dsize, ExportStringValue, GetDBM2, Qnil, rb_block_given_p(), rb_tainted_str_new(), rb_yield(), RSTRING_LEN, and RSTRING_PTR.

Referenced by fdbm_aref(), fdbm_fetch_m(), and fdbm_values_at().

static VALUE fdbm_fetch_m | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 189 of file dbm.c.

References fdbm_fetch(), NIL_P, rb_block_given_p(), rb_eIndexError, rb_raise(), and rb_scan_args().

Referenced by Init_dbm().

static VALUE fdbm_has_key | ( | VALUE | obj,
|  | VALUE | keystr
| ) |  | `[static]`

Definition at line 604 of file dbm.c.

References datum::dptr, datum::dsize, ExportStringValue, GetDBM2, Qfalse, Qtrue, RSTRING_LEN, and RSTRING_PTR.

Referenced by Init_dbm().

static VALUE fdbm_has_value | ( | VALUE | obj,
|  | VALUE | valstr
| ) |  | `[static]`

Definition at line 621 of file dbm.c.

References datum::dptr, datum::dsize, ExportStringValue, GetDBM2, memcmp(), Qfalse, Qtrue, RSTRING_LEN, and RSTRING_PTR.

Referenced by Init_dbm().

static VALUE fdbm_index | ( | VALUE | hash,
|  | VALUE | value
| ) |  | `[static]`

Definition at line 224 of file dbm.c.

References fdbm_key(), and rb_warn().

Referenced by Init_dbm().

static VALUE fdbm_initialize | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 92 of file dbm.c.

References ALLOC, DATA_PTR, dbmdata::di_dbm, dbmdata::di_size, FilePathValue, NIL_P, NUM2INT, Qnil, rb_scan_args(), rb_sys_fail(), RSTRING_PTR, and RUBY_DBM_RW_BIT.

Referenced by fdbm_s_open(), and Init_dbm().

static VALUE fdbm_invert | ( | VALUE | obj | ) | `[static]`

Definition at line 391 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, hash(), rb_hash_aset(), rb_hash_new(), and rb_tainted_str_new().

Referenced by Init_dbm().

static VALUE fdbm_key | ( | VALUE | obj,
|  | VALUE | valstr
| ) |  | `[static]`

Definition at line 202 of file dbm.c.

References datum::dptr, datum::dsize, ExportStringValue, GetDBM2, memcmp(), Qnil, rb_tainted_str_new(), RSTRING_LEN, and RSTRING_PTR.

Referenced by fdbm_index(), and Init_dbm().

static VALUE fdbm_keys | ( | VALUE | obj | ) | `[static]`

Definition at line 568 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_ary_new(), rb_ary_push(), and rb_tainted_str_new().

Referenced by Init_dbm().

static VALUE fdbm_length | ( | VALUE | obj | ) | `[static]`

Definition at line 468 of file dbm.c.

References dbmdata::di_size, datum::dptr, GetDBM2, and INT2FIX.

Referenced by Init_dbm().

static void fdbm_modify | ( | VALUE | obj | ) | `[static]`

Definition at line 268 of file dbm.c.

References OBJ_FROZEN, rb_error_frozen(), and rb_secure().

Referenced by fdbm_clear(), fdbm_delete(), fdbm_delete_if(), fdbm_shift(), and fdbm_store().

static VALUE fdbm_reject | ( | VALUE | obj | ) | `[static]`

Definition at line 680 of file dbm.c.

References fdbm_to_hash(), and rb_hash_delete_if().

Referenced by Init_dbm().

static VALUE fdbm_replace | ( | VALUE | obj,
|  | VALUE | other
| ) |  | `[static]`

Definition at line 430 of file dbm.c.

References fdbm_clear(), rb_block_call, rb_intern, and update_i().

Referenced by Init_dbm().

static VALUE fdbm_s_open | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | klass
| ) |  | `[static]`

Definition at line 146 of file dbm.c.

References Data_Wrap_Struct, fdbm_close(), fdbm_initialize(), free_dbm(), NIL_P, Qnil, rb_block_given_p(), rb_ensure(), and rb_yield().

Referenced by Init_dbm().

static VALUE fdbm_select | ( | VALUE | obj | ) | `[static]`

Definition at line 231 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_ary_new(), rb_ary_push(), rb_assoc_new(), rb_tainted_str_new(), rb_yield(), and RTEST.

Referenced by Init_dbm().

static VALUE fdbm_shift | ( | VALUE | obj | ) | `[static]`

Definition at line 309 of file dbm.c.

References dbmdata::di_size, datum::dptr, datum::dsize, fdbm_modify(), GetDBM2, Qnil, rb_assoc_new(), and rb_tainted_str_new().

Referenced by Init_dbm().

static VALUE fdbm_store | ( | VALUE | obj,
|  | VALUE | keystr,
|  | VALUE | valstr
| ) |  | `[static]`

Definition at line 438 of file dbm.c.

References DBM_REPLACE, dbmdata::di_size, datum::dptr, datum::dsize, EPERM, errno, fdbm_modify(), GetDBM2, rb_eDBMError, rb_obj_as_string(), rb_raise(), rb_sys_fail(), RSTRING_LEN, and RSTRING_PTR.

Referenced by Init_dbm(), and update_i().

static VALUE fdbm_to_a | ( | VALUE | obj | ) | `[static]`

Definition at line 642 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_ary_new(), rb_ary_push(), rb_assoc_new(), and rb_tainted_str_new().

Referenced by Init_dbm().

static VALUE fdbm_to_hash | ( | VALUE | obj | ) | `[static]`

Definition at line 661 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, hash(), rb_hash_aset(), rb_hash_new(), and rb_tainted_str_new().

Referenced by fdbm_reject(), and Init_dbm().

static VALUE fdbm_update | ( | VALUE | obj,
|  | VALUE | other
| ) |  | `[static]`

Definition at line 423 of file dbm.c.

References rb_block_call, rb_intern, and update_i().

Referenced by Init_dbm().

static VALUE fdbm_values | ( | VALUE | obj | ) | `[static]`

Definition at line 586 of file dbm.c.

References datum::dptr, datum::dsize, GetDBM2, rb_ary_new(), rb_ary_push(), and rb_tainted_str_new().

Referenced by Init_dbm().

static VALUE fdbm_values_at | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 255 of file dbm.c.

References argc, fdbm_fetch(), Qnil, rb_ary_new2(), and rb_ary_push().

Referenced by Init_dbm().

static void free_dbm | ( | struct dbmdata * | dbmp | ) | `[static]`

Definition at line 51 of file dbm.c.

References dbmdata::di_dbm, and xfree().

Referenced by fdbm_alloc(), and fdbm_s_open().

void Init_dbm | ( | void |  | ) |

Definition at line 686 of file dbm.c.

References fdbm_alloc(), fdbm_aref(), fdbm_clear(), fdbm_close(), fdbm_closed(), fdbm_delete(), fdbm_delete_if(), fdbm_each_key(), fdbm_each_pair(), fdbm_each_value(), fdbm_empty_p(), fdbm_fetch_m(), fdbm_has_key(), fdbm_has_value(), fdbm_index(), fdbm_initialize(), fdbm_invert(), fdbm_key(), fdbm_keys(), fdbm_length(), fdbm_reject(), fdbm_replace(), fdbm_s_open(), fdbm_select(), fdbm_shift(), fdbm_store(), fdbm_to_a(), fdbm_to_hash(), fdbm_update(), fdbm_values(), fdbm_values_at(), INT2FIX, rb_cDBM, rb_cObject, rb_define_alloc_func(), rb_define_class(), rb_define_const(), rb_define_method(), rb_define_singleton_method(), rb_eDBMError, rb_eStandardError, rb_include_module(), rb_mEnumerable, rb_str_new2(), and RUBY_DBM_RW_BIT.

static VALUE update_i | ( | VALUE | pair,
|  | VALUE | dbm
| ) |  | `[static]`

Definition at line 412 of file dbm.c.

References Check_Type, fdbm_store(), Qnil, RARRAY_LEN, RARRAY_PTR, rb_eArgError, rb_raise(), and T_ARRAY.

Referenced by fdbm_replace(), and fdbm_update().

## Variable Documentation

VALUE rb_cDBM`[static]`

Definition at line 24 of file dbm.c.

Referenced by Init_dbm().

VALUE rb_eDBMError

Definition at line 24 of file dbm.c.

Referenced by closed_dbm(), closed_sdbm(), fdbm_clear(), fdbm_delete(), fdbm_delete_if(), fdbm_store(), fsdbm_clear(), fsdbm_delete(), fsdbm_delete_if(), fsdbm_store(), Init_dbm(), and Init_sdbm().