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

ruby-changes:31595

From: nobu <ko1@a...>
Date: Thu, 14 Nov 2013 11:33:59 +0900 (JST)
Subject: [ruby-changes:31595] nobu:r43674 (trunk): hash.c, st.c: fix for ST_CHECK

nobu	2013-11-14 11:33:50 +0900 (Thu, 14 Nov 2013)

  New Revision: 43674

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43674

  Log:
    hash.c, st.c: fix for ST_CHECK
    
    * hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected
      by ST_CHECK.
    * st.c (st_foreach_check): call with non-error argument in normal case.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/st.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43673)
+++ ChangeLog	(revision 43674)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov 14 11:33:47 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected
+	  by ST_CHECK.
+
+	* st.c (st_foreach_check): call with non-error argument in normal case.
+
 Thu Nov 14 02:37:14 2013  Zachary Scott  <e@z...>
 
 	* ext/thread/thread.c: [DOC] This patch accomplishes the following:
Index: st.c
===================================================================
--- st.c	(revision 43673)
+++ st.c	(revision 43674)
@@ -948,7 +948,7 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L948
 	    val = PVAL(table, i);
 	    hash = PHASH(table, i);
 	    if (key == never) continue;
-	    retval = (*func)(key, val, arg);
+	    retval = (*func)(key, val, arg, 0);
 	    if (!table->entries_packed) {
 		FIND_ENTRY(table, ptr, hash, i);
 		if (retval == ST_CHECK) {
@@ -987,7 +987,7 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L987
 	    if (ptr->key == never)
 		goto unpacked_continue;
 	    i = ptr->hash % table->num_bins;
-	    retval = (*func)(ptr->key, ptr->record, arg);
+	    retval = (*func)(ptr->key, ptr->record, arg, 0);
 	  unpacked:
 	    switch (retval) {
 	      case ST_CHECK:	/* check if hash is modified during iteration */
@@ -1037,7 +1037,7 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L1037
 	    key = PKEY(table, i);
 	    val = PVAL(table, i);
 	    hash = PHASH(table, i);
-	    retval = (*func)(key, val, arg);
+	    retval = (*func)(key, val, arg, 0);
 	    if (!table->entries_packed) {
 		FIND_ENTRY(table, ptr, hash, i);
 		if (!ptr) return 0;
@@ -1064,7 +1064,7 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L1064
     if (ptr != 0) {
 	do {
 	    i = ptr->hash % table->num_bins;
-	    retval = (*func)(ptr->key, ptr->record, arg);
+	    retval = (*func)(ptr->key, ptr->record, arg, 0);
 	  unpacked:
 	    switch (retval) {
 	      case ST_CONTINUE:
@@ -1105,7 +1105,7 @@ st_reverse_foreach(st_table *table, int https://github.com/ruby/ruby/blob/trunk/st.c#L1105
             st_data_t key, val;
             key = PKEY(table, i);
             val = PVAL(table, i);
-            retval = (*func)(key, val, arg);
+            retval = (*func)(key, val, arg, 0);
             switch (retval) {
 	      case ST_CHECK:	/* check if hash is modified during iteration */
                 for (j = 0; j < table->num_entries; j++) {
Index: hash.c
===================================================================
--- hash.c	(revision 43673)
+++ hash.c	(revision 43674)
@@ -141,10 +141,12 @@ struct foreach_safe_arg { https://github.com/ruby/ruby/blob/trunk/hash.c#L141
 };
 
 static int
-foreach_safe_i(st_data_t key, st_data_t value, struct foreach_safe_arg *arg)
+foreach_safe_i(st_data_t key, st_data_t value, st_data_t args, int error)
 {
     int status;
+    struct foreach_safe_arg *arg = (void *)args;
 
+    if (error) return ST_STOP;
     status = (*arg->func)(key, value, arg->arg);
     if (status == ST_CONTINUE) {
 	return ST_CHECK;
@@ -174,12 +176,13 @@ struct hash_foreach_arg { https://github.com/ruby/ruby/blob/trunk/hash.c#L176
 };
 
 static int
-hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp)
+hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error)
 {
     struct hash_foreach_arg *arg = (struct hash_foreach_arg *)argp;
     int status;
     st_table *tbl;
 
+    if (error) return ST_STOP;
     tbl = RHASH(arg->hash)->ntbl;
     status = (*arg->func)((VALUE)key, (VALUE)value, arg->arg);
     if (RHASH(arg->hash)->ntbl != tbl) {

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

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