21 #include <crt_externs.h> 26 #define HASH_DELETED FL_USER1 27 #define HASH_PROC_DEFAULT FL_USER2 377 if (
RHASH(tmp)->ntbl) {
493 RHASH(tmp)->ntbl = tbl;
498 RHASH(tmp)->ntbl = 0;
590 if (block_given &&
argc == 2) {
591 rb_warn(
"block supersedes default value argument");
724 "wrong default_proc type %s (expected Proc)",
777 rb_warn(
"Hash#index is deprecated; use Hash#key");
824 if (val !=
Qundef)
return val;
1098 if (
RHASH(
hash)->ntbl->num_entries > 0) {
1175 if (
RHASH(hash2)->ntbl) {
1603 if (hash1 == hash2)
return Qtrue;
1609 return rb_eql(hash2, hash1);
1615 if (!
RHASH(hash1)->ntbl || !
RHASH(hash2)->ntbl)
1617 if (
RHASH(hash1)->ntbl->type !=
RHASH(hash2)->ntbl->type)
1678 *hval ^=
st_hash(hdata,
sizeof(hdata), 0);
2018 #define GET_ENVIRON(e) ((e) = rb_w32_get_environ()) 2019 #define FREE_ENVIRON(e) rb_w32_free_environ(e) 2020 static char **my_environ;
2022 #define environ my_environ 2023 #elif defined(__APPLE__) 2025 #define environ (*_NSGetEnviron()) 2026 #define GET_ENVIRON(e) (e) 2027 #define FREE_ENVIRON(e) 2030 #define GET_ENVIRON(e) (e) 2031 #define FREE_ENVIRON(e) 2033 #ifdef ENV_IGNORECASE 2034 #define ENVMATCH(s1, s2) (STRCASECMP((s1), (s2)) == 0) 2035 #define ENVNMATCH(s1, s2, n) (STRNCASECMP((s1), (s2), (n)) == 0) 2037 #define ENVMATCH(n1, n2) (strcmp((n1), (n2)) == 0) 2038 #define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0) 2053 if (!ptr)
return Qnil;
2157 if (block_given &&
argc == 2) {
2158 rb_warn(
"block supersedes default value argument");
2202 #if defined(_WIN32) || (defined(HAVE_SETENV) && defined(HAVE_UNSETENV)) 2203 #elif defined __sun__ 2205 in_origenv(
const char *str)
2209 if (*
env == str)
return 1;
2221 for (
i = 0;
env[
i];
i++) {
2232 getenvsize(
const char*
p)
2234 const char* porg =
p;
2236 return p - porg + 1;
2257 const char*
p = GetEnvironmentStringsA();
2271 if (!value || !*value) {
2273 if (!SetEnvironmentVariable(
name, value) &&
2274 GetLastError() != ERROR_ENVVAR_NOT_FOUND)
goto fail;
2276 if (failed)
goto fail;
2277 #elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV) 2284 #ifdef VOID_UNSETENV 2291 #elif defined __sun__ 2293 char **env_ptr, *str;
2300 if (!strncmp(str,
name,
len) && str[
len] ==
'=') {
2301 if (!in_origenv(str))
free(str);
2302 while ((env_ptr[0] = env_ptr[1]) != 0) env_ptr++;
2328 for (j=0; j<
max; j++)
2335 while (*envp && *envp !=
environ[
i]) envp++;
2557 volatile VALUE keys;
2573 if (del == 0)
return Qnil;
2660 volatile VALUE keys;
2676 if (del == 0)
return Qnil;
2706 volatile VALUE keys;
3000 rb_warn(
"ENV.index is deprecated; use ENV.key");
3108 volatile VALUE keys;
3170 #define rb_intern(str) rb_intern_const(str) RUBY_EXTERN VALUE rb_cString
void rb_define_global_const(const char *, VALUE)
#define RSTRING_LEN(string)
static int rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
static int each_pair_i(VALUE key, VALUE value)
static VALUE env_each_value(VALUE ehash)
void rb_enc_copy(VALUE obj1, VALUE obj2)
static VALUE rb_hash_each_value(VALUE hash)
static VALUE env_delete_m(VALUE obj, VALUE name)
size_t strlen(const char *)
rb_hash_update_func * func
static VALUE rb_hash_has_value(VALUE hash, VALUE val)
static void path_tainted_p(const char *path)
static int replace_i(VALUE key, VALUE val, VALUE hash)
VALUE rb_hash_dup(VALUE hash)
static VALUE rb_hash_s_try_convert(VALUE, VALUE)
static int envix(const char *nam)
VALUE rb_yield_values(int n,...)
static int keep_if_i(VALUE key, VALUE value, VALUE hash)
static int max(int a, int b)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
static int env_update_i(VALUE key, VALUE val)
static VALUE rb_hash_size(VALUE hash)
static VALUE rb_hash_empty_p(VALUE hash)
static VALUE env_invert(void)
static VALUE rb_hash_default(int argc, VALUE *argv, VALUE hash)
static int rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
static void rb_hash_modify(VALUE hash)
static VALUE env_str_new2(const char *ptr)
st_index_t rb_hash_end(st_index_t)
VALUE rb_hash_select_bang(VALUE hash)
static int keys_i(VALUE key, VALUE value, VALUE ary)
static VALUE env_to_s(void)
int rb_env_path_tainted(void)
int st_numcmp(st_data_t, st_data_t)
static VALUE env_keys(void)
static VALUE env_delete_if(VALUE ehash)
#define HASH_PROC_DEFAULT
static VALUE env_shift(void)
VALUE rb_ary_push(VALUE ary, VALUE item)
static int eql_i(VALUE key, VALUE val1, VALUE arg)
VALUE rb_str_buf_new2(const char *)
SSL_METHOD *(* func)(void)
static VALUE env_each_pair(VALUE ehash)
VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
struct st_table * rb_hash_tbl(VALUE hash)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RSTRING_PTR(string)
static int assoc_i(VALUE key, VALUE val, VALUE arg)
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE rb_hash_shift(VALUE hash)
static VALUE inspect_hash(VALUE hash, VALUE dummy, int recur)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static VALUE rb_hash_equal(VALUE hash1, VALUE hash2)
VALUE rb_tainted_str_new2(const char *)
st_index_t rb_str_hash(VALUE)
#define RARRAY_LEN(ARRAY)
#define ENVNMATCH(s1, s2, n)
void rb_include_module(VALUE klass, VALUE module)
static int env_path_tainted(const char *)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
static int values_i(VALUE key, VALUE value, VALUE ary)
static VALUE env_keep_if(VALUE ehash)
static int rb_hash_update_i(VALUE key, VALUE value, VALUE hash)
VALUE rb_hash_fetch(VALUE hash, VALUE key)
static VALUE rb_hash_each_key(VALUE hash)
static int rb_hash_search_value(VALUE key, VALUE value, VALUE arg)
VALUE rb_str_buf_append(VALUE, VALUE)
static VALUE rb_hash_replace(VALUE hash, VALUE hash2)
const char * rb_obj_classname(VALUE)
static VALUE rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
static VALUE env_rassoc(VALUE dmy, VALUE obj)
static int rb_hash_update_func_i(VALUE key, VALUE value, VALUE arg0)
static VALUE env_each_key(VALUE ehash)
VALUE rb_str_buf_cat(VALUE, const char *, long)
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
static int rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
static VALUE env_key(VALUE dmy, VALUE value)
static int hash_foreach_iter(st_data_t key, st_data_t value, struct hash_foreach_arg *arg)
int rb_block_given_p(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
static VALUE rb_hash_reject(VALUE hash)
static VALUE env_assoc(VALUE env, VALUE key)
static VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc)
VALUE rb_hash_reject_bang(VALUE hash)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
static VALUE env_select_bang(VALUE ehash)
#define st_init_table_with_size
char * ruby_strdup(const char *)
static int hash_i(VALUE key, VALUE val, VALUE arg)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_str_buf_cat2(VALUE, const char *)
static int each_value_i(VALUE key, VALUE value)
VALUE rb_locale_str_new(const char *, long)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE rb_hash_eql(VALUE hash1, VALUE hash2)
static VALUE env_delete(VALUE obj, VALUE name)
static VALUE hash_foreach_call(struct hash_foreach_arg *arg)
#define NEWOBJ(obj, type)
VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value)
int rb_foreach_func(VALUE, VALUE, VALUE)
static VALUE env_reject(void)
static VALUE rb_hash_each_pair(VALUE hash)
static VALUE rb_hash_values(VALUE hash)
static const struct st_hash_type objhash
static int rb_any_cmp(VALUE a, VALUE b)
VALUE rb_obj_alloc(VALUE)
#define RBIGNUM_DIGITS(b)
static VALUE rb_hash_to_hash(VALUE hash)
static VALUE env_replace(VALUE env, VALUE hash)
VALUE rb_str_resize(VALUE, long)
static VALUE rb_hash_set_default(VALUE hash, VALUE ifnone)
int rb_str_hash_cmp(VALUE, VALUE)
void st_foreach_safe(st_table *table, int(*func)(ANYARGS), st_data_t a)
static void rb_hash_modify_check(VALUE hash)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
static VALUE rb_hash_s_create(int argc, VALUE *argv, VALUE klass)
static char ** origenviron
static int select_i(VALUE key, VALUE value, VALUE result)
static VALUE rb_hash_index(VALUE hash, VALUE value)
static VALUE env_index(VALUE dmy, VALUE value)
static VALUE rb_f_getenv(VALUE obj, VALUE name)
#define REALLOC_N(var, type, n)
static VALUE hash_foreach_ensure(VALUE hash)
VALUE rb_obj_is_proc(VALUE)
static VALUE env_inspect(void)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
VALUE rb_sprintf(const char *format,...)
static VALUE rb_hash_update(VALUE hash1, VALUE hash2)
VALUE rb_hash_delete(VALUE hash, VALUE key)
static VALUE rb_hash_key(VALUE hash, VALUE value)
VALUE rb_ary_delete(VALUE ary, VALUE item)
VALUE rb_hash_assoc(VALUE hash, VALUE obj)
static VALUE env_has_key(VALUE env, VALUE key)
static const struct st_hash_type identhash
#define unsetenv(name, val)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_check_hash_type(VALUE hash)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
static VALUE rb_hash_compare_by_id_p(VALUE hash)
static VALUE env_values(void)
static int clear_i(VALUE key, VALUE value, VALUE dummy)
VALUE rb_hash_keep_if(VALUE hash)
static VALUE hash_alloc(VALUE klass)
char * strchr(char *, char)
void rb_extend_object(VALUE obj, VALUE module)
#define setenv(name, val)
static VALUE env_aset(VALUE obj, VALUE nm, VALUE val)
static VALUE env_to_a(void)
register unsigned int len
static VALUE hash_equal(VALUE hash1, VALUE hash2, int eql)
#define RARRAY_PTR(ARRAY)
static VALUE rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_proc_lambda_p(VALUE)
static int each_key_i(VALUE key, VALUE value)
void ruby_unsetenv(const char *name)
void rb_sys_fail(const char *mesg)
static VALUE env_select(VALUE ehash)
static VALUE rb_hash_clear(VALUE hash)
VALUE rb_hash_freeze(VALUE hash)
int rb_respond_to(VALUE, ID)
st_index_t st_hash(const void *ptr, size_t len, st_index_t h)
static VALUE env_none(void)
static VALUE env_size(void)
static int delete_if_i(VALUE key, VALUE value, VALUE hash)
static VALUE rb_hash_keys(VALUE hash)
VALUE rb_usascii_str_new2(const char *)
VALUE rb_equal(VALUE, VALUE)
static int inspect_i(VALUE key, VALUE value, VALUE str)
static VALUE rb_hash_compare_by_id(VALUE hash)
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
static VALUE to_hash(VALUE hash)
int st_shift(st_table *, st_data_t *, st_data_t *)
int rb_path_check(const char *path)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
VALUE rb_block_proc(void)
static VALUE env_to_hash(void)
static VALUE rb_hash_has_key(VALUE hash, VALUE key)
VALUE rb_check_array_type(VALUE ary)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static VALUE env_values_at(int argc, VALUE *argv)
VALUE rb_check_string_type(VALUE)
VALUE rb_ary_includes(VALUE ary, VALUE item)
static int shift_i_safe(VALUE key, VALUE value, VALUE arg)
static st_index_t rb_any_hash(VALUE a)
st_index_t rb_hash_uint(st_index_t, st_index_t)
static VALUE rb_hash_invert(VALUE hash)
int rb_method_basic_definition_p(VALUE, ID)
static int foreach_safe_i(st_data_t key, st_data_t value, struct foreach_safe_arg *arg)
static VALUE rb_hash_hash(VALUE hash)
static void hash_update(VALUE hash, VALUE key)
static VALUE recursive_eql(VALUE hash, VALUE dt, int recur)
static unsigned int hash(const char *str, unsigned int len)
static int rassoc_i(VALUE key, VALUE val, VALUE arg)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define SafeStringValue(v)
VALUE rb_ary_new2(long capa)
VALUE rb_filesystem_str_new_cstr(const char *)
static VALUE rb_hash_merge(VALUE hash1, VALUE hash2)
static VALUE recursive_hash(VALUE hash, VALUE dummy, int recur)
#define StringValuePtr(v)
VALUE rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
static st_data_t copy_str_key(st_data_t str)
static int key_i(VALUE key, VALUE value, VALUE arg)
static VALUE rb_hash_rehash(VALUE hash)
int st_foreach_func(st_data_t, st_data_t, st_data_t)
static int env_replace_i(VALUE key, VALUE val, VALUE keys)
void st_clear(st_table *)
VALUE rb_hash_delete_if(VALUE hash)
#define rb_check_frozen(obj)
static VALUE env_empty_p(void)
static int to_a_i(VALUE key, VALUE value, VALUE ary)
VALUE rb_obj_freeze(VALUE)
VALUE rb_tainted_str_new(const char *, long)
static VALUE env_reject_bang(VALUE ehash)
static VALUE env_fetch(int argc, VALUE *argv)
VALUE rb_hash_select(VALUE hash)
static VALUE env_has_value(VALUE dmy, VALUE obj)
static VALUE env_update(VALUE env, VALUE hash)
#define OBJSETUP(obj, c, t)
st_index_t st_numhash(st_data_t)
static VALUE rb_hash_delete_key(VALUE hash, VALUE key)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void ruby_setenv(const char *name, const char *value)
VALUE rb_str_new2(const char *)
void rb_warn(const char *fmt,...)
#define DUPSETUP(dup, obj)
static void default_proc_arity_check(VALUE proc)
st_index_t rb_hash_start(st_index_t)
VALUE rb_hash_rassoc(VALUE hash, VALUE obj)
static VALUE rb_hash_to_a(VALUE hash)
static VALUE rb_hash_initialize(int argc, VALUE *argv, VALUE hash)
static VALUE env_str_new(const char *ptr, long len)
static VALUE rb_hash_default_proc(VALUE hash)
static VALUE rb_hash_inspect(VALUE hash)
VALUE rb_obj_class(VALUE)