Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
|
#include "ruby/internal/config.h"
#include <errno.h>
#include "debug_counter.h"
#include "id.h"
#include "internal.h"
#include "internal/array.h"
#include "internal/bignum.h"
#include "internal/class.h"
#include "internal/cont.h"
#include "internal/error.h"
#include "internal/hash.h"
#include "internal/object.h"
#include "internal/proc.h"
#include "internal/symbol.h"
#include "internal/time.h"
#include "internal/vm.h"
#include "probes.h"
#include "ruby/st.h"
#include "ruby/util.h"
#include "ruby_assert.h"
#include "symbol.h"
#include "transient_heap.h"
Go to the source code of this file.
Data Structures | |
struct | ar_table_pair_struct |
struct | ar_table_struct |
struct | functor |
struct | foreach_safe_arg |
struct | hash_foreach_arg |
struct | update_callback_arg |
struct | update_arg |
struct | rehash_arg |
struct | shift_var |
struct | transform_keys_args |
struct | equal_data |
struct | update_func_arg |
struct | reset_hash_type_arg |
Macros | |
#define | HASH_DEBUG 0 |
#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 | st_index_hash(index) key64_hash(rb_hash_start(index), prime2) |
#define | rb_ident_cmp st_numcmp |
#define | identhash rb_hashtype_ident |
#define | RHASH_AR_TABLE_MAX_BOUND RHASH_AR_TABLE_MAX_SIZE |
#define | RHASH_AR_TABLE_REF(hash, n) (&RHASH_AR_TABLE(hash)->pairs[n]) |
#define | RHASH_AR_CLEARED_HINT 0xff |
#define | RHASH_AR_TABLE_SIZE(h) |
#define | RHASH_AR_TABLE_BOUND_RAW(h) |
#define | RHASH_AR_TABLE_BOUND(h) |
#define | RHASH_ST_TABLE_SET(h, s) rb_hash_st_table_set(h, s) |
#define | RHASH_TYPE(hash) (RHASH_AR_TABLE_P(hash) ? &objhash : RHASH_ST_TABLE(hash)->type) |
#define | HASH_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(HASH_DEBUG, expr, #expr) |
#define | hash_verify(h) ((void)0) |
#define | RHASH_SET_ST_FLAG(h) FL_SET_RAW(h, RHASH_ST_TABLE_FLAG) |
#define | RHASH_UNSET_ST_FLAG(h) FL_UNSET_RAW(h, RHASH_ST_TABLE_FLAG) |
#define | RHASH_AR_TABLE_SIZE_INC(h) HASH_AR_TABLE_SIZE_ADD(h, 1) |
#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 | to_hash rb_to_hash_type |
#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)) |
Typedefs | |
typedef st_index_t | st_hash_t |
typedef struct ar_table_pair_struct | ar_table_pair |
typedef struct ar_table_struct | ar_table |
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) |
Variables | |
VALUE | rb_cHash |
const struct st_hash_type | rb_hashtype_ident |
char ** | environ |
#define ENVNMATCH | ( | s1, | |
s2, | |||
n | |||
) | (memcmp((s1), (s2), (n)) == 0) |
#define get_env_ptr | ( | var, | |
val | |||
) | (var = get_env_cstr(val, #var)) |
#define HAS_EXTRA_STATES | ( | hash, | |
klass | |||
) |
#define HASH_ASSERT | ( | expr | ) | RUBY_ASSERT_MESG_WHEN(HASH_DEBUG, expr, #expr) |
#define identhash rb_hashtype_ident |
#define NOINSERT_UPDATE_CALLBACK | ( | func | ) |
#define RHASH_AR_TABLE_BOUND | ( | h | ) |
#define RHASH_AR_TABLE_BOUND_RAW | ( | h | ) |
#define RHASH_AR_TABLE_MAX_BOUND RHASH_AR_TABLE_MAX_SIZE |
#define RHASH_AR_TABLE_REF | ( | hash, | |
n | |||
) | (&RHASH_AR_TABLE(hash)->pairs[n]) |
#define RHASH_AR_TABLE_SIZE | ( | h | ) |
#define RHASH_AR_TABLE_SIZE_INC | ( | h | ) | HASH_AR_TABLE_SIZE_ADD(h, 1) |
#define RHASH_SET_ST_FLAG | ( | h | ) | FL_SET_RAW(h, RHASH_ST_TABLE_FLAG) |
#define RHASH_ST_TABLE_SET | ( | h, | |
s | |||
) | rb_hash_st_table_set(h, s) |
#define RHASH_TYPE | ( | hash | ) | (RHASH_AR_TABLE_P(hash) ? &objhash : RHASH_ST_TABLE(hash)->type) |
#define RHASH_UNSET_ST_FLAG | ( | h | ) | FL_UNSET_RAW(h, RHASH_ST_TABLE_FLAG) |
#define RHASH_UPDATE | ( | hash, | |
key, | |||
func, | |||
arg | |||
) | RHASH_UPDATE_ITER(hash, RHASH_ITER_LEV(hash), key, func, arg) |
#define RHASH_UPDATE_ITER | ( | h, | |
iter_lev, | |||
key, | |||
func, | |||
a | |||
) |
#define SET_DEFAULT | ( | hash, | |
ifnone | |||
) |
#define SET_PROC_DEFAULT | ( | hash, | |
proc | |||
) | set_proc_default(hash, proc) |
#define st_index_hash | ( | index | ) | key64_hash(rb_hash_start(index), prime2) |
#define to_hash rb_to_hash_type |
#define UPDATE_CALLBACK | ( | iter_lev, | |
func | |||
) | ((iter_lev) > 0 ? func##_noinsert : func##_insert) |
typedef struct ar_table_struct ar_table |
typedef struct ar_table_pair_struct ar_table_pair |
typedef st_index_t st_hash_t |
void Init_Hash | ( | void | ) |
Definition at line 6839 of file hash.c.
References environ, HASH_ASSERT, id_hash, rb_cHash, rb_cObject, rb_define_alias(), rb_define_alloc_func(), rb_define_class(), rb_define_global_const(), rb_define_method, rb_define_singleton_method, rb_extend_object(), rb_hash_aref(), rb_hash_aset(), rb_hash_assoc(), rb_hash_clear(), rb_hash_compare_by_id_p(), rb_hash_delete_if(), rb_hash_has_key(), rb_hash_keys(), rb_hash_rassoc(), rb_hash_rehash(), rb_hash_reject(), rb_hash_reject_bang(), rb_hash_set_default_proc(), rb_hash_size(), rb_hash_values(), rb_hash_values_at(), rb_include_module(), rb_make_internal_id(), rb_mEnumerable, rb_obj_alloc(), RHASH_AR_TABLE_MAX_SIZE, and ruby_register_rollback_func_for_ensure().
Definition at line 1860 of file hash.c.
References update_arg::hash, rb_check_convert_type_with_id(), and T_HASH.
Referenced by rb_econv_prepare_options(), and rb_Hash().
long rb_dbl_long_hash | ( | double | d | ) |
Definition at line 180 of file hash.c.
References rb_memhash().
VALUE rb_env_clear | ( | void | ) |
Definition at line 5839 of file hash.c.
References key, RARRAY_AREF, RARRAY_LEN, RB_GC_GUARD, RSTRING_PTR, ruby_setenv(), and TRUE.
Referenced by rb_execarg_run_options().
int rb_env_path_tainted | ( | void | ) |
Definition at line 5051 of file hash.c.
References rb_warn_deprecated_to_remove().
Definition at line 143 of file hash.c.
References FIXNUM_MAX, FIXNUM_MIN, FIXNUM_P, id_hash, INTEGER_PACK_NATIVE_BYTE_ORDER, LONG2FIX, Qundef, rb_check_funcall_basic_kw(), rb_exec_recursive_outer(), rb_integer_pack(), rb_mKernel, rb_to_int(), and T_BIGNUM.
Referenced by rb_complex_hash(), and rb_rational_hash().
Definition at line 4734 of file hash.c.
References st_hash_type::hash, key, RHASH_TBL_RAW, and st_update.
Definition at line 560 of file hash.c.
References HASH_ASSERT, and RHASH.
Definition at line 548 of file hash.c.
References FALSE, FL_TEST_RAW, HASH_ASSERT, NULL, RHASH, RHASH_ST_TABLE_FLAG, and TRUE.
Definition at line 2046 of file hash.c.
References key, and rb_hash_default_value().
Referenced by Init_Hash(), rb_autoload_str(), rb_econv_open_opts(), rb_econv_prepare_options(), rb_hash_values_at(), rb_io_extract_modeenc(), rb_iseq_build_from_ary(), rb_obj_dig(), and rb_warning_category_from_name().
Definition at line 2901 of file hash.c.
References identhash, key, rb_cString, rb_obj_class(), RHASH_ITER_LEV, RHASH_TYPE, RHASH_UPDATE_ITER, and shift_var::val.
Referenced by Init_Exception(), Init_GC(), Init_Hash(), Init_ossl_asn1(), Init_ossl_x509name(), InitVM_Enumerator(), olerecord_set_ivar(), rb_ast_add_mark_object(), rb_autoload_str(), rb_econv_prepare_options(), rb_hash_set_pair(), rb_iseq_new_top(), and rb_uninterruptible().
Definition at line 4160 of file hash.c.
References st_hash_type::compare, reset_hash_type_arg::hash, st_hash_type::hash, HASH_ASSERT, identhash, key, reset_hash_type_arg::orighash, Qnil, Qundef, rb_assoc_new(), rb_ensure(), rb_hash_foreach(), RHASH_EMPTY_P, and st_table::type.
Referenced by Init_Hash().
Definition at line 4777 of file hash.c.
References argc, argv, st_hash_type::hash, HASH_ASSERT, rb_hash_bulk_insert_into_st_table(), RHASH_AR_TABLE_MAX_SIZE, RHASH_AR_TABLE_SIZE, and RHASH_TBL_RAW.
Definition at line 2819 of file hash.c.
References rb_hash_foreach(), RHASH_ITER_LEV, and st_clear.
Referenced by Init_Hash(), and yyparse().
Definition at line 4432 of file hash.c.
References st_hash_type::hash, identhash, Qfalse, and Qtrue.
Referenced by Init_Hash().
Definition at line 1999 of file hash.c.
References CLASS_OF, FL_TEST, key, LIKELY, Qnil, Qundef, rb_funcall(), rb_method_basic_definition_p, RHASH_IFNONE, and RHASH_PROC_DEFAULT.
Referenced by rb_hash_aref(), and rb_str_format().
Definition at line 2309 of file hash.c.
References key, Qundef, and rb_hash_stlike_delete().
Referenced by rb_gc_free_dsymbol(), rb_hash_delete(), and rb_sym2id().
Definition at line 2490 of file hash.c.
References rb_hash_foreach(), and RETURN_SIZED_ENUMERATOR.
Referenced by Init_Hash().
Definition at line 1579 of file hash.c.
References FL_EXIVAR, hash_foreach_arg::hash, rb_copy_generic_ivar(), rb_obj_class(), RBASIC, and RHASH_PROC_DEFAULT.
Definition at line 2138 of file hash.c.
References key.
Referenced by rb_category_compile_warn(), rb_category_warn(), and rb_category_warning().
void rb_hash_foreach | ( | VALUE | hash, |
rb_foreach_func * | func, | ||
VALUE | farg | ||
) |
Definition at line 1498 of file hash.c.
References hash_foreach_arg::arg, hash_foreach_arg::func, hash_foreach_arg::hash, hash_verify, and rb_ensure().
Referenced by ole_rec2variant(), rb_clear_coverages(), rb_extract_keywords(), rb_hash_assoc(), rb_hash_clear(), rb_hash_delete_if(), rb_hash_keys(), rb_hash_rassoc(), rb_hash_rehash(), rb_hash_reject(), rb_hash_reject_bang(), rb_hash_update_by(), rb_hash_values(), and rb_tracepoint_disable().
Definition at line 101 of file hash.c.
References rb_obj_freeze().
Referenced by rb_econv_prepare_options().
Definition at line 2852 of file hash.c.
References FL_EXIVAR, key, rb_cString, rb_fstring(), rb_str_new_frozen(), and RBASIC_CLASS.
Definition at line 3549 of file hash.c.
References ptr, RARRAY_PTR_USE_TRANSIENT, rb_ary_new_capa(), rb_ary_set_len(), rb_gc_writebarrier_remember(), rb_hash_foreach(), RHASH_SIZE, ST_DATA_COMPATIBLE_P, and st_keys.
Referenced by Init_Hash().
Definition at line 2072 of file hash.c.
References key, Qnil, and rb_hash_lookup2().
Definition at line 2059 of file hash.c.
Referenced by rb_hash_lookup(), rb_io_extract_encoding_option(), and rb_str_format().
VALUE rb_hash_new | ( | void | ) |
Definition at line 1538 of file hash.c.
References rb_cHash.
Referenced by date__httpdate(), date__iso8601(), date__jisx0301(), date__parse(), date__rfc2822(), date__rfc3339(), date__xmlschema(), Init_GC(), Init_limits(), Init_ossl_asn1(), Init_ossl_x509name(), Init_sizeof(), olerecord_set_ivar(), rb_default_coverage(), rb_econv_prepare_options(), rb_Hash(), rb_hash_new_with_size(), rb_hash_reject(), rb_ident_hash_new(), and yyparse().
VALUE rb_hash_new_with_size | ( | st_index_t | size | ) |
Definition at line 1544 of file hash.c.
References rb_hash_new(), RHASH_AR_TABLE_MAX_SIZE, RHASH_ST_TABLE_SET, and st_init_table_with_size.
Referenced by InitVM_Enumerator().
Definition at line 4221 of file hash.c.
References st_hash_type::hash, Qnil, and rb_hash_foreach().
Referenced by Init_Hash().
Definition at line 1960 of file hash.c.
References hash_verify, st_table::num_entries, rb_eRuntimeError, rb_hash_foreach(), rb_raise(), RHASH_ITER_LEV, RHASH_ST_TABLE_SET, st_free_table, st_init_table_with_size, and st_table::type.
Referenced by Init_Hash().
Definition at line 2560 of file hash.c.
References HAS_EXTRA_STATES, PRIsVALUE, rb_hash_foreach(), rb_hash_new(), rb_warn(), RETURN_SIZED_ENUMERATOR, RHASH_EMPTY_P, RTEST, and ruby_verbose.
Referenced by Init_Hash().
Definition at line 2519 of file hash.c.
References Qnil, rb_hash_foreach(), RETURN_SIZED_ENUMERATOR, and RHASH_SIZE.
Referenced by Init_Hash().
Definition at line 1590 of file hash.c.
References hash_foreach_arg::hash, and rb_cHash.
Definition at line 2234 of file hash.c.
References NIL_P, rb_check_convert_type_with_id(), rb_eTypeError, rb_obj_classname(), rb_obj_is_proc(), rb_raise(), SET_DEFAULT, SET_PROC_DEFAULT, and T_DATA.
Referenced by Init_Hash().
Definition at line 113 of file hash.c.
References RB_OBJ_WRITE, and RHASH.
Definition at line 3468 of file hash.c.
References NIL_P, RARRAY_AREF, RARRAY_LEN, rb_builtin_class_name(), rb_check_array_type(), rb_eArgError, rb_eTypeError, rb_hash_aset(), and rb_raise().
Definition at line 2981 of file hash.c.
References INT2FIX, and RHASH_SIZE.
Referenced by Init_Hash().
size_t rb_hash_size_num | ( | VALUE | hash | ) |
Definition at line 2987 of file hash.c.
References RHASH_SIZE.
Definition at line 567 of file hash.c.
References HASH_ASSERT, and RHASH.
Definition at line 574 of file hash.c.
References FL_SET_RAW, HASH_ASSERT, NULL, RHASH, and RHASH_ST_TABLE_FLAG.
int rb_hash_stlike_foreach | ( | VALUE | hash, |
st_foreach_callback_func * | func, | ||
st_data_t | arg | ||
) |
Definition at line 1457 of file hash.c.
References hash_foreach_arg::arg, hash_foreach_arg::func, hash_foreach_arg::hash, and st_foreach.
Referenced by rb_execarg_extract_options().
int rb_hash_stlike_foreach_with_replace | ( | VALUE | hash, |
st_foreach_check_callback_func * | func, | ||
st_update_callback_func * | replace, | ||
st_data_t | arg | ||
) |
Definition at line 1468 of file hash.c.
References hash_foreach_arg::arg, hash_foreach_arg::func, hash_foreach_arg::hash, and st_foreach_with_replace.
int rb_hash_stlike_update | ( | VALUE | hash, |
st_data_t | key, | ||
st_update_callback_func * | func, | ||
st_data_t | arg | ||
) |
Definition at line 1609 of file hash.c.
References OBJ_WB_UNPROTECT, and rb_hash_tbl_raw().
Definition at line 1603 of file hash.c.
Referenced by rb_hash_tbl().
VALUE rb_hash_update_by | ( | VALUE | hash1, |
VALUE | hash2, | ||
rb_hash_update_func * | func | ||
) |
Definition at line 4036 of file hash.c.
References update_func_arg::func, update_func_arg::hash, rb_hash_foreach(), and to_hash.
Definition at line 3593 of file hash.c.
References ptr, RARRAY_PTR_USE_TRANSIENT, rb_ary_new_capa(), rb_ary_set_len(), rb_gc_writebarrier_remember(), rb_hash_foreach(), RHASH_SIZE, ST_DATA_COMPATIBLE_P, and st_values.
Referenced by Init_Hash().
Definition at line 2652 of file hash.c.
References argc, argv, rb_ary_new2, rb_ary_push(), and rb_hash_aref().
Referenced by Init_Hash().
st_table * rb_init_identtable | ( | void | ) |
Definition at line 4451 of file hash.c.
References identhash, and st_init_table.
Referenced by Init_MemoryView().
Definition at line 1501 of file variable.c.
References rb_is_instance_id(), and VM_ASSERT.
Definition at line 1853 of file hash.c.
References update_arg::hash, rb_convert_type_with_id(), and T_HASH.
Definition at line 5145 of file hash.c.
References ALLOC_N, ALLOCV_END, ALLOCV_N, environ, fail, free, GET_ENVIRON, L, len, malloc, max, name, NULL, PRIuSIZE, rb_sprintf(), rb_sys_fail_str(), REALLOC_N, ruby_strdup(), snprintf, str, strlen(), and xfree.
Referenced by rb_env_clear(), rb_execarg_run_options(), and ruby_unsetenv().
void ruby_unsetenv | ( | const char * | name | ) |
Definition at line 5284 of file hash.c.
References name, and ruby_setenv().
void st_foreach_safe | ( | st_table * | table, |
st_foreach_func * | func, | ||
st_data_t | a | ||
) |
Definition at line 1309 of file hash.c.
References foreach_safe_arg::arg, foreach_safe_arg::func, rb_eRuntimeError, rb_raise(), and st_foreach_check.
|
extern |
Referenced by Init_Hash(), and ruby_setenv().
VALUE rb_cHash |
Definition at line 106 of file hash.c.
Referenced by Init_Hash(), rb_extract_keywords(), rb_hash_new(), and rb_hash_resurrect().
const struct st_hash_type rb_hashtype_ident |