Ruby  1.9.3p551(2014-11-13revision48407)
Data Structures | Macros | Functions | Variables
gdbm.c File Reference
#include "ruby.h"
#include <gdbm.h>
#include <fcntl.h>
#include <errno.h>

Go to the source code of this file.

Data Structures

struct  dbmdata
 

Macros

#define RUBY_GDBM_RW_BIT   0x20000000
 
#define MY_BLOCK_SIZE   (2048)
 
#define MY_FATAL_FUNC   rb_gdbm_fatal
 
#define GetDBM(obj, dbmp)
 
#define GetDBM2(obj, data, dbm)
 

Functions

static void rb_gdbm_fatal (char *msg)
 
static void closed_dbm (void)
 
static void free_dbm (struct dbmdata *dbmp)
 
static VALUE fgdbm_close (VALUE obj)
 
static VALUE fgdbm_closed (VALUE obj)
 
static VALUE fgdbm_s_alloc (VALUE klass)
 
static VALUE fgdbm_initialize (int argc, VALUE *argv, VALUE obj)
 
static VALUE fgdbm_s_open (int argc, VALUE *argv, VALUE klass)
 
static VALUE rb_gdbm_fetch (GDBM_FILE dbm, datum key)
 
static VALUE rb_gdbm_fetch2 (GDBM_FILE dbm, VALUE keystr)
 
static VALUE rb_gdbm_fetch3 (VALUE obj, VALUE keystr)
 
static VALUE rb_gdbm_firstkey (GDBM_FILE dbm)
 
static VALUE rb_gdbm_nextkey (GDBM_FILE dbm, VALUE keystr)
 
static VALUE fgdbm_fetch (VALUE obj, VALUE keystr, VALUE ifnone)
 
static VALUE fgdbm_aref (VALUE obj, VALUE keystr)
 
static VALUE fgdbm_fetch_m (int argc, VALUE *argv, VALUE obj)
 
static VALUE fgdbm_key (VALUE obj, VALUE valstr)
 
static VALUE fgdbm_index (VALUE obj, VALUE value)
 
static VALUE fgdbm_select (VALUE obj)
 
static VALUE fgdbm_values_at (int argc, VALUE *argv, VALUE obj)
 
static void rb_gdbm_modify (VALUE obj)
 
static VALUE rb_gdbm_delete (VALUE obj, VALUE keystr)
 
static VALUE fgdbm_delete (VALUE obj, VALUE keystr)
 
static VALUE fgdbm_shift (VALUE obj)
 
static VALUE fgdbm_delete_if (VALUE obj)
 
static VALUE fgdbm_clear (VALUE obj)
 
static VALUE fgdbm_invert (VALUE obj)
 
static VALUE fgdbm_store (VALUE obj, VALUE keystr, VALUE valstr)
 
static VALUE update_i (VALUE pair, VALUE dbm)
 
static VALUE fgdbm_update (VALUE obj, VALUE other)
 
static VALUE fgdbm_replace (VALUE obj, VALUE other)
 
static VALUE fgdbm_length (VALUE obj)
 
static VALUE fgdbm_empty_p (VALUE obj)
 
static VALUE fgdbm_each_value (VALUE obj)
 
static VALUE fgdbm_each_key (VALUE obj)
 
static VALUE fgdbm_each_pair (VALUE obj)
 
static VALUE fgdbm_keys (VALUE obj)
 
static VALUE fgdbm_values (VALUE obj)
 
static VALUE fgdbm_has_key (VALUE obj, VALUE keystr)
 
static VALUE fgdbm_has_value (VALUE obj, VALUE valstr)
 
static VALUE fgdbm_to_a (VALUE obj)
 
static VALUE fgdbm_reorganize (VALUE obj)
 
static VALUE fgdbm_sync (VALUE obj)
 
static VALUE fgdbm_set_cachesize (VALUE obj, VALUE val)
 
static VALUE fgdbm_set_fastmode (VALUE obj, VALUE val)
 
static VALUE fgdbm_set_syncmode (VALUE obj, VALUE val)
 
static VALUE fgdbm_to_hash (VALUE obj)
 
static VALUE fgdbm_reject (VALUE obj)
 
void Init_gdbm (void)
 

Variables

static VALUE rb_cGDBM
 
static VALUE rb_eGDBMError
 
static VALUE rb_eGDBMFatalError
 

Macro Definition Documentation

#define GetDBM (   obj,
  dbmp 
)
Value:
do {\
Data_Get_Struct((obj), struct dbmdata, (dbmp));\
if ((dbmp) == 0) closed_dbm();\
if ((dbmp)->di_dbm == 0) closed_dbm();\
} while (0)

Definition at line 97 of file gdbm.c.

Referenced by fgdbm_close(), and fgdbm_empty_p().

#define GetDBM2 (   obj,
  data,
  dbm 
)
#define MY_BLOCK_SIZE   (2048)

Definition at line 78 of file gdbm.c.

Referenced by fgdbm_initialize().

#define MY_FATAL_FUNC   rb_gdbm_fatal

Definition at line 79 of file gdbm.c.

Referenced by fgdbm_initialize().

#define RUBY_GDBM_RW_BIT   0x20000000

Definition at line 76 of file gdbm.c.

Referenced by fgdbm_initialize(), and Init_gdbm().

Function Documentation

static void closed_dbm ( void  )
static

Definition at line 92 of file gdbm.c.

References rb_eRuntimeError, and rb_raise().

static VALUE fgdbm_aref ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 373 of file gdbm.c.

References rb_gdbm_fetch3().

Referenced by Init_gdbm().

static VALUE fgdbm_clear ( VALUE  obj)
static

Definition at line 606 of file gdbm.c.

References dbmdata::di_size, datum::dptr, free(), GetDBM2, key, rb_eGDBMError, rb_gdbm_modify(), and rb_raise().

Referenced by fgdbm_replace(), and Init_gdbm().

static VALUE fgdbm_close ( VALUE  obj)
static

Definition at line 124 of file gdbm.c.

References dbmdata::di_dbm, GetDBM, and Qnil.

Referenced by fgdbm_s_open(), and Init_gdbm().

static VALUE fgdbm_closed ( VALUE  obj)
static

Definition at line 142 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_delete ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 527 of file gdbm.c.

References fgdbm_fetch(), Qnil, and rb_gdbm_delete().

Referenced by Init_gdbm().

static VALUE fgdbm_delete_if ( VALUE  obj)
static
static VALUE fgdbm_each_key ( VALUE  obj)
static

Definition at line 833 of file gdbm.c.

References GetDBM2, rb_gdbm_firstkey(), rb_gdbm_nextkey(), rb_yield(), RETURN_ENUMERATOR, and RTEST.

Referenced by Init_gdbm().

static VALUE fgdbm_each_pair ( VALUE  obj)
static
static VALUE fgdbm_each_value ( VALUE  obj)
static

Definition at line 807 of file gdbm.c.

References GetDBM2, rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), rb_yield(), RETURN_ENUMERATOR, and RTEST.

Referenced by Init_gdbm().

static VALUE fgdbm_empty_p ( VALUE  obj)
static

Definition at line 777 of file gdbm.c.

References dbmdata::di_dbm, dbmdata::di_size, datum::dptr, free(), GetDBM, key, Qfalse, and Qtrue.

Referenced by Init_gdbm().

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

Definition at line 353 of file gdbm.c.

References NIL_P, Qnil, rb_block_given_p(), rb_gdbm_fetch3(), and rb_yield().

Referenced by fgdbm_delete(), and fgdbm_fetch_m().

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

Definition at line 386 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_has_key ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 937 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_has_value ( VALUE  obj,
VALUE  valstr 
)
static
static VALUE fgdbm_index ( VALUE  obj,
VALUE  value 
)
static

Definition at line 430 of file gdbm.c.

References fgdbm_key(), and rb_warn().

Referenced by Init_gdbm().

static VALUE fgdbm_initialize ( int  argc,
VALUE argv,
VALUE  obj 
)
static
static VALUE fgdbm_invert ( VALUE  obj)
static

Definition at line 650 of file gdbm.c.

References GetDBM2, hash(), rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), rb_hash_aset(), rb_hash_new(), and RTEST.

Referenced by Init_gdbm().

static VALUE fgdbm_key ( VALUE  obj,
VALUE  valstr 
)
static
static VALUE fgdbm_keys ( VALUE  obj)
static

Definition at line 885 of file gdbm.c.

References GetDBM2, rb_ary_new(), rb_ary_push(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), and RTEST.

Referenced by Init_gdbm().

static VALUE fgdbm_length ( VALUE  obj)
static

Definition at line 750 of file gdbm.c.

References dbmdata::di_size, datum::dptr, free(), GetDBM2, i, INT2FIX, and key.

Referenced by Init_gdbm().

static VALUE fgdbm_reject ( VALUE  obj)
static

Definition at line 1168 of file gdbm.c.

References fgdbm_to_hash(), and rb_hash_delete_if().

Referenced by Init_gdbm().

static VALUE fgdbm_reorganize ( VALUE  obj)
static

Definition at line 1018 of file gdbm.c.

References GetDBM2, and rb_gdbm_modify().

Referenced by Init_gdbm().

static VALUE fgdbm_replace ( VALUE  obj,
VALUE  other 
)
static

Definition at line 735 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_s_alloc ( VALUE  klass)
static

Definition at line 156 of file gdbm.c.

References Data_Wrap_Struct, and free_dbm().

Referenced by Init_gdbm().

static VALUE fgdbm_s_open ( int  argc,
VALUE argv,
VALUE  klass 
)
static
static VALUE fgdbm_select ( VALUE  obj)
static
static VALUE fgdbm_set_cachesize ( VALUE  obj,
VALUE  val 
)
static

Definition at line 1058 of file gdbm.c.

References FIX2INT, GetDBM2, rb_eGDBMError, and rb_raise().

Referenced by Init_gdbm().

static VALUE fgdbm_set_fastmode ( VALUE  obj,
VALUE  val 
)
static

Definition at line 1083 of file gdbm.c.

References GetDBM2, rb_eGDBMError, rb_raise(), and RTEST.

Referenced by fgdbm_set_syncmode(), and Init_gdbm().

static VALUE fgdbm_set_syncmode ( VALUE  obj,
VALUE  val 
)
static

Definition at line 1114 of file gdbm.c.

References fgdbm_set_fastmode(), GetDBM2, Qfalse, Qtrue, rb_eGDBMError, rb_raise(), and RTEST.

Referenced by Init_gdbm().

static VALUE fgdbm_shift ( VALUE  obj)
static

Definition at line 544 of file gdbm.c.

References GetDBM2, NIL_P, Qnil, rb_assoc_new(), rb_gdbm_delete(), rb_gdbm_fetch2(), rb_gdbm_firstkey(), and rb_gdbm_modify().

Referenced by Init_gdbm().

static VALUE fgdbm_store ( VALUE  obj,
VALUE  keystr,
VALUE  valstr 
)
static
static VALUE fgdbm_sync ( VALUE  obj)
static

Definition at line 1040 of file gdbm.c.

References GetDBM2, and rb_gdbm_modify().

Referenced by Init_gdbm().

static VALUE fgdbm_to_a ( VALUE  obj)
static
static VALUE fgdbm_to_hash ( VALUE  obj)
static
static VALUE fgdbm_update ( VALUE  obj,
VALUE  other 
)
static

Definition at line 721 of file gdbm.c.

References rb_block_call, rb_intern, and update_i().

Referenced by Init_gdbm().

static VALUE fgdbm_values ( VALUE  obj)
static

Definition at line 909 of file gdbm.c.

References datum::dptr, free(), GetDBM2, key, rb_ary_new(), rb_ary_push(), and rb_gdbm_fetch().

Referenced by Init_gdbm().

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

Definition at line 473 of file gdbm.c.

References argc, i, rb_ary_new2(), rb_ary_push(), and rb_gdbm_fetch3().

Referenced by Init_gdbm().

static void free_dbm ( struct dbmdata dbmp)
static

Definition at line 109 of file gdbm.c.

References dbmdata::di_dbm, and xfree().

Referenced by fgdbm_initialize(), fgdbm_s_alloc(), and fgdbm_s_open().

void Init_gdbm ( void  )
static VALUE rb_gdbm_delete ( VALUE  obj,
VALUE  keystr 
)
static
static void rb_gdbm_fatal ( char *  msg)
static

Definition at line 81 of file gdbm.c.

References rb_eGDBMFatalError, and rb_raise().

static VALUE rb_gdbm_fetch ( GDBM_FILE  dbm,
datum  key 
)
static

Definition at line 281 of file gdbm.c.

References datum::dptr, datum::dsize, free(), OBJ_TAINT, Qnil, and rb_str_new().

Referenced by fgdbm_values(), and rb_gdbm_fetch2().

static VALUE rb_gdbm_fetch2 ( GDBM_FILE  dbm,
VALUE  keystr 
)
static
static VALUE rb_gdbm_fetch3 ( VALUE  obj,
VALUE  keystr 
)
static

Definition at line 309 of file gdbm.c.

References GetDBM2, and rb_gdbm_fetch2().

Referenced by fgdbm_aref(), fgdbm_fetch(), and fgdbm_values_at().

static VALUE rb_gdbm_firstkey ( GDBM_FILE  dbm)
static
static void rb_gdbm_modify ( VALUE  obj)
static
static VALUE rb_gdbm_nextkey ( GDBM_FILE  dbm,
VALUE  keystr 
)
static
static VALUE update_i ( VALUE  pair,
VALUE  dbm 
)
static

Definition at line 702 of file gdbm.c.

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

Referenced by fgdbm_replace(), and fgdbm_update().

Variable Documentation

VALUE rb_cGDBM
static

Definition at line 74 of file gdbm.c.

Referenced by Init_gdbm().

VALUE rb_eGDBMError
static
VALUE rb_eGDBMFatalError
static

Definition at line 74 of file gdbm.c.

Referenced by Init_gdbm(), and rb_gdbm_fatal().