зеркало из https://github.com/github/ruby.git
* eval.c (rb_yield_0): no mvalue_to_svalue conversion here.
* eval.c (massign): takes svalue, convert it to mvalue inside. * eval.c (rb_eval): parameters for yield/return are always svalues now. * eval.c (svalue_to_mvalue): more strict conversion. * eval.c (mvalue_to_svalue): ditto. * st.c (new_size): prime hash size enabled. * ext/socket/socket.c (Init_socket): SO_* constants added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ef8e0b4dff
Коммит
def42c9a0c
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
Fri Jun 22 18:08:45 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_yield_0): no mvalue_to_svalue conversion here.
|
||||
|
||||
* eval.c (massign): takes svalue, convert it to mvalue inside.
|
||||
|
||||
* eval.c (rb_eval): parameters for yield/return are always
|
||||
svalues now.
|
||||
|
||||
* eval.c (svalue_to_mvalue): more strict conversion.
|
||||
|
||||
* eval.c (mvalue_to_svalue): ditto.
|
||||
|
||||
Fri Jun 22 17:12:23 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* st.c (new_size): prime hash size enabled.
|
||||
|
||||
* ext/socket/socket.c (Init_socket): SO_* constants added.
|
||||
|
||||
Tue Jun 19 22:24:07 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* gc.c (rb_setjmp): avoid GCC 3.0 warnings.
|
||||
|
|
59
eval.c
59
eval.c
|
@ -2005,7 +2005,11 @@ svalue_to_mvalue(v)
|
|||
VALUE v;
|
||||
{
|
||||
if (NIL_P(v)) return rb_ary_new2(0);
|
||||
if (TYPE(v) != T_ARRAY) {
|
||||
if (TYPE(v) == T_ARRAY) {
|
||||
if (RARRAY(v)->len > 1) return v;
|
||||
return rb_ary_new3(1, v);
|
||||
}
|
||||
else {
|
||||
v = rb_ary_to_ary(v);
|
||||
}
|
||||
return v;
|
||||
|
@ -2021,9 +2025,7 @@ mvalue_to_svalue(v)
|
|||
if (RARRAY(v)->len == 0) {
|
||||
return Qnil;
|
||||
}
|
||||
if (RARRAY(v)->len == 1 &&
|
||||
!NIL_P(RARRAY(v)->ptr[0]) &&
|
||||
TYPE(RARRAY(v)->ptr[0]) != T_ARRAY) {
|
||||
if (RARRAY(v)->len == 1) {
|
||||
return RARRAY(v)->ptr[0];
|
||||
}
|
||||
return v;
|
||||
|
@ -2374,16 +2376,20 @@ rb_eval(self, n)
|
|||
|
||||
case NODE_RESTARGS:
|
||||
case NODE_RESTARY:
|
||||
result = svalue_to_mvalue(rb_eval(self, node->nd_head));
|
||||
result = rb_ary_to_ary(rb_eval(self, node->nd_head));
|
||||
break;
|
||||
|
||||
case NODE_REXPAND:
|
||||
case NODE_SVALUE:
|
||||
result = mvalue_to_svalue(rb_eval(self, node->nd_head));
|
||||
break;
|
||||
|
||||
case NODE_MVALUE:
|
||||
result = svalue_to_mvalue(rb_eval(self, node->nd_head));
|
||||
break;
|
||||
|
||||
case NODE_YIELD:
|
||||
if (node->nd_stts) {
|
||||
result = rb_eval(self, node->nd_stts);
|
||||
result = mvalue_to_svalue(rb_eval(self, node->nd_stts));
|
||||
}
|
||||
else {
|
||||
result = Qnil;
|
||||
|
@ -2526,7 +2532,7 @@ rb_eval(self, n)
|
|||
|
||||
case NODE_RETURN:
|
||||
if (node->nd_stts) {
|
||||
return_value(rb_eval(self, node->nd_stts));
|
||||
return_value(mvalue_to_svalue(rb_eval(self, node->nd_stts)));
|
||||
}
|
||||
else {
|
||||
return_value(Qnil);
|
||||
|
@ -2537,7 +2543,7 @@ rb_eval(self, n)
|
|||
|
||||
case NODE_ARGSCAT:
|
||||
result = rb_ary_concat(rb_eval(self, node->nd_head),
|
||||
svalue_to_mvalue(rb_eval(self, node->nd_body)));
|
||||
rb_eval(self, node->nd_body));
|
||||
break;
|
||||
|
||||
case NODE_ARGSPUSH:
|
||||
|
@ -3620,18 +3626,10 @@ rb_yield_0(val, self, klass, pcall)
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (nd_type(block->var) == NODE_MASGN)
|
||||
if (nd_type(block->var) == NODE_MASGN) {
|
||||
massign(self, block->var, val, pcall);
|
||||
}
|
||||
else {
|
||||
/* argument adjust for proc_call etc. */
|
||||
if (pcall) {
|
||||
if (RARRAY(val)->len == 1) {
|
||||
val = RARRAY(val)->ptr[0];
|
||||
}
|
||||
else {
|
||||
val = mvalue_to_svalue(val);
|
||||
}
|
||||
}
|
||||
assign(self, block->var, val, pcall);
|
||||
}
|
||||
}
|
||||
|
@ -3639,10 +3637,6 @@ rb_yield_0(val, self, klass, pcall)
|
|||
POP_TAG();
|
||||
if (state) goto pop_state;
|
||||
}
|
||||
else if (pcall) {
|
||||
/* argument adjust for proc_call etc. */
|
||||
val = mvalue_to_svalue(val);
|
||||
}
|
||||
|
||||
PUSH_ITER(block->iter);
|
||||
PUSH_TAG(PROT_NONE);
|
||||
|
@ -3744,9 +3738,7 @@ massign(self, node, val, pcall)
|
|||
NODE *list;
|
||||
int i = 0, len;
|
||||
|
||||
if (!pcall) {
|
||||
val = svalue_to_mvalue(val);
|
||||
}
|
||||
val = svalue_to_mvalue(val);
|
||||
len = RARRAY(val)->len;
|
||||
list = node->nd_head;
|
||||
for (i=0; list && i<len; i++) {
|
||||
|
@ -6347,9 +6339,7 @@ proc_invoke(proc, args, pcall)
|
|||
PUSH_ITER(ITER_CUR);
|
||||
ruby_frame->iter = ITER_CUR;
|
||||
|
||||
if (!pcall) {
|
||||
args = mvalue_to_svalue(args);
|
||||
}
|
||||
args = mvalue_to_svalue(args);
|
||||
PUSH_TAG(PROT_NONE);
|
||||
state = EXEC_TAG();
|
||||
if (state == 0) {
|
||||
|
@ -6821,20 +6811,15 @@ static VALUE
|
|||
bmcall(args, method)
|
||||
VALUE args, method;
|
||||
{
|
||||
if (TYPE(args) == T_ARRAY) {
|
||||
return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
|
||||
}
|
||||
return method_call(1, &args, method);
|
||||
args = svalue_to_mvalue(args);
|
||||
return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
umcall(args, method)
|
||||
VALUE args, method;
|
||||
{
|
||||
if (TYPE(args) == T_ARRAY) {
|
||||
return umethod_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
|
||||
}
|
||||
return umethod_call(1, &args, method);
|
||||
return umethod_call(0, 0, method);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
|
@ -2259,6 +2259,50 @@ Init_socket()
|
|||
#ifdef SO_LINGER
|
||||
sock_define_const("SO_LINGER", SO_LINGER);
|
||||
#endif
|
||||
#ifdef SO_PASSCRED
|
||||
sock_define_const("SO_PASSCRED", SO_PASSCRED);
|
||||
#endif
|
||||
#ifdef SO_PEERCRED
|
||||
sock_define_const("SO_PEERCRED", SO_PEERCRED);
|
||||
#endif
|
||||
#ifdef SO_RCVLOWAT
|
||||
sock_define_const("SO_RCVLOWAT", SO_RCVLOWAT);
|
||||
#endif
|
||||
#ifdef SO_SNDLOWAT
|
||||
sock_define_const("SO_SNDLOWAT", SO_SNDLOWAT);
|
||||
#endif
|
||||
#ifdef SO_RCVTIMEO
|
||||
sock_define_const("SO_RCVTIMEO", SO_RCVTIMEO);
|
||||
#endif
|
||||
#ifdef SO_SNDTIMEO
|
||||
sock_define_const("SO_SNDTIMEO", SO_SNDTIMEO);
|
||||
#endif
|
||||
|
||||
#ifdef SO_SECURITY_AUTHENTICATION
|
||||
sock_define_const("SO_SECURITY_AUTHENTICATION", SO_SECURITY_AUTHENTICATION);
|
||||
#endif
|
||||
#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
|
||||
sock_define_const("SO_SECURITY_ENCRYPTION_TRANSPORT", SO_SECURITY_ENCRYPTION_TRANSPORT);
|
||||
#endif
|
||||
#ifdef SO_SECURITY_ENCRYPTION_NETWORK
|
||||
sock_define_const("SO_SECURITY_ENCRYPTION_NETWORK", SO_SECURITY_ENCRYPTION_NETWORK);
|
||||
#endif
|
||||
|
||||
#ifdef SO_BINDTODEVICE
|
||||
sock_define_const("SO_BINDTODEVICE", SO_BINDTODEVICE);
|
||||
#endif
|
||||
#ifdef SO_ATTACH_FILTER
|
||||
sock_define_const("SO_ATTACH_FILTER", SO_ATTACH_FILTER);
|
||||
#endif
|
||||
#ifdef SO_DETACH_FILTER
|
||||
sock_define_const("SO_DETACH_FILTER", SO_DETACH_FILTER);
|
||||
#endif
|
||||
#ifdef SO_PEERNAME
|
||||
sock_define_const("SO_PEERNAME", SO_PEERNAME);
|
||||
#endif
|
||||
#ifdef SO_TIMESTAMP
|
||||
sock_define_const("SO_TIMESTAMP", SO_TIMESTAMP);
|
||||
#endif
|
||||
|
||||
#ifdef SOPRI_INTERACTIVE
|
||||
sock_define_const("SOPRI_INTERACTIVE", SOPRI_INTERACTIVE);
|
||||
|
|
3
hash.c
3
hash.c
|
@ -668,7 +668,8 @@ static VALUE
|
|||
rb_hash_inspect(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
if (RHASH(hash)->tbl->num_entries == 0) return rb_str_new2("{}");
|
||||
if (RHASH(hash)->tbl == 0 || RHASH(hash)->tbl->num_entries == 0)
|
||||
return rb_str_new2("{}");
|
||||
if (rb_inspecting_p(hash)) return rb_str_new2("{...}");
|
||||
return rb_protect_inspect(inspect_hash, hash, 0);
|
||||
}
|
||||
|
|
8
io.c
8
io.c
|
@ -3461,10 +3461,14 @@ static void
|
|||
opt_i_set(val)
|
||||
VALUE val;
|
||||
{
|
||||
if (!RTEST(val)) {
|
||||
if (ruby_inplace_mode) free(ruby_inplace_mode);
|
||||
ruby_inplace_mode = 0;
|
||||
return;
|
||||
}
|
||||
StringValue(val);
|
||||
if (ruby_inplace_mode) free(ruby_inplace_mode);
|
||||
ruby_inplace_mode = 0;
|
||||
if (!RTEST(val)) return;
|
||||
StringValue(val);
|
||||
ruby_inplace_mode = strdup(RSTRING(val)->ptr);
|
||||
}
|
||||
|
||||
|
|
6
node.h
6
node.h
|
@ -90,7 +90,8 @@ enum node_type {
|
|||
NODE_ARGSPUSH,
|
||||
NODE_RESTARGS,
|
||||
NODE_RESTARY,
|
||||
NODE_REXPAND,
|
||||
NODE_SVALUE,
|
||||
NODE_MVALUE,
|
||||
NODE_BLOCK_ARG,
|
||||
NODE_BLOCK_PASS,
|
||||
NODE_DEFN,
|
||||
|
@ -307,7 +308,8 @@ typedef struct RNode {
|
|||
#define NEW_ARGSPUSH(a,b) rb_node_newnode(NODE_ARGSPUSH,a,b,0)
|
||||
#define NEW_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,a,0,0)
|
||||
#define NEW_RESTARY(a) rb_node_newnode(NODE_RESTARY,a,0,0)
|
||||
#define NEW_REXPAND(a) rb_node_newnode(NODE_REXPAND,a,0,0)
|
||||
#define NEW_SVALUE(a) rb_node_newnode(NODE_SVALUE,a,0,0)
|
||||
#define NEW_MVALUE(a) rb_node_newnode(NODE_MVALUE,a,0,0)
|
||||
#define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v))
|
||||
#define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0)
|
||||
#define NEW_ALIAS(n,o) rb_node_newnode(NODE_ALIAS,o,n,0)
|
||||
|
|
15
parse.y
15
parse.y
|
@ -426,7 +426,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
|||
}
|
||||
| lhs '=' mrhs_basic
|
||||
{
|
||||
$$ = node_assign($1, $3);
|
||||
$$ = node_assign($1, NEW_SVALUE($3));
|
||||
}
|
||||
| mlhs '=' mrhs
|
||||
{
|
||||
|
@ -1133,6 +1133,9 @@ mrhs : arg
|
|||
$$ = $1;
|
||||
}
|
||||
| mrhs_basic
|
||||
{
|
||||
$$ = NEW_SVALUE($1);
|
||||
}
|
||||
|
||||
mrhs_basic : args ',' arg
|
||||
{
|
||||
|
@ -1147,7 +1150,7 @@ mrhs_basic : args ',' arg
|
|||
| tSTAR arg
|
||||
{
|
||||
value_expr($2);
|
||||
$$ = NEW_REXPAND($2);
|
||||
$$ = $2;
|
||||
}
|
||||
|
||||
primary : literal
|
||||
|
@ -4666,16 +4669,10 @@ ret_args(node)
|
|||
NODE *node;
|
||||
{
|
||||
if (node) {
|
||||
if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
|
||||
node = node->nd_head;
|
||||
}
|
||||
else if (nd_type(node) == NODE_BLOCK_PASS) {
|
||||
if (nd_type(node) == NODE_BLOCK_PASS) {
|
||||
rb_compile_error("block argument should not be given");
|
||||
}
|
||||
}
|
||||
if (nd_type(node) == NODE_RESTARGS) {
|
||||
nd_set_type(node, NODE_REXPAND);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,27 +56,27 @@ a = *nil; test_ok(a == nil)
|
|||
a = *1; test_ok(a == 1)
|
||||
a = *[]; test_ok(a == nil)
|
||||
a = *[1]; test_ok(a == 1)
|
||||
a = *[nil]; test_ok(a == [nil])
|
||||
a = *[[]]; test_ok(a == [[]])
|
||||
a = *[nil]; test_ok(a == nil)
|
||||
a = *[[]]; test_ok(a == [])
|
||||
a = *[*[]]; test_ok(a == nil)
|
||||
a = *[*[1]]; test_ok(a == 1)
|
||||
a = *[*[1,2]]; test_ok(a == [1,2])
|
||||
|
||||
*a = nil; test_ok(a == [])
|
||||
*a = 1; test_ok(a == [1])
|
||||
*a = []; test_ok(a == [])
|
||||
*a = [1]; test_ok(a == [1])
|
||||
*a = [nil]; test_ok(a == [nil])
|
||||
*a = [[]]; test_ok(a == [[]])
|
||||
*a = [*[]]; test_ok(a == [])
|
||||
*a = [*[1]]; test_ok(a == [1])
|
||||
*a = []; test_ok(a == [[]])
|
||||
*a = [1]; test_ok(a == [[1]])
|
||||
*a = [nil]; test_ok(a == [[nil]])
|
||||
*a = [[]]; test_ok(a == [[[]]])
|
||||
*a = [*[]]; test_ok(a == [[]])
|
||||
*a = [*[1]]; test_ok(a == [[1]])
|
||||
*a = [*[1,2]]; test_ok(a == [1,2])
|
||||
|
||||
*a = *nil; test_ok(a == [])
|
||||
*a = *1; test_ok(a == [1])
|
||||
*a = *[]; test_ok(a == [])
|
||||
*a = *[1]; test_ok(a == [1])
|
||||
*a = *[nil]; test_ok(a == [nil])
|
||||
*a = *[nil]; test_ok(a == [])
|
||||
*a = *[[]]; test_ok(a == [[]])
|
||||
*a = *[*[]]; test_ok(a == [])
|
||||
*a = *[*[1]]; test_ok(a == [1])
|
||||
|
@ -84,12 +84,12 @@ a = *[*[1,2]]; test_ok(a == [1,2])
|
|||
|
||||
a,b,*c = nil; test_ok([a,b,c] == [nil, nil, []])
|
||||
a,b,*c = 1; test_ok([a,b,c] == [1, nil, []])
|
||||
a,b,*c = []; test_ok([a,b,c] == [nil, nil, []])
|
||||
a,b,*c = [1]; test_ok([a,b,c] == [1, nil, []])
|
||||
a,b,*c = [nil]; test_ok([a,b,c] == [nil, nil, []])
|
||||
a,b,*c = [[]]; test_ok([a,b,c] == [[], nil, []])
|
||||
a,b,*c = [*[]]; test_ok([a,b,c] == [nil, nil, []])
|
||||
a,b,*c = [*[1]]; test_ok([a,b,c] == [1, nil, []])
|
||||
a,b,*c = []; test_ok([a,b,c] == [[], nil, []])
|
||||
a,b,*c = [1]; test_ok([a,b,c] == [[1], nil, []])
|
||||
a,b,*c = [nil]; test_ok([a,b,c] == [[nil], nil, []])
|
||||
a,b,*c = [[]]; test_ok([a,b,c] == [[[]], nil, []])
|
||||
a,b,*c = [*[]]; test_ok([a,b,c] == [[], nil, []])
|
||||
a,b,*c = [*[1]]; test_ok([a,b,c] == [[1], nil, []])
|
||||
a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1, 2, []])
|
||||
|
||||
a,b,*c = *nil; test_ok([a,b,c] == [nil, nil, []])
|
||||
|
@ -116,27 +116,27 @@ def f; yield *nil; end; f {|a| test_ok(a == nil)}
|
|||
def f; yield *1; end; f {|a| test_ok(a == 1)}
|
||||
def f; yield *[]; end; f {|a| test_ok(a == nil)}
|
||||
def f; yield *[1]; end; f {|a| test_ok(a == 1)}
|
||||
def f; yield *[nil]; end; f {|a| test_ok(a == [nil])}
|
||||
def f; yield *[[]]; end; f {|a| test_ok(a == [[]])}
|
||||
def f; yield *[nil]; end; f {|a| test_ok(a == nil)}
|
||||
def f; yield *[[]]; end; f {|a| test_ok(a == [])}
|
||||
def f; yield *[*[]]; end; f {|a| test_ok(a == nil)}
|
||||
def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)}
|
||||
def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])}
|
||||
|
||||
def f; yield nil; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield 1; end; f {|*a| test_ok(a == [1])}
|
||||
def f; yield []; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield [1]; end; f {|*a| test_ok(a == [1])}
|
||||
def f; yield [nil]; end; f {|*a| test_ok(a == [nil])}
|
||||
def f; yield [[]]; end; f {|*a| test_ok(a == [[]])}
|
||||
def f; yield [*[]]; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])}
|
||||
def f; yield []; end; f {|*a| test_ok(a == [[]])}
|
||||
def f; yield [1]; end; f {|*a| test_ok(a == [[1]])}
|
||||
def f; yield [nil]; end; f {|*a| test_ok(a == [[nil]])}
|
||||
def f; yield [[]]; end; f {|*a| test_ok(a == [[[]]])}
|
||||
def f; yield [*[]]; end; f {|*a| test_ok(a == [[]])}
|
||||
def f; yield [*[1]]; end; f {|*a| test_ok(a == [[1]])}
|
||||
def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
|
||||
|
||||
def f; yield *nil; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield *1; end; f {|*a| test_ok(a == [1])}
|
||||
def f; yield *[]; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield *[1]; end; f {|*a| test_ok(a == [1])}
|
||||
def f; yield *[nil]; end; f {|*a| test_ok(a == [nil])}
|
||||
def f; yield *[nil]; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield *[[]]; end; f {|*a| test_ok(a == [[]])}
|
||||
def f; yield *[*[]]; end; f {|*a| test_ok(a == [])}
|
||||
def f; yield *[*[1]]; end; f {|*a| test_ok(a == [1])}
|
||||
|
@ -144,12 +144,12 @@ def f; yield *[*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
|
|||
|
||||
def f; yield nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
|
||||
def f; yield 1; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
|
||||
def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
|
||||
def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
|
||||
def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
|
||||
def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[], nil, []])}
|
||||
def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
|
||||
def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
|
||||
def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [[], nil, []])}
|
||||
def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [[1], nil, []])}
|
||||
def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [[nil], nil, []])}
|
||||
def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[[]], nil, []])}
|
||||
def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[], nil, []])}
|
||||
def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [[1], nil, []])}
|
||||
def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])}
|
||||
|
||||
def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
|
||||
|
@ -637,14 +637,19 @@ class IterTest
|
|||
def each6; @body.each { |*x| yield(x) } end
|
||||
def each7; @body.each { |x| yield(*x) } end
|
||||
def each8; @body.each { |x| yield(x) } end
|
||||
|
||||
def f(a)
|
||||
test_ok(a == [1])
|
||||
end
|
||||
end
|
||||
IterTest.new(nil).method(:f).to_proc.call([1])
|
||||
|
||||
IterTest.new([0]).each0 { |x| $x = x }
|
||||
test_ok($x == 0)
|
||||
IterTest.new([1]).each1 { |x| $x = x }
|
||||
test_ok($x == 1)
|
||||
IterTest.new([2]).each2 { |x| $x = x }
|
||||
test_ok($x == [2]); p $x
|
||||
test_ok($x == [2])
|
||||
IterTest.new([3]).each3 { |x| $x = x }
|
||||
test_ok($x == 3)
|
||||
IterTest.new([4]).each4 { |x| $x = x }
|
||||
|
@ -661,17 +666,17 @@ test_ok($x == 8)
|
|||
IterTest.new([[0]]).each0 { |x| $x = x }
|
||||
test_ok($x == [0])
|
||||
IterTest.new([[1]]).each1 { |x| $x = x }
|
||||
test_ok($x == 1)
|
||||
test_ok($x == [1])
|
||||
IterTest.new([[2]]).each2 { |x| $x = x }
|
||||
test_ok($x == [2]); p $x
|
||||
test_ok($x == [[2]])
|
||||
IterTest.new([[3]]).each3 { |x| $x = x }
|
||||
test_ok($x == 3)
|
||||
IterTest.new([[4]]).each4 { |x| $x = x }
|
||||
test_ok($x == [4]); p $x
|
||||
test_ok($x == [4])
|
||||
IterTest.new([[5]]).each5 { |x| $x = x }
|
||||
test_ok($x == 5)
|
||||
test_ok($x == [5])
|
||||
IterTest.new([[6]]).each6 { |x| $x = x }
|
||||
test_ok($x == [6])
|
||||
test_ok($x == [[6]])
|
||||
IterTest.new([[7]]).each7 { |x| $x = x }
|
||||
test_ok($x == 7)
|
||||
IterTest.new([[8]]).each8 { |x| $x = x }
|
||||
|
|
16
st.c
16
st.c
|
@ -65,7 +65,7 @@ static void rehash();
|
|||
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
|
||||
|
||||
#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
|
||||
#define do_hash_bin(key,table) (do_hash(key, table)&(table)->num_bins)
|
||||
#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
|
||||
|
||||
/*
|
||||
* MINSIZE is the minimum size of a dictionary.
|
||||
|
@ -114,12 +114,14 @@ new_size(size)
|
|||
{
|
||||
int i;
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
for (i=3; i<31; i++) {
|
||||
if ((1<<i) > size) return 1<<i;
|
||||
}
|
||||
return -1;
|
||||
#else
|
||||
int newsize;
|
||||
|
||||
for (i = 0, newsize = MINSIZE;
|
||||
i < sizeof(primes)/sizeof(primes[0]);
|
||||
i++, newsize <<= 1)
|
||||
|
@ -231,7 +233,7 @@ st_free_table(table)
|
|||
#endif
|
||||
|
||||
#define FIND_ENTRY(table, ptr, hash_val, bin_pos) \
|
||||
bin_pos = hash_val&(table)->num_bins;\
|
||||
bin_pos = hash_val%(table)->num_bins;\
|
||||
ptr = (table)->bins[bin_pos];\
|
||||
if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
|
||||
COLLISION;\
|
||||
|
@ -267,7 +269,7 @@ st_lookup(table, key, value)
|
|||
st_table_entry *entry;\
|
||||
if (table->num_entries/(table->num_bins+1) > ST_DEFAULT_MAX_DENSITY) {\
|
||||
rehash(table);\
|
||||
bin_pos = hash_val & table->num_bins;\
|
||||
bin_pos = hash_val % table->num_bins;\
|
||||
}\
|
||||
\
|
||||
entry = alloc(st_table_entry);\
|
||||
|
@ -311,7 +313,7 @@ st_add_direct(table, key, value)
|
|||
unsigned int hash_val, bin_pos;
|
||||
|
||||
hash_val = do_hash(key, table);
|
||||
bin_pos = hash_val & table->num_bins;
|
||||
bin_pos = hash_val % table->num_bins;
|
||||
ADD_DIRECT(table, key, value, hash_val, bin_pos);
|
||||
}
|
||||
|
||||
|
@ -331,7 +333,7 @@ rehash(table)
|
|||
ptr = table->bins[i];
|
||||
while (ptr != 0) {
|
||||
next = ptr->next;
|
||||
hash_val = ptr->hash & new_num_bins;
|
||||
hash_val = ptr->hash % new_num_bins;
|
||||
ptr->next = new_bins[hash_val];
|
||||
new_bins[hash_val] = ptr;
|
||||
ptr = next;
|
||||
|
@ -558,5 +560,5 @@ static int
|
|||
numhash(n)
|
||||
long n;
|
||||
{
|
||||
return n / 7;
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define RUBY_VERSION "1.7.1"
|
||||
#define RUBY_RELEASE_DATE "2001-06-19"
|
||||
#define RUBY_RELEASE_DATE "2001-06-22"
|
||||
#define RUBY_VERSION_CODE 171
|
||||
#define RUBY_RELEASE_CODE 20010619
|
||||
#define RUBY_RELEASE_CODE 20010622
|
||||
|
|
Загрузка…
Ссылка в новой задаче