23 # ifdef HAVE_CRT_EXTERNS_H
30 #define HAS_EXTRA_STATES(hash, klass) ( \
31 ((klass = has_extra_methods(rb_obj_class(hash))) != 0) || \
32 FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \
33 !NIL_P(RHASH_IFNONE(hash)))
34 #define HASH_REJECT_COPY_EXTRA_STATES 1
101 if (recurse)
return INT2FIX(0);
116 ul &= (1UL << (
sizeof(long)*
CHAR_BIT-1)) - 1;
135 if (a ==
Qundef)
return 0;
164 #define identhash st_hashtype_num
181 status = (*arg->
func)(key, value, arg->
arg);
268 if (!
RHASH(hash)->ntbl)
337 if (!
RHASH(hash)->ntbl) {
340 return RHASH(hash)->ntbl;
375 #define NOINSERT_UPDATE_CALLBACK(func) \
377 func##_noinsert(st_data_t *key, st_data_t *val, st_data_t arg, int existing) \
379 if (!existing) no_new_key(); \
380 return func(key, val, (struct update_arg *)arg, existing); \
384 func##_insert(st_data_t *key, st_data_t *val, st_data_t arg, int existing) \
386 return func(key, val, (struct update_arg *)arg, existing); \
404 arg.
arg = optional_arg;
415 if (arg.new_value)
RB_OBJ_WRITTEN(hash, arg.old_value, arg.new_value);
420 #define UPDATE_CALLBACK(iter_lev, func) ((iter_lev) > 0 ? func##_noinsert : func##_insert)
422 #define RHASH_UPDATE_ITER(h, iter_lev, key, func, a) do { \
423 tbl_update((h), (key), UPDATE_CALLBACK((iter_lev), func), (st_data_t)(a)); \
426 #define RHASH_UPDATE(hash, key, func, arg) \
427 RHASH_UPDATE_ITER(hash, RHASH_ITER_LEV(hash), key, func, arg)
526 if (
RHASH(tmp)->ntbl) {
548 rb_warn(
"wrong element type %s at %ld (expected array)",
550 rb_warn(
"ignoring wrong elements is deprecated, remove them explicitly");
551 rb_warn(
"this causes ArgumentError in the next release");
555 switch (RARRAY_LEN(v)) {
574 for (i=0; i<
argc; i+=2) {
654 if (!
RHASH(hash)->ntbl)
658 RHASH(tmp)->ntbl = tbl;
662 RHASH(hash)->ntbl = tbl;
663 RHASH(tmp)->ntbl = 0;
763 if (block_given && argc == 2) {
764 rb_warn(
"block supersedes default value argument");
767 if (block_given)
return rb_yield(key);
816 if (argc == 0)
return Qnil;
902 "wrong default_proc type %s (expected Proc)",
955 rb_warn(
"Hash#index is deprecated; use Hash#key");
964 if (!
RHASH(hash)->ntbl)
1002 if (val !=
Qundef)
return val;
1043 if (
RHASH(hash)->ntbl) {
1098 if (
RHASH(hash)->ntbl)
1120 if (!n)
return Qnil;
1122 if (n ==
RHASH(hash)->ntbl->num_entries)
return Qnil;
1158 #if HASH_REJECT_COPY_EXTRA_STATES
1160 rb_warn(
"following states will not be copied in the future version:");
1181 #if HASH_REJECT_COPY_EXTRA_STATES
1209 for (i=0; i<
argc; i++) {
1276 if (!
RHASH(hash)->ntbl)
1278 n =
RHASH(hash)->ntbl->num_entries;
1280 if (n ==
RHASH(hash)->ntbl->num_entries)
return Qnil;
1301 if (
RHASH(hash)->ntbl)
1327 if (!
RHASH(hash)->ntbl)
1329 if (
RHASH(hash)->ntbl->num_entries > 0) {
1360 return hash_aset(key, val, arg, existing);
1431 if (hash == hash2)
return hash;
1433 ntbl =
RHASH(hash)->ntbl;
1434 if (
RHASH(hash2)->ntbl) {
1473 if (hash == hash2)
return hash;
1482 table2 =
RHASH(hash2)->ntbl;
1789 if (size == 0)
return keys;
1833 if (size == 0)
return values;
1869 if (!
RHASH(hash)->ntbl)
1941 if (recur)
return Qtrue;
1954 if (hash1 == hash2)
return Qtrue;
1960 return rb_eql(hash2, hash1);
1966 if (!
RHASH(hash1)->ntbl || !
RHASH(hash2)->ntbl)
1968 if (
RHASH(hash1)->ntbl->type !=
RHASH(hash2)->ntbl->type)
2028 *hval ^=
st_hash(hdata,
sizeof(hdata), 0);
2310 table =
RHASH(hash)->ntbl;
2311 orighash = table->
type;
2320 table->
type = &assochash;
2410 if (level - 1 > 0) {
2414 else if (level < 0) {
2466 if (!
RHASH(hash)->ntbl)
2478 #define GET_ENVIRON(e) ((e) = rb_w32_get_environ())
2479 #define FREE_ENVIRON(e) rb_w32_free_environ(e)
2480 static char **my_environ;
2482 #define environ my_environ
2484 static inline char *
2487 static int binary = -1;
2488 static int locale = -1;
2495 #define getenv(n) w32_getenv(n)
2496 #elif defined(__APPLE__)
2498 #define environ (*_NSGetEnviron())
2499 #define GET_ENVIRON(e) (e)
2500 #define FREE_ENVIRON(e)
2503 #define GET_ENVIRON(e) (e)
2504 #define FREE_ENVIRON(e)
2506 #ifdef ENV_IGNORECASE
2507 #define ENVMATCH(s1, s2) (STRCASECMP((s1), (s2)) == 0)
2508 #define ENVNMATCH(s1, s2, n) (STRNCASECMP((s1), (s2), (n)) == 0)
2510 #define ENVMATCH(n1, n2) (strcmp((n1), (n2)) == 0)
2511 #define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
2530 if (!ptr)
return Qnil;
2635 if (block_given && argc == 2) {
2636 rb_warn(
"block supersedes default value argument");
2645 if (block_given)
return rb_yield(key);
2669 if (path_tainted < 0) {
2678 if (path_tainted < 0) {
2684 #if defined(_WIN32) || (defined(HAVE_SETENV) && defined(HAVE_UNSETENV))
2687 in_origenv(
const char *str)
2690 for (env = origenviron; *env; ++env) {
2691 if (*env == str)
return 1;
2699 register int i, len =
strlen(nam);
2703 for (i = 0; env[i]; i++) {
2704 if (
ENVNMATCH(env[i],nam,len) && env[i][len] ==
'=')
2714 getenvsize(
const char* p)
2716 const char* porg = p;
2717 while (*p++) p +=
strlen(p) + 1;
2718 return p - porg + 1;
2727 #if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
2754 char* p = GetEnvironmentStringsA();
2758 FreeEnvironmentStringsA(p);
2759 if (n >= getenvblocksize()) {
2771 if (!value || !*value) {
2773 if (!SetEnvironmentVariable(name, value) &&
2774 GetLastError() != ERROR_ENVVAR_NOT_FOUND)
goto fail;
2780 #elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
2784 if (
setenv(name, value, 1))
2788 #ifdef VOID_UNSETENV
2797 char **env_ptr, *str;
2800 for (env_ptr =
GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) {
2801 if (!strncmp(str, name, len) && str[len] ==
'=') {
2802 if (!in_origenv(str))
free(str);
2803 while ((env_ptr[0] = env_ptr[1]) != 0) env_ptr++;
2809 snprintf(str, len,
"%s=%s", name, value);
2819 if (environ == origenviron) {
2824 for (max = i; environ[
max]; max++) ;
2825 tmpenv =
ALLOC_N(
char*, max+2);
2826 for (j=0; j<
max; j++)
2833 while (*envp && *envp != environ[i]) envp++;
2837 while (environ[i]) {
2838 environ[i] = environ[i+1];
2850 environ[i] =
ALLOC_N(
char, len);
2851 snprintf(environ[i],len,
"%s=%s",name,value);
2917 char *s =
strchr(*env,
'=');
2934 for (; *env ; ++env) {
2981 char *s =
strchr(*env,
'=');
3037 char *s =
strchr(*env,
'=');
3071 volatile VALUE keys;
3088 if (del == 0)
return Qnil;
3123 for (i=0; i<
argc; i++) {
3171 volatile VALUE keys;
3188 if (del == 0)
return Qnil;
3218 volatile VALUE keys;
3258 char *s =
strchr(*env,
'=');
3260 if (env != environ) {
3297 char *s =
strchr(*env,
'=');
3335 for (i=0; env[i]; i++)
3421 char *s =
strchr(*env,
'=');
3452 char *s =
strchr(*env,
'=');
3483 char *s =
strchr(*env,
'=');
3507 rb_warn(
"ENV.index is deprecated; use ENV.key");
3528 char *s =
strchr(*env,
'=');
3568 char *s =
strchr(*env,
'=');
3613 volatile VALUE keys;
3617 if (env == hash)
return env;
3650 if (env == hash)
return env;
3773 #define rb_intern(str) rb_intern_const(str)