23 # ifdef HAVE_CRT_EXTERNS_H
32 #define HASH_DELETED FL_USER1
33 #define HASH_PROC_DEFAULT FL_USER2
110 #define identhash st_hashtype_num
125 status = (*arg->
func)(key, value, arg->
arg);
204 if (!
RHASH(hash)->ntbl)
268 if (!
RHASH(hash)->ntbl) {
271 return RHASH(hash)->ntbl;
288 #define NOINSERT_UPDATE_CALLBACK(func) \
290 func##_noinsert(st_data_t *key, st_data_t *val, st_data_t arg, int existing) \
292 if (!existing) no_new_key(); \
293 return func(key, val, arg, existing); \
296 #define UPDATE_CALLBACK(iter_lev, func) ((iter_lev) > 0 ? func##_noinsert : func)
298 #define RHASH_UPDATE_ITER(hash, iter_lev, key, func, arg) \
299 st_update(RHASH(hash)->ntbl, (st_data_t)(key), \
300 UPDATE_CALLBACK((iter_lev), func), \
302 #define RHASH_UPDATE(hash, key, func, arg) \
303 RHASH_UPDATE_ITER(hash, RHASH_ITER_LEV(hash), key, func, arg)
399 if (
RHASH(tmp)->ntbl) {
421 rb_warn(
"wrong element type %s at %ld (expected array)",
423 rb_warn(
"ignoring wrong elements is deprecated, remove them explicitly");
424 rb_warn(
"this causes ArgumentError in the next release");
428 switch (RARRAY_LEN(v)) {
447 for (i=0; i<
argc; i+=2) {
521 if (!
RHASH(hash)->ntbl)
526 RHASH(hash)->ntbl = tbl;
626 if (block_given && argc == 2) {
627 rb_warn(
"block supersedes default value argument");
630 if (block_given)
return rb_yield(key);
679 if (argc == 0)
return Qnil;
765 "wrong default_proc type %s (expected Proc)",
818 rb_warn(
"Hash#index is deprecated; use Hash#key");
827 if (!
RHASH(hash)->ntbl)
865 if (val !=
Qundef)
return val;
917 if (
RHASH(hash)->ntbl) {
963 if (
RHASH(hash)->ntbl)
984 if (!
RHASH(hash)->ntbl)
986 n =
RHASH(hash)->ntbl->num_entries;
988 if (n ==
RHASH(hash)->ntbl->num_entries)
return Qnil;
1026 for (i=0; i<
argc; i++) {
1090 if (!
RHASH(hash)->ntbl)
1092 n =
RHASH(hash)->ntbl->num_entries;
1094 if (n ==
RHASH(hash)->ntbl->num_entries)
return Qnil;
1115 if (
RHASH(hash)->ntbl)
1141 if (!
RHASH(hash)->ntbl)
1143 if (
RHASH(hash)->ntbl->num_entries > 0) {
1164 return hash_aset(key, val, arg, existing);
1257 if (hash == hash2)
return hash;
1259 if (
RHASH(hash2)->ntbl) {
1261 RHASH(hash)->ntbl->type =
RHASH(hash2)->ntbl->type;
1291 if (!
RHASH(hash)->ntbl)
1617 if (!
RHASH(hash)->ntbl)
1689 if (recur)
return Qtrue;
1702 if (hash1 == hash2)
return Qtrue;
1708 return rb_eql(hash2, hash1);
1714 if (!
RHASH(hash1)->ntbl || !
RHASH(hash2)->ntbl)
1716 if (
RHASH(hash1)->ntbl->type !=
RHASH(hash2)->ntbl->type)
1776 *hval ^=
st_hash(hdata,
sizeof(hdata), 0);
1785 if (!
RHASH(hash)->ntbl)
1787 hval =
RHASH(hash)->ntbl->num_entries;
2127 if (!
RHASH(hash)->ntbl)
2139 #define GET_ENVIRON(e) ((e) = rb_w32_get_environ())
2140 #define FREE_ENVIRON(e) rb_w32_free_environ(e)
2141 static char **my_environ;
2143 #define environ my_environ
2145 #define getenv(n) rb_w32_ugetenv(n)
2146 #elif defined(__APPLE__)
2148 #define environ (*_NSGetEnviron())
2149 #define GET_ENVIRON(e) (e)
2150 #define FREE_ENVIRON(e)
2153 #define GET_ENVIRON(e) (e)
2154 #define FREE_ENVIRON(e)
2156 #ifdef ENV_IGNORECASE
2157 #define ENVMATCH(s1, s2) (STRCASECMP((s1), (s2)) == 0)
2158 #define ENVNMATCH(s1, s2, n) (STRNCASECMP((s1), (s2), (n)) == 0)
2160 #define ENVMATCH(n1, n2) (strcmp((n1), (n2)) == 0)
2161 #define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
2180 if (!ptr)
return Qnil;
2288 if (block_given && argc == 2) {
2289 rb_warn(
"block supersedes default value argument");
2298 if (block_given)
return rb_yield(key);
2322 if (path_tainted < 0) {
2331 if (path_tainted < 0) {
2337 #if defined(_WIN32) || (defined(HAVE_SETENV) && defined(HAVE_UNSETENV))
2340 in_origenv(
const char *str)
2343 for (env = origenviron; *env; ++env) {
2344 if (*env == str)
return 1;
2352 register int i, len =
strlen(nam);
2356 for (i = 0; env[
i]; i++) {
2357 if (
ENVNMATCH(env[i],nam,len) && env[i][len] ==
'=')
2367 getenvsize(
const char*
p)
2369 const char* porg =
p;
2370 while (*p++) p +=
strlen(p) + 1;
2371 return p - porg + 1;
2392 const char* p = GetEnvironmentStringsA();
2394 if (
strlen(name) + 2 +
strlen(value) + getenvsize(p) >= getenvblocksize()) {
2406 if (!value || !*value) {
2408 if (!SetEnvironmentVariable(name, value) &&
2409 GetLastError() != ERROR_ENVVAR_NOT_FOUND)
goto fail;
2411 if (failed)
goto fail;
2412 #elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
2416 if (
setenv(name, value, 1))
2419 #ifdef VOID_UNSETENV
2428 char **env_ptr, *str;
2434 for (env_ptr =
GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) {
2435 if (!strncmp(str, name, len) && str[len] ==
'=') {
2436 if (!in_origenv(str))
free(str);
2437 while ((env_ptr[0] = env_ptr[1]) != 0) env_ptr++;
2443 snprintf(str, len,
"%s=%s", name, value);
2456 if (environ == origenviron) {
2461 for (max = i; environ[
max]; max++) ;
2462 tmpenv =
ALLOC_N(
char*, max+2);
2463 for (j=0; j<
max; j++)
2470 while (*envp && *envp != environ[i]) envp++;
2474 while (environ[i]) {
2475 environ[
i] = environ[i+1];
2488 snprintf(environ[i],len,
"%s=%s",name,value);
2559 char *s =
strchr(*env,
'=');
2578 for (; *env ; ++env) {
2626 char *s =
strchr(*env,
'=');
2683 char *s =
strchr(*env,
'=');
2710 volatile VALUE keys;
2727 if (del == 0)
return Qnil;
2763 for (i=0; i<
argc; i++) {
2789 char *s =
strchr(*env,
'=');
2814 volatile VALUE keys;
2831 if (del == 0)
return Qnil;
2861 volatile VALUE keys;
2902 char *s =
strchr(*env,
'=');
2904 if (env != environ) {
2942 char *s =
strchr(*env,
'=');
2981 for (i=0; env[
i]; i++)
3068 char *s =
strchr(*env,
'=');
3099 char *s =
strchr(*env,
'=');
3131 char *s =
strchr(*env,
'=');
3155 rb_warn(
"ENV.index is deprecated; use ENV.key");
3177 char *s =
strchr(*env,
'=');
3217 char *s =
strchr(*env,
'=');
3262 volatile VALUE keys;
3266 if (env == hash)
return env;
3300 if (env == hash)
return env;
3423 #define rb_intern(str) rb_intern_const(str)