Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Functions | Variables
hash.c File Reference
#include "internal.h"
#include "ruby/st.h"
#include "ruby/util.h"
#include <errno.h>
#include "probes.h"
#include "id.h"
#include "symbol.h"
#include "gc.h"

Go to the source code of this file.

Data Structures

struct  foreach_safe_arg
 
struct  hash_foreach_arg
 
struct  update_callback_arg
 
struct  update_arg
 
struct  rehash_arg
 
struct  shift_var
 
struct  equal_data
 
struct  update_func_arg
 
struct  reset_hash_type_arg
 

Macros

#define HAS_EXTRA_STATES(hash, klass)
 
#define SET_DEFAULT(hash, ifnone)
 
#define SET_PROC_DEFAULT(hash, proc)   set_proc_default(hash, proc)
 
#define COPY_DEFAULT(hash, hash2)   copy_default(RHASH(hash), RHASH(hash2))
 
#define rb_ident_cmp   st_numcmp
 
#define NOINSERT_UPDATE_CALLBACK(func)
 
#define UPDATE_CALLBACK(iter_lev, func)   ((iter_lev) > 0 ? func##_noinsert : func##_insert)
 
#define RHASH_UPDATE_ITER(h, iter_lev, key, func, a)
 
#define RHASH_UPDATE(hash, key, func, arg)   RHASH_UPDATE_ITER(hash, RHASH_ITER_LEV(hash), key, func, arg)
 
#define GET_ENVIRON(e)   (e)
 
#define FREE_ENVIRON(e)
 
#define ENVMATCH(n1, n2)   (strcmp((n1), (n2)) == 0)
 
#define ENVNMATCH(s1, s2, n)   (memcmp((s1), (s2), (n)) == 0)
 
#define get_env_ptr(var, val)   (var = get_env_cstr(val, #var))
 
#define env_name(s)   env_name(&(s))
 
#define rb_intern(str)   rb_intern_const(str)
 

Typedefs

typedef int st_foreach_func(st_data_t, st_data_t, st_data_t)
 
typedef int rb_foreach_func(VALUE, VALUE, VALUE)
 
typedef int(* tbl_update_func) (st_data_t *, st_data_t *, st_data_t, int)
 

Functions

VALUE rb_hash_freeze (VALUE hash)
 
VALUE rb_hash_set_ifnone (VALUE hash, VALUE ifnone)
 
VALUE rb_hash (VALUE obj)
 
long rb_objid_hash (st_index_t index)
 
long rb_dbl_long_hash (double d)
 
VALUE rb_obj_hash (VALUE obj)
 
void st_foreach_safe (st_table *table, int(*func)(ANYARGS), st_data_t a)
 
void rb_hash_foreach (VALUE hash, int(*func)(ANYARGS), VALUE farg)
 
VALUE rb_hash_new (void)
 
VALUE rb_hash_new_with_size (st_index_t size)
 
VALUE rb_hash_dup (VALUE hash)
 
struct st_tablerb_hash_tbl (VALUE hash)
 
struct st_tablerb_hash_tbl_raw (VALUE hash)
 
 NORETURN (static void no_new_key(void))
 
VALUE rb_check_hash_type (VALUE hash)
 
VALUE rb_hash_rehash (VALUE hash)
 
VALUE rb_hash_default_value (VALUE hash, VALUE key)
 
VALUE rb_hash_aref (VALUE hash, VALUE key)
 
VALUE rb_hash_lookup2 (VALUE hash, VALUE key, VALUE def)
 
VALUE rb_hash_lookup (VALUE hash, VALUE key)
 
VALUE rb_hash_fetch (VALUE hash, VALUE key)
 
VALUE rb_hash_set_default_proc (VALUE hash, VALUE proc)
 
VALUE rb_hash_delete_entry (VALUE hash, VALUE key)
 
VALUE rb_hash_delete (VALUE hash, VALUE key)
 
VALUE rb_hash_delete_if (VALUE hash)
 
VALUE rb_hash_reject_bang (VALUE hash)
 
VALUE rb_hash_reject (VALUE hash)
 
VALUE rb_hash_values_at (int argc, VALUE *argv, VALUE hash)
 
VALUE rb_hash_fetch_values (int argc, VALUE *argv, VALUE hash)
 
VALUE rb_hash_select (VALUE hash)
 
VALUE rb_hash_select_bang (VALUE hash)
 
VALUE rb_hash_keep_if (VALUE hash)
 
VALUE rb_hash_clear (VALUE hash)
 
VALUE rb_hash_aset (VALUE hash, VALUE key, VALUE val)
 
VALUE rb_hash_size (VALUE hash)
 
VALUE rb_hash_keys (VALUE hash)
 
VALUE rb_hash_values (VALUE hash)
 
VALUE rb_hash_has_key (VALUE hash, VALUE key)
 
VALUE rb_hash_update_by (VALUE hash1, VALUE hash2, rb_hash_update_func *func)
 
VALUE rb_hash_assoc (VALUE hash, VALUE key)
 
VALUE rb_hash_rassoc (VALUE hash, VALUE obj)
 
VALUE rb_hash_compare_by_id_p (VALUE hash)
 
VALUE rb_ident_hash_new (void)
 
st_tablerb_init_identtable (void)
 
st_tablerb_init_identtable_with_size (st_index_t size)
 
VALUE rb_hash_dig (int argc, VALUE *argv, VALUE self)
 
int rb_hash_add_new_element (VALUE hash, VALUE key, VALUE val)
 
int rb_env_path_tainted (void)
 
void ruby_setenv (const char *name, const char *value)
 
void ruby_unsetenv (const char *name)
 
VALUE rb_env_clear (void)
 
void Init_Hash (void)
 

Variables

VALUE rb_cHash
 
char ** environ
 

Macro Definition Documentation

◆ COPY_DEFAULT

#define COPY_DEFAULT (   hash,
  hash2 
)    copy_default(RHASH(hash), RHASH(hash2))

Definition at line 42 of file hash.c.

◆ env_name

#define env_name (   s)    env_name(&(s))

Definition at line 3308 of file hash.c.

◆ ENVMATCH

#define ENVMATCH (   n1,
  n2 
)    (strcmp((n1), (n2)) == 0)

Definition at line 3199 of file hash.c.

◆ ENVNMATCH

#define ENVNMATCH (   s1,
  s2,
 
)    (memcmp((s1), (s2), (n)) == 0)

Definition at line 3200 of file hash.c.

◆ FREE_ENVIRON

#define FREE_ENVIRON (   e)

Definition at line 3193 of file hash.c.

◆ get_env_ptr

#define get_env_ptr (   var,
  val 
)    (var = get_env_cstr(val, #var))

Definition at line 3295 of file hash.c.

◆ GET_ENVIRON

#define GET_ENVIRON (   e)    (e)

Definition at line 3192 of file hash.c.

Referenced by ruby_setenv().

◆ HAS_EXTRA_STATES

#define HAS_EXTRA_STATES (   hash,
  klass 
)
Value:
( \
((klass = has_extra_methods(rb_obj_class(hash))) != 0) || \
FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \
#define FL_EXIVAR
Definition: ruby.h:1215
#define FL_TAINT
Definition: ruby.h:1213
#define RHASH_IFNONE(h)
Definition: ruby.h:1058
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
Definition: object.c:277
#define NIL_P(v)
Definition: ruby.h:451
#define HASH_PROC_DEFAULT
Definition: internal.h:1273

Definition at line 31 of file hash.c.

◆ NOINSERT_UPDATE_CALLBACK

#define NOINSERT_UPDATE_CALLBACK (   func)
Value:
static int \
func##_noinsert(st_data_t *key, st_data_t *val, st_data_t arg, int existing) \
{ \
if (!existing) no_new_key(); \
return func(key, val, (struct update_arg *)arg, existing); \
} \
\
static int \
func##_insert(st_data_t *key, st_data_t *val, st_data_t arg, int existing) \
{ \
return func(key, val, (struct update_arg *)arg, existing); \
}
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
#define val

Definition at line 506 of file hash.c.

◆ rb_ident_cmp

#define rb_ident_cmp   st_numcmp

Definition at line 269 of file hash.c.

◆ rb_intern

#define rb_intern (   str)    rb_intern_const(str)

Referenced by Init_Hash().

◆ RHASH_UPDATE

#define RHASH_UPDATE (   hash,
  key,
  func,
  arg 
)    RHASH_UPDATE_ITER(hash, RHASH_ITER_LEV(hash), key, func, arg)

Definition at line 559 of file hash.c.

◆ RHASH_UPDATE_ITER

#define RHASH_UPDATE_ITER (   h,
  iter_lev,
  key,
  func,
 
)
Value:
do { \
tbl_update((h), (key), UPDATE_CALLBACK((iter_lev), func), (st_data_t)(a)); \
} while (0)
#define UPDATE_CALLBACK(iter_lev, func)
Definition: hash.c:553
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22

Definition at line 555 of file hash.c.

◆ SET_DEFAULT

#define SET_DEFAULT (   hash,
  ifnone 
)
Value:
( \
FL_UNSET_RAW(hash, HASH_PROC_DEFAULT), \
RHASH_SET_IFNONE(hash, ifnone))
#define HASH_PROC_DEFAULT
Definition: internal.h:1273

Definition at line 36 of file hash.c.

◆ SET_PROC_DEFAULT

#define SET_PROC_DEFAULT (   hash,
  proc 
)    set_proc_default(hash, proc)

Definition at line 40 of file hash.c.

◆ UPDATE_CALLBACK

#define UPDATE_CALLBACK (   iter_lev,
  func 
)    ((iter_lev) > 0 ? func##_noinsert : func##_insert)

Definition at line 553 of file hash.c.

Typedef Documentation

◆ rb_foreach_func

typedef int rb_foreach_func(VALUE, VALUE, VALUE)

Definition at line 328 of file hash.c.

◆ st_foreach_func

typedef int st_foreach_func(st_data_t, st_data_t, st_data_t)

Definition at line 293 of file hash.c.

◆ tbl_update_func

typedef int(* tbl_update_func) (st_data_t *, st_data_t *, st_data_t, int)

Definition at line 529 of file hash.c.

Function Documentation

◆ Init_Hash()

void Init_Hash ( void  )

Definition at line 4554 of file hash.c.

References id_hash, id_yield, and rb_intern.

◆ NORETURN()

NORETURN ( static void   no_new_keyvoid)

◆ rb_check_hash_type()

VALUE rb_check_hash_type ( VALUE  hash)

Definition at line 722 of file hash.c.

References rb_check_convert_type_with_id(), and T_HASH.

Referenced by rb_Hash(), and rb_scan_args().

◆ rb_dbl_long_hash()

long rb_dbl_long_hash ( double  d)

Definition at line 144 of file hash.c.

References rb_hash_start(), rb_memhash(), and rb_objid_hash().

Referenced by rb_dbl_hash().

◆ rb_env_clear()

VALUE rb_env_clear ( void  )

Definition at line 4004 of file hash.c.

◆ rb_env_path_tainted()

int rb_env_path_tainted ( void  )

Definition at line 3424 of file hash.c.

◆ rb_hash()

VALUE rb_hash ( VALUE  obj)

Definition at line 121 of file hash.c.

References hval, and rb_exec_recursive_outer().

◆ rb_hash_add_new_element()

int rb_hash_add_new_element ( VALUE  hash,
VALUE  key,
VALUE  val 
)

Definition at line 3150 of file hash.c.

References rb_hash_tbl_raw().

◆ rb_hash_aref()

VALUE rb_hash_aref ( VALUE  hash,
VALUE  key 
)

◆ rb_hash_aset()

VALUE rb_hash_aset ( VALUE  hash,
VALUE  key,
VALUE  val 
)

Definition at line 1616 of file hash.c.

References RHASH, and RHASH_ITER_LEV.

Referenced by pruby_register_instance(), rb_uninterruptible(), and rb_vm_add_root_module().

◆ rb_hash_assoc()

VALUE rb_hash_assoc ( VALUE  hash,
VALUE  key 
)

◆ rb_hash_clear()

VALUE rb_hash_clear ( VALUE  hash)

Definition at line 1519 of file hash.c.

◆ rb_hash_compare_by_id_p()

VALUE rb_hash_compare_by_id_p ( VALUE  hash)

Definition at line 2913 of file hash.c.

References Qfalse, Qtrue, and RHASH.

◆ rb_hash_default_value()

VALUE rb_hash_default_value ( VALUE  hash,
VALUE  key 
)

Definition at line 803 of file hash.c.

References CLASS_OF, and rb_method_basic_definition_p().

Referenced by rb_hash_aref().

◆ rb_hash_delete()

VALUE rb_hash_delete ( VALUE  hash,
VALUE  key 
)

Definition at line 1119 of file hash.c.

References Qnil, Qundef, and rb_hash_delete_entry().

Referenced by pruby_unregister_instance().

◆ rb_hash_delete_entry()

VALUE rb_hash_delete_entry ( VALUE  hash,
VALUE  key 
)

Definition at line 1098 of file hash.c.

References Qundef, RHASH, st_data_t, st_delete, and val.

Referenced by rb_hash_delete().

◆ rb_hash_delete_if()

VALUE rb_hash_delete_if ( VALUE  hash)

Definition at line 1253 of file hash.c.

References RETURN_SIZED_ENUMERATOR.

◆ rb_hash_dig()

VALUE rb_hash_dig ( int  argc,
VALUE argv,
VALUE  self 
)

Definition at line 3009 of file hash.c.

References argv, Qnil, rb_check_arity, rb_hash_aref(), rb_obj_dig(), and UNLIMITED_ARGUMENTS.

◆ rb_hash_dup()

VALUE rb_hash_dup ( VALUE  hash)

Definition at line 449 of file hash.c.

References RBASIC.

◆ rb_hash_fetch()

VALUE rb_hash_fetch ( VALUE  hash,
VALUE  key 
)

Definition at line 917 of file hash.c.

Referenced by rb_hash_fetch_values().

◆ rb_hash_fetch_values()

VALUE rb_hash_fetch_values ( int  argc,
VALUE argv,
VALUE  hash 
)

Definition at line 1399 of file hash.c.

References argc, rb_ary_new2, rb_ary_push(), and rb_hash_fetch().

◆ rb_hash_foreach()

void rb_hash_foreach ( VALUE  hash,
int(*)(ANYARGS func,
VALUE  farg 
)

Definition at line 385 of file hash.c.

References hash_foreach_arg::hash, RHASH, and RHASH_ITER_LEV.

Referenced by rb_hash_keys(), rb_hash_rassoc(), and rb_hash_values().

◆ rb_hash_freeze()

VALUE rb_hash_freeze ( VALUE  hash)

Definition at line 77 of file hash.c.

◆ rb_hash_has_key()

VALUE rb_hash_has_key ( VALUE  hash,
VALUE  key 
)

Definition at line 2219 of file hash.c.

References Qfalse, Qtrue, RHASH, and st_lookup.

◆ rb_hash_keep_if()

VALUE rb_hash_keep_if ( VALUE  hash)

Definition at line 1492 of file hash.c.

References RETURN_SIZED_ENUMERATOR.

◆ rb_hash_keys()

VALUE rb_hash_keys ( VALUE  hash)

◆ rb_hash_lookup()

VALUE rb_hash_lookup ( VALUE  hash,
VALUE  key 
)

Definition at line 853 of file hash.c.

References Qnil, and rb_hash_lookup2().

◆ rb_hash_lookup2()

VALUE rb_hash_lookup2 ( VALUE  hash,
VALUE  key,
VALUE  def 
)

Definition at line 842 of file hash.c.

References RHASH, st_lookup, and val.

Referenced by rb_hash_lookup(), and rb_io_extract_encoding_option().

◆ rb_hash_new()

VALUE rb_hash_new ( void  )

◆ rb_hash_new_with_size()

VALUE rb_hash_new_with_size ( st_index_t  size)

Definition at line 430 of file hash.c.

References rb_hash_new(), RHASH, and st_init_table_with_size.

Referenced by rb_hash_bulk_insert().

◆ rb_hash_rassoc()

VALUE rb_hash_rassoc ( VALUE  hash,
VALUE  obj 
)

Definition at line 2747 of file hash.c.

References Qnil, and rb_hash_foreach().

◆ rb_hash_rehash()

VALUE rb_hash_rehash ( VALUE  hash)

Definition at line 779 of file hash.c.

References rb_eRuntimeError, rb_raise(), and RHASH_ITER_LEV.

◆ rb_hash_reject()

VALUE rb_hash_reject ( VALUE  hash)

Definition at line 1309 of file hash.c.

◆ rb_hash_reject_bang()

VALUE rb_hash_reject_bang ( VALUE  hash)

Definition at line 1272 of file hash.c.

References RETURN_SIZED_ENUMERATOR.

◆ rb_hash_select()

VALUE rb_hash_select ( VALUE  hash)

Definition at line 1434 of file hash.c.

◆ rb_hash_select_bang()

VALUE rb_hash_select_bang ( VALUE  hash)

Definition at line 1465 of file hash.c.

References RETURN_SIZED_ENUMERATOR.

◆ rb_hash_set_default_proc()

VALUE rb_hash_set_default_proc ( VALUE  hash,
VALUE  proc 
)

Definition at line 1025 of file hash.c.

◆ rb_hash_set_ifnone()

VALUE rb_hash_set_ifnone ( VALUE  hash,
VALUE  ifnone 
)

Definition at line 88 of file hash.c.

◆ rb_hash_size()

VALUE rb_hash_size ( VALUE  hash)

Definition at line 1718 of file hash.c.

References INT2FIX, and RHASH_SIZE.

◆ rb_hash_tbl()

struct st_table* rb_hash_tbl ( VALUE  hash)

Definition at line 475 of file hash.c.

References OBJ_WB_UNPROTECT.

◆ rb_hash_tbl_raw()

struct st_table* rb_hash_tbl_raw ( VALUE  hash)

Definition at line 482 of file hash.c.

Referenced by rb_execarg_extract_options(), rb_hash_add_new_element(), and rb_reset_coverages().

◆ rb_hash_update_by()

VALUE rb_hash_update_by ( VALUE  hash1,
VALUE  hash2,
rb_hash_update_func func 
)

Definition at line 2594 of file hash.c.

◆ rb_hash_values()

VALUE rb_hash_values ( VALUE  hash)

◆ rb_hash_values_at()

VALUE rb_hash_values_at ( int  argc,
VALUE argv,
VALUE  hash 
)

Definition at line 1371 of file hash.c.

References argc, rb_ary_new2, rb_ary_push(), and rb_hash_aref().

◆ rb_ident_hash_new()

VALUE rb_ident_hash_new ( void  )

Definition at line 2924 of file hash.c.

References rb_hash_new(), RHASH, and st_init_table.

Referenced by Init_sym(), and rb_uninterruptible().

◆ rb_init_identtable()

st_table* rb_init_identtable ( void  )

Definition at line 2932 of file hash.c.

References st_init_table.

◆ rb_init_identtable_with_size()

st_table* rb_init_identtable_with_size ( st_index_t  size)

Definition at line 2938 of file hash.c.

References st_init_table_with_size.

◆ rb_objid_hash()

long rb_objid_hash ( st_index_t  index)

Definition at line 246 of file hash.c.

Referenced by rb_dbl_long_hash().

◆ ruby_setenv()

void ruby_setenv ( const char *  name,
const char *  value 
)

Definition at line 3497 of file hash.c.

References ALLOCV_END, ALLOCV_N, buf, fail, free(), GET_ENVIRON, len, malloc, NULL, PRIuSIZE, rb_sprintf(), rb_sys_fail_str(), snprintf, and strlen().

Referenced by ruby_unsetenv().

◆ ruby_unsetenv()

void ruby_unsetenv ( const char *  name)

Definition at line 3641 of file hash.c.

References ruby_setenv().

◆ st_foreach_safe()

void st_foreach_safe ( st_table table,
int(*)(ANYARGS func,
st_data_t  a 
)

Variable Documentation

◆ environ

char** environ

◆ rb_cHash

VALUE rb_cHash

Definition at line 82 of file hash.c.