Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions | Variables
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
 

Macros

#define DSIZE_TYPE   TYPEOF_DATUM_DSIZE
 
#define RSTRING_DSIZE(s)   RSTRING_LENINT(s)
 
#define TOO_LONG(n)   ((long)(+(DSIZE_TYPE)(n)) != (n))
 
#define RUBY_DBM_RW_BIT   0x20000000
 
#define GetDBM(obj, dbmp)
 
#define GetDBM2(obj, dbmp, dbm)
 
#define O_CLOEXEC   0
 

Functions

static void closed_dbm (void)
 
static void free_dbm (void *ptr)
 
static size_t memsize_dbm (const void *ptr)
 
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 (RB_BLOCK_CALL_FUNC_ARGLIST(pair, 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
 
static const rb_data_type_t dbm_type
 

Macro Definition Documentation

◆ DSIZE_TYPE

#define DSIZE_TYPE   TYPEOF_DATUM_DSIZE

Definition at line 24 of file dbm.c.

Referenced by fdbm_delete(), fdbm_delete_if(), fdbm_fetch(), fdbm_has_key(), fdbm_has_value(), and fdbm_key().

◆ GetDBM

#define GetDBM (   obj,
  dbmp 
)
Value:
do {\
TypedData_Get_Struct((obj), struct dbmdata, &dbm_type, (dbmp));\
if ((dbmp) == 0) closed_dbm();\
if ((dbmp)->di_dbm == 0) closed_dbm();\
} while (0)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: zonetab.h:883
Definition: dbm.c:37
static const rb_data_type_t dbm_type
Definition: dbm.c:81
static void closed_dbm(void)
Definition: dbm.c:43

Definition at line 48 of file dbm.c.

Referenced by fdbm_close().

◆ GetDBM2

#define GetDBM2 (   obj,
  dbmp,
  dbm 
)

◆ O_CLOEXEC

#define O_CLOEXEC   0

◆ RSTRING_DSIZE

#define RSTRING_DSIZE (   s)    RSTRING_LENINT(s)

Definition at line 29 of file dbm.c.

Referenced by fdbm_store().

◆ RUBY_DBM_RW_BIT

#define RUBY_DBM_RW_BIT   0x20000000

Definition at line 35 of file dbm.c.

Referenced by fdbm_initialize(), and Init_dbm().

◆ TOO_LONG

#define TOO_LONG (   n)    ((long)(+(DSIZE_TYPE)(n)) != (n))

Definition at line 30 of file dbm.c.

Referenced by fdbm_delete(), fdbm_fetch(), fdbm_has_key(), fdbm_has_value(), and fdbm_key().

Function Documentation

◆ closed_dbm()

static void closed_dbm ( void  )
static

Definition at line 43 of file dbm.c.

References rb_eDBMError, and rb_raise().

◆ fdbm_alloc()

static VALUE fdbm_alloc ( VALUE  klass)
static

Definition at line 127 of file dbm.c.

References TypedData_Wrap_Struct.

Referenced by fdbm_s_open(), and Init_dbm().

◆ fdbm_aref()

static VALUE fdbm_aref ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 299 of file dbm.c.

References fdbm_fetch(), and Qnil.

Referenced by Init_dbm().

◆ fdbm_clear()

static VALUE fdbm_clear ( VALUE  obj)
static

Definition at line 551 of file dbm.c.

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

Referenced by fdbm_replace(), and Init_dbm().

◆ fdbm_close()

static VALUE fdbm_close ( VALUE  obj)
static

Definition at line 95 of file dbm.c.

References dbmdata::di_dbm, GetDBM, and Qnil.

Referenced by fdbm_s_open(), and Init_dbm().

◆ fdbm_closed()

static VALUE fdbm_closed ( VALUE  obj)
static

Definition at line 113 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_delete()

static VALUE fdbm_delete ( VALUE  obj,
VALUE  keystr 
)
static

◆ fdbm_delete_if()

static VALUE fdbm_delete_if ( VALUE  obj)
static

◆ fdbm_each_key()

static VALUE fdbm_each_key ( VALUE  obj)
static

Definition at line 763 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_each_pair()

static VALUE fdbm_each_pair ( VALUE  obj)
static

Definition at line 787 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_each_value()

static VALUE fdbm_each_value ( VALUE  obj)
static

Definition at line 739 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_empty_p()

static VALUE fdbm_empty_p ( VALUE  obj)
static

Definition at line 711 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_fetch()

static VALUE fdbm_fetch ( VALUE  obj,
VALUE  keystr,
VALUE  ifnone 
)
static

◆ fdbm_fetch_m()

static VALUE fdbm_fetch_m ( int  argc,
VALUE argv,
VALUE  obj 
)
static

Definition at line 313 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().

◆ fdbm_has_key()

static VALUE fdbm_has_key ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 867 of file dbm.c.

References datum::dptr, datum::dsize, DSIZE_TYPE, ExportStringValue, GetDBM2, key, len, Qfalse, Qtrue, RSTRING_LEN, RSTRING_PTR, TOO_LONG, and val.

Referenced by Init_dbm().

◆ fdbm_has_value()

static VALUE fdbm_has_value ( VALUE  obj,
VALUE  valstr 
)
static

Definition at line 895 of file dbm.c.

References datum::dptr, datum::dsize, DSIZE_TYPE, ExportStringValue, GetDBM2, key, len, memcmp(), Qfalse, Qtrue, RSTRING_LEN, RSTRING_PTR, TOO_LONG, and val.

Referenced by Init_dbm().

◆ fdbm_index()

static VALUE fdbm_index ( VALUE  hash,
VALUE  value 
)
static

Definition at line 358 of file dbm.c.

References fdbm_key(), and rb_warn().

Referenced by Init_dbm().

◆ fdbm_initialize()

static VALUE fdbm_initialize ( int  argc,
VALUE argv,
VALUE  obj 
)
static

◆ fdbm_invert()

static VALUE fdbm_invert ( VALUE  obj)
static

Definition at line 578 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_key()

static VALUE fdbm_key ( VALUE  obj,
VALUE  valstr 
)
static

◆ fdbm_keys()

static VALUE fdbm_keys ( VALUE  obj)
static

Definition at line 816 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_length()

static VALUE fdbm_length ( VALUE  obj)
static

Definition at line 686 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_modify()

static void fdbm_modify ( VALUE  obj)
static

Definition at line 415 of file dbm.c.

References OBJ_FROZEN, and rb_error_frozen().

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

◆ fdbm_reject()

static VALUE fdbm_reject ( VALUE  obj)
static

Definition at line 978 of file dbm.c.

References fdbm_to_hash(), and rb_hash_delete_if().

Referenced by Init_dbm().

◆ fdbm_replace()

static VALUE fdbm_replace ( VALUE  obj,
VALUE  other 
)
static

Definition at line 635 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_s_open()

static VALUE fdbm_s_open ( int  argc,
VALUE argv,
VALUE  klass 
)
static

Definition at line 248 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_select()

static VALUE fdbm_select ( VALUE  obj)
static

◆ fdbm_shift()

static VALUE fdbm_shift ( VALUE  obj)
static

Definition at line 473 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_store()

static VALUE fdbm_store ( VALUE  obj,
VALUE  keystr,
VALUE  valstr 
)
static

◆ fdbm_to_a()

static VALUE fdbm_to_a ( VALUE  obj)
static

Definition at line 926 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_to_hash()

static VALUE fdbm_to_hash ( VALUE  obj)
static

Definition at line 952 of file dbm.c.

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

Referenced by fdbm_reject(), and Init_dbm().

◆ fdbm_update()

static VALUE fdbm_update ( VALUE  obj,
VALUE  other 
)
static

Definition at line 620 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_values()

static VALUE fdbm_values ( VALUE  obj)
static

Definition at line 840 of file dbm.c.

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

Referenced by Init_dbm().

◆ fdbm_values_at()

static VALUE fdbm_values_at ( int  argc,
VALUE argv,
VALUE  obj 
)
static

Definition at line 402 of file dbm.c.

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

Referenced by Init_dbm().

◆ free_dbm()

static void free_dbm ( void *  ptr)
static

Definition at line 60 of file dbm.c.

References dbmdata::di_dbm, and xfree().

◆ Init_dbm()

void Init_dbm ( void  )

◆ memsize_dbm()

static size_t memsize_dbm ( const void *  ptr)
static

Definition at line 70 of file dbm.c.

References dbmdata::di_dbm, and size.

◆ update_i()

static VALUE update_i ( RB_BLOCK_CALL_FUNC_ARGLIST(pair, dbm)  )
static

Definition at line 599 of file dbm.c.

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

Referenced by fdbm_replace(), and fdbm_update().

Variable Documentation

◆ dbm_type

const rb_data_type_t dbm_type
static
Initial value:
= {
"dbm",
0, 0,
}
static size_t memsize_dbm(const void *ptr)
Definition: dbm.c:70
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1145
static void free_dbm(void *ptr)
Definition: dbm.c:60

Definition at line 81 of file dbm.c.

◆ rb_cDBM

VALUE rb_cDBM
static

Definition at line 33 of file dbm.c.

Referenced by Init_dbm().

◆ rb_eDBMError

VALUE rb_eDBMError
static

Definition at line 33 of file dbm.c.

Referenced by closed_dbm(), fdbm_clear(), fdbm_delete(), fdbm_delete_if(), fdbm_store(), and Init_dbm().