[前][次][番号順一覧][スレッド一覧]

ruby-changes:5098

From: knu <ko1@a...>
Date: Mon, 26 May 2008 03:22:08 +0900 (JST)
Subject: [ruby-changes:5098] Ruby:r16593 (ruby_1_8): * hash.c (rb_hash_default): Fix rdoc.

knu	2008-05-26 03:21:48 +0900 (Mon, 26 May 2008)

  New Revision: 16593

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/hash.c

  Log:
    * hash.c (rb_hash_default): Fix rdoc.
      (rb_hash_each, env_each_value, env_each_pair): Return an
      enumerator if no block is given.
      (rb_hash_update): Update rdoc.
      (envix): Conditionalize the definition itself.
      (rb_f_getenv, env_fetch, env_keys, env_values, env_values_at)
      (env_select, env_inspect, env_to_a, env_empty_p, env_has_key)
      (env_has_value, env_index, env_indexes, env_to_hash, env_shift)
      (env_update): Require secure level 4.
      (env_each_value, env_each_i): Delay variable initialization.
      (env_each_key, env_each_value, env_reject_bang)
      (env_clear, env_replace): Omit duplicated secure level check.
      (env_has_value): Do to_str conversion.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16593&r2=16592&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/hash.c?r1=16593&r2=16592&diff_format=u

Index: ruby_1_8/hash.c
===================================================================
--- ruby_1_8/hash.c	(revision 16592)
+++ ruby_1_8/hash.c	(revision 16593)
@@ -538,7 +538,7 @@
  *     h.default(2)                            #=> "cat"
  *
  *     h = Hash.new {|h,k| h[k] = k.to_i*10}   #=> {}
- *     h.default                               #=> 0
+ *     h.default                               #=> nil
  *     h.default(2)                            #=> 20
  */
 
@@ -891,7 +891,7 @@
  *
  *   h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
  *   h.values_at("cow", "cat")  #=> ["bovine", "feline"]
-*/
+ */
 
 VALUE
 rb_hash_values_at(argc, argv, hash)
@@ -1212,6 +1212,7 @@
 rb_hash_each(hash)
     VALUE hash;
 {
+    RETURN_ENUMERATOR(hash, 0, 0);
     rb_hash_foreach(hash, each_i, 0);
     return hash;
 }
@@ -1716,12 +1717,20 @@
  *     hsh.merge!(other_hash){|key, oldval, newval| block}    => hsh
  *     hsh.update(other_hash){|key, oldval, newval| block}    => hsh
  *
- *  Adds the contents of <i>other_hash</i> to <i>hsh</i>, overwriting
- *  entries with duplicate keys with those from <i>other_hash</i>.
+ *  Adds the contents of <i>other_hash</i> to <i>hsh</i>.  If no
+ *  block is specified entries with duplicate keys are overwritten
+ *  with the values from <i>other_hash</i>, otherwise the value
+ *  of each duplicate key is determined by calling the block with
+ *  the key, its value in <i>hsh</i> and its value in <i>other_hash</i>.
  *
  *     h1 = { "a" => 100, "b" => 200 }
  *     h2 = { "b" => 254, "c" => 300 }
  *     h1.merge!(h2)   #=> {"a"=>100, "b"=>254, "c"=>300}
+ *
+ *     h1 = { "a" => 100, "b" => 200 }
+ *     h2 = { "b" => 254, "c" => 300 }
+ *     h1.merge!(h2) { |key, v1, v2| v1 }
+ *                     #=> {"a"=>100, "b"=>200, "c"=>300}
  */
 
 static VALUE
@@ -1847,7 +1856,8 @@
 {
     char *nam, *env;
 
-    StringValue(name);
+    rb_secure(4);
+    SafeStringValue(name);
     nam = RSTRING(name)->ptr;
     if (strlen(nam) != RSTRING(name)->len) {
 	rb_raise(rb_eArgError, "bad environment variable name");
@@ -1879,12 +1889,13 @@
     long block_given;
     char *nam, *env;
 
+    rb_secure(4);
     rb_scan_args(argc, argv, "11", &key, &if_none);
     block_given = rb_block_given_p();
     if (block_given && argc == 2) {
 	rb_warn("block supersedes default value argument");
     }
-    StringValue(key);
+    SafeStringValue(key);
     nam = RSTRING(key)->ptr;
     if (strlen(nam) != RSTRING(key)->len) {
 	rb_raise(rb_eArgError, "bad environment variable name");
@@ -1922,6 +1933,7 @@
     return path_tainted;
 }
 
+#if !defined(_WIN32) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV))
 static int
 envix(nam)
     const char *nam;
@@ -1943,6 +1955,7 @@
     FREE_ENVIRON(environ);
     return i;
 }
+#endif
 
 void
 ruby_setenv(name, value)
@@ -2079,8 +2092,10 @@
 env_keys()
 {
     char **env;
-    VALUE ary = rb_ary_new();
+    VALUE ary;
 
+    rb_secure(4);
+    ary = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2101,7 +2116,7 @@
     long i;
 
     RETURN_ENUMERATOR(ehash, 0, 0);
-    keys = env_keys();
+    keys = env_keys();	/* rb_secure(4); */
     for (i=0; i<RARRAY(keys)->len; i++) {
 	rb_yield(RARRAY(keys)->ptr[i]);
     }
@@ -2111,9 +2126,11 @@
 static VALUE
 env_values()
 {
+    VALUE ary;
     char **env;
-    VALUE ary = rb_ary_new();
 
+    rb_secure(4);
+    ary = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2130,10 +2147,11 @@
 env_each_value(ehash)
     VALUE ehash;
 {
-    VALUE values = env_values();
+    VALUE values;
     long i;
 
     RETURN_ENUMERATOR(ehash, 0, 0);
+    values = env_values();	/* rb_secure(4); */
     for (i=0; i<RARRAY(values)->len; i++) {
 	rb_yield(RARRAY(values)->ptr[i]);
     }
@@ -2146,9 +2164,11 @@
     int values;
 {
     char **env;
-    VALUE ary = rb_ary_new();
+    VALUE ary;
     long i;
 
+    rb_secure(4);
+    ary = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2183,6 +2203,7 @@
 env_each_pair(ehash)
     VALUE ehash;
 {
+    RETURN_ENUMERATOR(ehash, 0, 0);
     return env_each_i(ehash, Qtrue);
 }
 
@@ -2195,9 +2216,7 @@
     int del = 0;
 
     RETURN_ENUMERATOR(ehash, 0, 0);
-    rb_secure(4);
-    keys = env_keys();
-
+    keys = env_keys();	/* rb_secure(4); */
     for (i=0; i<RARRAY(keys)->len; i++) {
 	VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
 	if (!NIL_P(val)) {
@@ -2226,9 +2245,11 @@
     int argc;
     VALUE *argv;
 {
-    VALUE result = rb_ary_new();
+    VALUE result;
     long i;
 
+    rb_secure(4);
+    result = rb_ary_new();
     for (i=0; i<argc; i++) {
 	rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
     }
@@ -2243,6 +2264,7 @@
     char **env;
 
     RETURN_ENUMERATOR(ehash, 0, 0);
+    rb_secure(4);
     result = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
@@ -2267,9 +2289,7 @@
     volatile VALUE keys;
     long i;
 
-    rb_secure(4);
-    keys = env_keys();
-
+    keys = env_keys();	/* rb_secure(4); */
     for (i=0; i<RARRAY(keys)->len; i++) {
 	VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
 	if (!NIL_P(val)) {
@@ -2289,9 +2309,10 @@
 env_inspect()
 {
     char **env;
-    VALUE str = rb_str_buf_new2("{");
-    VALUE i;
+    VALUE str, i;
 
+    rb_secure(4);
+    str = rb_str_buf_new2("{");
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2319,8 +2340,10 @@
 env_to_a()
 {
     char **env;
-    VALUE ary = rb_ary_new();
+    VALUE ary;
 
+    rb_secure(4);
+    ary = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2346,6 +2369,7 @@
     int i;
     char **env;
 
+    rb_secure(4);
     env = GET_ENVIRON(environ);
     for(i=0; env[i]; i++)
 	;
@@ -2358,6 +2382,7 @@
 {
     char **env;
 
+    rb_secure(4);
     env = GET_ENVIRON(environ);
     if (env[0] == 0) {
 	FREE_ENVIRON(environ);
@@ -2373,6 +2398,7 @@
 {
     char *s;
 
+    rb_secure(4);
     s = StringValuePtr(key);
     if (strlen(s) != RSTRING(key)->len)
 	rb_raise(rb_eArgError, "bad environment variable name");
@@ -2386,7 +2412,9 @@
 {
     char **env;
 
-    if (TYPE(value) != T_STRING) return Qfalse;
+    rb_secure(4);
+    value = rb_check_string_type(value);
+    if (NIL_P(value)) return Qfalse;
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2410,6 +2438,7 @@
     char **env;
     VALUE str;
 
+    rb_secure(4);
     StringValue(value);
     env = GET_ENVIRON(environ);
     while (*env) {
@@ -2438,6 +2467,7 @@
 
     rb_warn("ENV.%s is deprecated; use ENV.values_at",
 	    rb_id2name(rb_frame_last_func()));
+    rb_secure(4);
     for (i=0;i<argc;i++) {
 	VALUE tmp = rb_check_string_type(argv[i]);
 	if (NIL_P(tmp)) {
@@ -2456,8 +2486,10 @@
 env_to_hash()
 {
     char **env;
-    VALUE hash = rb_hash_new();
+    VALUE hash;
 
+    rb_secure(4);
+    hash = rb_hash_new();
     env = GET_ENVIRON(environ);
     while (*env) {
 	char *s = strchr(*env, '=');
@@ -2482,6 +2514,7 @@
 {
     char **env;
 
+    rb_secure(4);
     env = GET_ENVIRON(environ);
     if (*env) {
 	char *s = strchr(*env, '=');
@@ -2519,9 +2552,10 @@
 env_replace(env, hash)
     VALUE env, hash;
 {
-    volatile VALUE keys = env_keys();
+    volatile VALUE keys;
     long i;
 
+    keys = env_keys();	/* rb_secure(4); */
     if (env == hash) return env;
     hash = to_hash(hash);
     rb_hash_foreach(hash, env_replace_i, keys);
@@ -2549,6 +2583,7 @@
 env_update(env, hash)
     VALUE env, hash;
 {
+    rb_secure(4);
     if (env == hash) return env;
     hash = to_hash(hash);
     rb_hash_foreach(hash, env_update_i, 0);
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 16592)
+++ ruby_1_8/ChangeLog	(revision 16593)
@@ -1,3 +1,19 @@
+Mon May 26 03:16:20 2008  Akinori MUSHA  <knu@i...>
+
+	* hash.c (rb_hash_default): Fix rdoc.
+	  (rb_hash_each, env_each_value, env_each_pair): Return an
+	  enumerator if no block is given.
+	  (rb_hash_update): Update rdoc.
+	  (envix): Conditionalize the definition itself.
+	  (rb_f_getenv, env_fetch, env_keys, env_values, env_values_at)
+	  (env_select, env_inspect, env_to_a, env_empty_p, env_has_key)
+	  (env_has_value, env_index, env_indexes, env_to_hash, env_shift)
+	  (env_update): Require secure level 4.
+	  (env_each_value, env_each_i): Delay variable initialization.
+	  (env_each_key, env_each_value, env_reject_bang)
+	  (env_clear, env_replace): Omit duplicated secure level check.
+	  (env_has_value): Do to_str conversion.
+
 Sun May 25 19:48:12 2008  Akinori MUSHA  <knu@i...>
 
 	* hash.c (env_delete_if): Return an enumerator if no block is

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]