зеркало из https://github.com/github/ruby.git
* hash.c (rb_hash_rehash): replace st_foreach() by its deep
checking counterpart. [ruby-dev:24310] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2c17921671
Коммит
f1f0f39e03
|
@ -1,3 +1,8 @@
|
|||
Thu Sep 23 09:29:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* hash.c (rb_hash_rehash): replace st_foreach() by its deep
|
||||
checking counterpart. [ruby-dev:24310]
|
||||
|
||||
Wed Sep 22 14:21:54 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* parse.y [ripper]: on__scan event removed.
|
||||
|
|
19
array.c
19
array.c
|
@ -97,7 +97,7 @@ rb_ary_frozen_p(ary)
|
|||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE ary_alloc _((VALUE));
|
||||
static VALUE ary_alloc(VALUE);
|
||||
static VALUE
|
||||
ary_alloc(klass)
|
||||
VALUE klass;
|
||||
|
@ -1673,9 +1673,12 @@ sort_1(a, b, data)
|
|||
struct ary_sort_data *data;
|
||||
{
|
||||
VALUE retval = rb_yield_values(2, *a, *b);
|
||||
int n;
|
||||
|
||||
ary_sort_check(data);
|
||||
return rb_cmpint(retval, *a, *b);
|
||||
n = rb_cmpint(retval, *a, *b);
|
||||
ary_sort_check(data);
|
||||
return n;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1684,11 +1687,12 @@ sort_2(ap, bp, data)
|
|||
struct ary_sort_data *data;
|
||||
{
|
||||
VALUE retval;
|
||||
long a = (long)*ap, b = (long)*bp;
|
||||
VALUE a = *ap, b = *bp;
|
||||
int n;
|
||||
|
||||
if (FIXNUM_P(a) && FIXNUM_P(b)) {
|
||||
if (a > b) return 1;
|
||||
if (a < b) return -1;
|
||||
if ((long)a > (long)b) return 1;
|
||||
if ((long)a < (long)b) return -1;
|
||||
return 0;
|
||||
}
|
||||
if (TYPE(a) == T_STRING && TYPE(b) == T_STRING) {
|
||||
|
@ -1697,7 +1701,10 @@ sort_2(ap, bp, data)
|
|||
|
||||
retval = rb_funcall(a, id_cmp, 1, b);
|
||||
ary_sort_check(data);
|
||||
return rb_cmpint(retval, a, b);
|
||||
n = rb_cmpint(retval, a, b);
|
||||
ary_sort_check(data);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
18
eval.c
18
eval.c
|
@ -924,6 +924,7 @@ static struct tag *prot_tag;
|
|||
#define PROT_LOOP INT2FIX(1) /* 3 */
|
||||
#define PROT_LAMBDA INT2FIX(2) /* 5 */
|
||||
#define PROT_YIELD INT2FIX(3) /* 7 */
|
||||
#define PROT_TOP INT2FIX(4) /* 9 */
|
||||
|
||||
#define EXEC_TAG() (FLUSH_REGISTER_WINDOWS, setjmp(prot_tag->buf))
|
||||
|
||||
|
@ -947,7 +948,7 @@ static struct tag *prot_tag;
|
|||
#define TAG_RAISE 0x6
|
||||
#define TAG_THROW 0x7
|
||||
#define TAG_FATAL 0x8
|
||||
#define TAG_CONT 0x9
|
||||
#define TAG_CONTCALL 0x9
|
||||
#define TAG_MASK 0xf
|
||||
|
||||
VALUE ruby_class;
|
||||
|
@ -1442,6 +1443,8 @@ ruby_cleanup(ex)
|
|||
|
||||
extern NODE *ruby_eval_tree;
|
||||
|
||||
static void cont_call _((VALUE));
|
||||
|
||||
int
|
||||
ruby_exec()
|
||||
{
|
||||
|
@ -1449,13 +1452,18 @@ ruby_exec()
|
|||
volatile NODE *tmp;
|
||||
|
||||
Init_stack((void*)&tmp);
|
||||
PUSH_TAG(PROT_NONE);
|
||||
PUSH_TAG(PROT_THREAD);
|
||||
PUSH_ITER(ITER_NOT);
|
||||
/* default visibility is private at toplevel */
|
||||
SCOPE_SET(SCOPE_PRIVATE);
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
eval_node(ruby_top_self, ruby_eval_tree);
|
||||
}
|
||||
#if 0
|
||||
else if (state == TAG_CONTCALL) {
|
||||
cont_call(prot_tag->retval);
|
||||
}
|
||||
#endif
|
||||
POP_ITER();
|
||||
POP_TAG();
|
||||
return state;
|
||||
|
@ -5869,10 +5877,11 @@ backtrace(lev)
|
|||
{
|
||||
struct FRAME *frame = ruby_frame;
|
||||
char buf[BUFSIZ];
|
||||
VALUE ary;
|
||||
volatile VALUE ary;
|
||||
NODE *n;
|
||||
|
||||
ary = rb_ary_new();
|
||||
fprintf(stderr, "<ary=%p(0x%x)\n", ary, BUILTIN_TYPE(ary));
|
||||
if (frame->last_func == ID_ALLOCATOR) {
|
||||
frame = frame->prev;
|
||||
}
|
||||
|
@ -5889,7 +5898,9 @@ backtrace(lev)
|
|||
else {
|
||||
snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
|
||||
}
|
||||
fprintf(stderr, "=ary=%p(0x%x)\n", ary, BUILTIN_TYPE(ary));
|
||||
rb_ary_push(ary, rb_str_new2(buf));
|
||||
fprintf(stderr, "#ary=%p(0x%x)\n", ary, BUILTIN_TYPE(ary));
|
||||
if (lev < -1) return ary;
|
||||
}
|
||||
else {
|
||||
|
@ -5901,6 +5912,7 @@ backtrace(lev)
|
|||
}
|
||||
}
|
||||
}
|
||||
fprintf(stderr, ">ary=%p(0x%x)\n", ary, BUILTIN_TYPE(ary));
|
||||
while (frame && (n = frame->node)) {
|
||||
if (frame->prev && frame->prev->last_func) {
|
||||
snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
|
||||
|
|
2
file.c
2
file.c
|
@ -3001,7 +3001,7 @@ rb_file_truncate(obj, len)
|
|||
# define LOCK_UN 8
|
||||
# endif
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
static int
|
||||
rb_thread_flock(fd, op, fptr)
|
||||
int fd, op;
|
||||
|
|
75
hash.c
75
hash.c
|
@ -104,16 +104,16 @@ static struct st_hash_type objhash = {
|
|||
rb_any_hash,
|
||||
};
|
||||
|
||||
struct rb_hash_foreach_arg {
|
||||
struct hash_foreach_arg {
|
||||
VALUE hash;
|
||||
enum st_retval (*func)();
|
||||
VALUE arg;
|
||||
};
|
||||
|
||||
static int
|
||||
rb_hash_foreach_iter(key, value, arg, err)
|
||||
hash_foreach_iter(key, value, arg, err)
|
||||
VALUE key, value;
|
||||
struct rb_hash_foreach_arg *arg;
|
||||
struct hash_foreach_arg *arg;
|
||||
int err;
|
||||
{
|
||||
int status;
|
||||
|
@ -141,15 +141,7 @@ rb_hash_foreach_iter(key, value, arg, err)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_hash_foreach_call(arg)
|
||||
struct rb_hash_foreach_arg *arg;
|
||||
{
|
||||
st_foreach(RHASH(arg->hash)->tbl, rb_hash_foreach_iter, (st_data_t)arg);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_hash_foreach_ensure(hash)
|
||||
hash_foreach_ensure(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
RHASH(hash)->iter_lev--;
|
||||
|
@ -163,22 +155,31 @@ rb_hash_foreach_ensure(hash)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
hash_foreach_call(arg)
|
||||
struct hash_foreach_arg *arg;
|
||||
{
|
||||
st_foreach(RHASH(arg->hash)->tbl, hash_foreach_iter, (st_data_t)arg);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static int
|
||||
rb_hash_foreach(hash, func, farg)
|
||||
hash_foreach(hash, func, farg)
|
||||
VALUE hash;
|
||||
enum st_retval (*func)();
|
||||
VALUE farg;
|
||||
{
|
||||
struct rb_hash_foreach_arg arg;
|
||||
struct hash_foreach_arg arg;
|
||||
|
||||
RHASH(hash)->iter_lev++;
|
||||
arg.hash = hash;
|
||||
arg.func = func;
|
||||
arg.arg = farg;
|
||||
return rb_ensure(rb_hash_foreach_call, (VALUE)&arg, rb_hash_foreach_ensure, hash);
|
||||
return rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
|
||||
}
|
||||
|
||||
static VALUE hash_alloc _((VALUE));
|
||||
|
||||
static VALUE
|
||||
hash_alloc(klass)
|
||||
VALUE klass;
|
||||
|
@ -357,7 +358,7 @@ rb_hash_rehash(hash)
|
|||
}
|
||||
rb_hash_modify(hash);
|
||||
tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
|
||||
st_foreach(RHASH(hash)->tbl, rb_hash_rehash_i, (st_data_t)tbl);
|
||||
hash_foreach(hash, rb_hash_rehash_i, (st_data_t)tbl);
|
||||
st_free_table(RHASH(hash)->tbl);
|
||||
RHASH(hash)->tbl = tbl;
|
||||
|
||||
|
@ -569,7 +570,7 @@ rb_hash_key(hash, value)
|
|||
args[0] = value;
|
||||
args[1] = Qnil;
|
||||
|
||||
st_foreach(RHASH(hash)->tbl, key_i, (st_data_t)args);
|
||||
hash_foreach(hash, key_i, (st_data_t)args);
|
||||
|
||||
return args[1];
|
||||
}
|
||||
|
@ -661,7 +662,7 @@ rb_hash_shift(hash)
|
|||
|
||||
rb_hash_modify(hash);
|
||||
var.stop = 0;
|
||||
st_foreach(RHASH(hash)->tbl, shift_i, (st_data_t)&var);
|
||||
hash_foreach(hash, shift_i, (st_data_t)&var);
|
||||
|
||||
if (var.stop) {
|
||||
return rb_assoc_new(var.key, var.val);
|
||||
|
@ -702,7 +703,7 @@ rb_hash_delete_if(hash)
|
|||
VALUE hash;
|
||||
{
|
||||
rb_hash_modify(hash);
|
||||
rb_hash_foreach(hash, delete_if_i, hash);
|
||||
hash_foreach(hash, delete_if_i, hash);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -797,7 +798,7 @@ rb_hash_select(hash)
|
|||
VALUE result;
|
||||
|
||||
result = rb_ary_new();
|
||||
rb_hash_foreach(hash, select_i, result);
|
||||
hash_foreach(hash, select_i, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -827,7 +828,7 @@ rb_hash_clear(hash)
|
|||
|
||||
rb_hash_modify(hash);
|
||||
if (RHASH(hash)->tbl->num_entries > 0) {
|
||||
st_foreach(RHASH(hash)->tbl, clear_i, 0);
|
||||
hash_foreach(hash, clear_i, 0);
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
@ -895,7 +896,7 @@ rb_hash_replace(hash, hash2)
|
|||
hash2 = to_hash(hash2);
|
||||
if (hash == hash2) return hash;
|
||||
rb_hash_clear(hash);
|
||||
st_foreach(RHASH(hash2)->tbl, replace_i, hash);
|
||||
hash_foreach(hash2, replace_i, hash);
|
||||
RHASH(hash)->ifnone = RHASH(hash2)->ifnone;
|
||||
if (FL_TEST(hash2, HASH_PROC_DEFAULT)) {
|
||||
FL_SET(hash, HASH_PROC_DEFAULT);
|
||||
|
@ -976,7 +977,7 @@ static VALUE
|
|||
rb_hash_each_value(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
rb_hash_foreach(hash, each_value_i, 0);
|
||||
hash_foreach(hash, each_value_i, 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -1008,7 +1009,7 @@ static VALUE
|
|||
rb_hash_each_key(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
rb_hash_foreach(hash, each_key_i, 0);
|
||||
hash_foreach(hash, each_key_i, 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -1042,7 +1043,7 @@ static VALUE
|
|||
rb_hash_each_pair(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
rb_hash_foreach(hash, each_pair_i, 0);
|
||||
hash_foreach(hash, each_pair_i, 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -1079,7 +1080,7 @@ static VALUE
|
|||
rb_hash_each(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
rb_hash_foreach(hash, each_i, 0);
|
||||
hash_foreach(hash, each_i, 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -1110,7 +1111,7 @@ rb_hash_to_a(hash)
|
|||
VALUE ary;
|
||||
|
||||
ary = rb_ary_new();
|
||||
st_foreach(RHASH(hash)->tbl, to_a_i, ary);
|
||||
hash_foreach(hash, to_a_i, ary);
|
||||
if (OBJ_TAINTED(hash)) OBJ_TAINT(ary);
|
||||
|
||||
return ary;
|
||||
|
@ -1168,7 +1169,7 @@ inspect_hash(hash)
|
|||
VALUE str;
|
||||
|
||||
str = rb_str_buf_new2("{");
|
||||
st_foreach(RHASH(hash)->tbl, inspect_i, str);
|
||||
hash_foreach(hash, inspect_i, str);
|
||||
rb_str_buf_cat2(str, "}");
|
||||
OBJ_INFECT(str, hash);
|
||||
|
||||
|
@ -1262,7 +1263,7 @@ rb_hash_keys(hash)
|
|||
VALUE ary;
|
||||
|
||||
ary = rb_ary_new();
|
||||
st_foreach(RHASH(hash)->tbl, keys_i, ary);
|
||||
hash_foreach(hash, keys_i, ary);
|
||||
|
||||
return ary;
|
||||
}
|
||||
|
@ -1295,7 +1296,7 @@ rb_hash_values(hash)
|
|||
VALUE ary;
|
||||
|
||||
ary = rb_ary_new();
|
||||
st_foreach(RHASH(hash)->tbl, values_i, ary);
|
||||
hash_foreach(hash, values_i, ary);
|
||||
|
||||
return ary;
|
||||
}
|
||||
|
@ -1360,7 +1361,7 @@ rb_hash_has_value(hash, val)
|
|||
|
||||
data[0] = Qfalse;
|
||||
data[1] = val;
|
||||
st_foreach(RHASH(hash)->tbl, rb_hash_search_value, (st_data_t)data);
|
||||
hash_foreach(hash, rb_hash_search_value, (st_data_t)data);
|
||||
return data[0];
|
||||
}
|
||||
|
||||
|
@ -1412,7 +1413,7 @@ hash_equal(hash1, hash2, eql)
|
|||
|
||||
data.tbl = RHASH(hash2)->tbl;
|
||||
data.result = Qtrue;
|
||||
st_foreach(RHASH(hash1)->tbl, equal_i, (st_data_t)&data);
|
||||
hash_foreach(hash1, equal_i, (st_data_t)&data);
|
||||
|
||||
return data.result;
|
||||
}
|
||||
|
@ -1487,7 +1488,7 @@ rb_hash_invert(hash)
|
|||
{
|
||||
VALUE h = rb_hash_new();
|
||||
|
||||
st_foreach(RHASH(hash)->tbl, rb_hash_invert_i, h);
|
||||
hash_foreach(hash, rb_hash_invert_i, h);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -1533,10 +1534,10 @@ rb_hash_update(hash1, hash2)
|
|||
{
|
||||
hash2 = to_hash(hash2);
|
||||
if (rb_block_given_p()) {
|
||||
st_foreach(RHASH(hash2)->tbl, rb_hash_update_block_i, hash1);
|
||||
hash_foreach(hash2, rb_hash_update_block_i, hash1);
|
||||
}
|
||||
else {
|
||||
st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1);
|
||||
hash_foreach(hash2, rb_hash_update_i, hash1);
|
||||
}
|
||||
return hash1;
|
||||
}
|
||||
|
@ -2294,7 +2295,7 @@ env_replace(env, hash)
|
|||
|
||||
if (env == hash) return env;
|
||||
hash = to_hash(hash);
|
||||
st_foreach(RHASH(hash)->tbl, env_replace_i, keys);
|
||||
hash_foreach(hash, env_replace_i, keys);
|
||||
|
||||
for (i=0; i<RARRAY(keys)->len; i++) {
|
||||
env_delete(env, RARRAY(keys)->ptr[i]);
|
||||
|
@ -2321,7 +2322,7 @@ env_update(env, hash)
|
|||
{
|
||||
if (env == hash) return env;
|
||||
hash = to_hash(hash);
|
||||
st_foreach(RHASH(hash)->tbl, env_update_i, 0);
|
||||
hash_foreach(hash, env_update_i, 0);
|
||||
return env;
|
||||
}
|
||||
|
||||
|
|
1
st.c
1
st.c
|
@ -3,7 +3,6 @@
|
|||
/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
|
||||
|
||||
#include "config.h"
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
4
st.h
4
st.h
|
@ -27,6 +27,10 @@ struct st_table {
|
|||
|
||||
enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
|
||||
|
||||
#ifndef _
|
||||
# define _(args) args
|
||||
#endif
|
||||
|
||||
st_table *st_init_table _((struct st_hash_type *));
|
||||
st_table *st_init_table_with_size _((struct st_hash_type *, int));
|
||||
st_table *st_init_numtable _((void));
|
||||
|
|
Загрузка…
Ссылка в новой задаче