ext/gdbm/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

Defines

#define TOO_LONG(n)   0
#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 (const 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 (RB_BLOCK_CALL_FUNC_ARGLIST(pair, 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


Define 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 103 of file gdbm.c.

#define GetDBM2 ( obj,
data,
dbm   ) 

Value:

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

Definition at line 109 of file gdbm.c.

#define MY_BLOCK_SIZE   (2048)

Definition at line 84 of file gdbm.c.

Referenced by fgdbm_initialize().

#define MY_FATAL_FUNC   rb_gdbm_fatal

Definition at line 85 of file gdbm.c.

Referenced by fgdbm_initialize().

#define RUBY_GDBM_RW_BIT   0x20000000

Definition at line 82 of file gdbm.c.

Referenced by fgdbm_initialize(), and Init_gdbm().

#define TOO_LONG (  )     0

Definition at line 79 of file gdbm.c.


Function Documentation

static void closed_dbm ( void   )  [static]

Definition at line 98 of file gdbm.c.

References rb_eRuntimeError, and rb_raise().

static VALUE fgdbm_aref ( VALUE  obj,
VALUE  keystr 
) [static]

Definition at line 394 of file gdbm.c.

References rb_gdbm_fetch3().

Referenced by Init_gdbm().

static VALUE fgdbm_clear ( VALUE  obj  )  [static]

Definition at line 631 of file gdbm.c.

References dbmdata::di_size, datum::dptr, free, GetDBM2, if(), 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 130 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 148 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 550 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_delete_if ( VALUE  obj  )  [static]

Definition at line 591 of file gdbm.c.

References dbmdata::di_size, GetDBM2, OBJ_FREEZE, RARRAY_LEN, RARRAY_PTR, rb_ary_clear(), rb_ary_push(), rb_ary_tmp_new(), rb_assoc_new(), rb_gdbm_delete(), rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_modify(), rb_gdbm_nextkey(), rb_jump_tag(), rb_protect(), rb_str_dup(), rb_yield(), RTEST, and VALUE.

Referenced by Init_gdbm().

static VALUE fgdbm_each_key ( VALUE  obj  )  [static]

Definition at line 858 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_each_pair ( VALUE  obj  )  [static]

Definition at line 884 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_each_value ( VALUE  obj  )  [static]

Definition at line 832 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_empty_p ( VALUE  obj  )  [static]

Definition at line 802 of file gdbm.c.

References dbmdata::di_dbm, dbmdata::di_size, free, GetDBM, key, Qfalse, and Qtrue.

Referenced by Init_gdbm().

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

Definition at line 374 of file gdbm.c.

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

Referenced by fgdbm_delete(), and fgdbm_fetch_m().

static VALUE fgdbm_fetch_m ( int  argc,
VALUE *  argv,
VALUE  obj 
) [static]

Definition at line 407 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_has_key ( VALUE  obj,
VALUE  keystr 
) [static]

Definition at line 964 of file gdbm.c.

References GetDBM2, key, len, Qfalse, Qtrue, RSTRING_LENINT, RSTRING_PTR, StringValue, and TOO_LONG.

Referenced by Init_gdbm().

static VALUE fgdbm_has_value ( VALUE  obj,
VALUE  valstr 
) [static]

Definition at line 992 of file gdbm.c.

References GetDBM2, memcmp(), NIL_P, Qfalse, Qtrue, rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), RSTRING_LEN, RSTRING_PTR, RTEST, StringValue, and VALUE.

Referenced by Init_gdbm().

static VALUE fgdbm_index ( VALUE  obj,
VALUE  value 
) [static]

Definition at line 451 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]

Definition at line 191 of file gdbm.c.

References ALLOC, DATA_PTR, dbmdata::di_dbm, dbmdata::di_size, free_dbm(), MY_BLOCK_SIZE, MY_FATAL_FUNC, NIL_P, NUM2INT, Qnil, rb_eGDBMError, rb_fd_fix_cloexec(), rb_raise(), rb_scan_args(), rb_sys_fail_str(), RSTRING_PTR, RUBY_GDBM_RW_BIT, SafeStringValue, and VALUE.

Referenced by fgdbm_s_open(), and Init_gdbm().

static VALUE fgdbm_invert ( VALUE  obj  )  [static]

Definition at line 675 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_key ( VALUE  obj,
VALUE  valstr 
) [static]

Definition at line 427 of file gdbm.c.

References GetDBM2, memcmp(), NIL_P, Qnil, rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), RSTRING_LEN, RSTRING_PTR, RTEST, StringValue, and VALUE.

Referenced by fgdbm_index(), and Init_gdbm().

static VALUE fgdbm_keys ( VALUE  obj  )  [static]

Definition at line 910 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_length ( VALUE  obj  )  [static]

Definition at line 775 of file gdbm.c.

References dbmdata::di_size, free, GetDBM2, INT2FIX, and key.

Referenced by Init_gdbm().

static VALUE fgdbm_reject ( VALUE  obj  )  [static]

Definition at line 1199 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 1048 of file gdbm.c.

References GetDBM2, rb_fd_fix_cloexec(), and rb_gdbm_modify().

Referenced by Init_gdbm().

static VALUE fgdbm_replace ( VALUE  obj,
VALUE  other 
) [static]

Definition at line 760 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 162 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]

Definition at line 280 of file gdbm.c.

References Data_Wrap_Struct, fgdbm_close(), fgdbm_initialize(), free_dbm(), NIL_P, Qnil, rb_block_given_p(), rb_ensure(), rb_yield(), and VALUE.

Referenced by Init_gdbm().

static VALUE fgdbm_select ( VALUE  obj  )  [static]

Definition at line 465 of file gdbm.c.

References GetDBM2, rb_ary_new(), rb_ary_push(), rb_assoc_new(), rb_gdbm_fetch2(), rb_gdbm_firstkey(), rb_gdbm_nextkey(), rb_yield(), RTEST, and VALUE.

Referenced by Init_gdbm().

static VALUE fgdbm_set_cachesize ( VALUE  obj,
VALUE  val 
) [static]

Definition at line 1089 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 1114 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 1145 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 567 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_store ( VALUE  obj,
VALUE  keystr,
VALUE  valstr 
) [static]

Definition at line 700 of file gdbm.c.

References dbmdata::di_size, datum::dptr, datum::dsize, EPERM, errno, GetDBM2, key, rb_eGDBMError, rb_gdbm_modify(), rb_raise(), rb_sys_fail(), RSTRING_LENINT, RSTRING_PTR, StringValue, and val.

Referenced by Init_gdbm(), and update_i().

static VALUE fgdbm_sync ( VALUE  obj  )  [static]

Definition at line 1071 of file gdbm.c.

References GetDBM2, and rb_gdbm_modify().

Referenced by Init_gdbm().

static VALUE fgdbm_to_a ( VALUE  obj  )  [static]

Definition at line 1022 of file gdbm.c.

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

Referenced by Init_gdbm().

static VALUE fgdbm_to_hash ( VALUE  obj  )  [static]

Definition at line 1174 of file gdbm.c.

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

Referenced by fgdbm_reject(), and Init_gdbm().

static VALUE fgdbm_update ( VALUE  obj,
VALUE  other 
) [static]

Definition at line 746 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 934 of file gdbm.c.

References free, GetDBM2, key, rb_ary_new(), rb_ary_push(), rb_gdbm_fetch(), and VALUE.

Referenced by Init_gdbm().

static VALUE fgdbm_values_at ( int  argc,
VALUE *  argv,
VALUE  obj 
) [static]

Definition at line 494 of file gdbm.c.

References rb_ary_new2, rb_ary_push(), rb_gdbm_fetch3(), and VALUE.

Referenced by Init_gdbm().

static void free_dbm ( struct dbmdata dbmp  )  [static]

Definition at line 115 of file gdbm.c.

References dbmdata::di_dbm, and xfree.

void Init_gdbm ( void   ) 

Definition at line 1205 of file gdbm.c.

References fgdbm_aref(), fgdbm_clear(), fgdbm_close(), fgdbm_closed(), fgdbm_delete(), fgdbm_delete_if(), fgdbm_each_key(), fgdbm_each_pair(), fgdbm_each_value(), fgdbm_empty_p(), fgdbm_fetch_m(), fgdbm_has_key(), fgdbm_has_value(), fgdbm_index(), fgdbm_initialize(), fgdbm_invert(), fgdbm_key(), fgdbm_keys(), fgdbm_length(), fgdbm_reject(), fgdbm_reorganize(), fgdbm_replace(), fgdbm_s_alloc(), fgdbm_s_open(), fgdbm_select(), fgdbm_set_cachesize(), fgdbm_set_fastmode(), fgdbm_set_syncmode(), fgdbm_shift(), fgdbm_store(), fgdbm_sync(), fgdbm_to_a(), fgdbm_to_hash(), fgdbm_update(), fgdbm_values(), fgdbm_values_at(), INT2FIX, rb_cGDBM, rb_cObject, rb_define_alloc_func(), rb_define_class(), rb_define_const(), rb_define_method(), rb_define_singleton_method(), rb_eException, rb_eGDBMError, rb_eGDBMFatalError, rb_eStandardError, rb_include_module(), rb_mEnumerable, rb_str_new2, and RUBY_GDBM_RW_BIT.

static VALUE rb_gdbm_delete ( VALUE  obj,
VALUE  keystr 
) [static]

Definition at line 513 of file gdbm.c.

References dbmdata::di_size, GetDBM2, key, len, Qnil, rb_eGDBMError, rb_gdbm_modify(), rb_raise(), RSTRING_LEN, RSTRING_PTR, StringValue, and TOO_LONG.

Referenced by fgdbm_delete(), fgdbm_delete_if(), and fgdbm_shift().

static void rb_gdbm_fatal ( const char *  msg  )  [static]

Definition at line 87 of file gdbm.c.

References rb_eGDBMFatalError, and rb_raise().

static VALUE rb_gdbm_fetch ( GDBM_FILE  dbm,
datum  key 
) [static]

Definition at line 296 of file gdbm.c.

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

Referenced by fgdbm_values(), and rb_gdbm_fetch2().

static VALUE rb_gdbm_fetch2 ( GDBM_FILE  dbm,
VALUE  keystr 
) [static]

Definition at line 312 of file gdbm.c.

References key, len, Qnil, rb_gdbm_fetch(), RSTRING_LEN, RSTRING_PTR, StringValue, and TOO_LONG.

Referenced by fgdbm_delete_if(), fgdbm_each_pair(), fgdbm_each_value(), fgdbm_has_value(), fgdbm_invert(), fgdbm_key(), fgdbm_select(), fgdbm_shift(), fgdbm_to_a(), fgdbm_to_hash(), and rb_gdbm_fetch3().

static VALUE rb_gdbm_fetch3 ( VALUE  obj,
VALUE  keystr 
) [static]

Definition at line 327 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]

Definition at line 337 of file gdbm.c.

References free, key, OBJ_TAINT, Qnil, rb_str_new(), and VALUE.

Referenced by fgdbm_delete_if(), fgdbm_each_key(), fgdbm_each_pair(), fgdbm_each_value(), fgdbm_has_value(), fgdbm_invert(), fgdbm_key(), fgdbm_keys(), fgdbm_select(), fgdbm_shift(), fgdbm_to_a(), and fgdbm_to_hash().

static void rb_gdbm_modify ( VALUE  obj  )  [static]

Definition at line 507 of file gdbm.c.

References OBJ_FROZEN, and rb_error_frozen().

Referenced by fgdbm_clear(), fgdbm_delete_if(), fgdbm_reorganize(), fgdbm_shift(), fgdbm_store(), fgdbm_sync(), and rb_gdbm_delete().

static VALUE rb_gdbm_nextkey ( GDBM_FILE  dbm,
VALUE  keystr 
) [static]

Definition at line 353 of file gdbm.c.

References datum::dptr, datum::dsize, free, key, len, OBJ_TAINT, Qnil, rb_str_new(), RSTRING_LEN, RSTRING_PTR, TOO_LONG, and VALUE.

Referenced by fgdbm_delete_if(), fgdbm_each_key(), fgdbm_each_pair(), fgdbm_each_value(), fgdbm_has_value(), fgdbm_invert(), fgdbm_key(), fgdbm_keys(), fgdbm_select(), fgdbm_to_a(), and fgdbm_to_hash().

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

Definition at line 727 of file gdbm.c.

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


Variable Documentation

VALUE rb_cGDBM [static]

Definition at line 74 of file gdbm.c.

Referenced by Init_gdbm().

VALUE rb_eGDBMError [static]

Definition at line 74 of file gdbm.c.

Referenced by fgdbm_clear(), fgdbm_initialize(), fgdbm_set_cachesize(), fgdbm_set_fastmode(), fgdbm_set_syncmode(), fgdbm_store(), Init_gdbm(), and rb_gdbm_delete().

VALUE rb_eGDBMFatalError [static]

Definition at line 74 of file gdbm.c.

Referenced by Init_gdbm(), and rb_gdbm_fatal().


Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7