1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bignum.c (rb_big_mul0): multiply two numbers (x, y) without

normalizing the result.  x should be a big number.
  [ruby-dev:26778]

* bignum.c (rb_big_pow): use rb_big_mul0() instead of
  rb_big_mul().

* array.c (rb_ary_or, rb_ary_and, rb_ary_plus, rb_ary_diff):
  revert the change on 2005-08-03.  Set operation on other item
  should have in separate methods.

* parse.y (shadowing_lvar_gen): warn when arguments shadows
  external local variables.

* parse.y (f_opt): optional arguments should not clobber external
  local variables.

* parse.y (f_rest_arg): rest arguments should not clobber external
  local variables.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-08-10 01:39:24 +00:00
parent 5a0361f84c
commit 160055b474
4 changed files with 81 additions and 42 deletions

View file

@ -1,3 +1,25 @@
Wed Aug 10 10:38:50 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (rb_big_mul0): multiply two numbers (x, y) without
normalizing the result. x should be a big number.
[ruby-dev:26778]
* bignum.c (rb_big_pow): use rb_big_mul0() instead of
rb_big_mul().
* array.c (rb_ary_or, rb_ary_and, rb_ary_plus, rb_ary_diff):
revert the change on 2005-08-03. Set operation on other item
should have in separate methods.
* parse.y (shadowing_lvar_gen): warn when arguments shadows
external local variables.
* parse.y (f_opt): optional arguments should not clobber external
local variables.
* parse.y (f_rest_arg): rest arguments should not clobber external
local variables.
Wed Aug 10 10:29:40 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: fix bug on handling __ruby2val_optkeys().
@ -14,6 +36,11 @@ Tue Aug 9 21:53:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (formal_assign): let default values override
arguments to zsuper. fixed: [ruby-dev:26743]
Tue Aug 9 20:30:19 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
* bignum.c (rb_big_coerce): allow bignum x bignum coercing.
[ruby-dev:26778]
Tue Aug 9 15:12:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c: remove dangerous 'rb_jump_tag's.

31
array.c
View file

@ -301,17 +301,6 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
static VALUE
make_ary(ary)
VALUE ary;
{
VALUE tmp = rb_check_array_type(ary);
if (NIL_P(tmp)) {
return rb_ary_new3(1, ary);
}
return tmp;
}
static VALUE
to_a(ary)
VALUE ary;
@ -2355,16 +2344,10 @@ VALUE
rb_ary_plus(x, y)
VALUE x, y;
{
VALUE tmp, z;
VALUE z;
long len;
tmp = rb_check_array_type(y);
if (NIL_P(tmp)) {
z = rb_ary_dup(x);
rb_ary_push(z, y);
return z;
}
y = tmp;
y = to_ary(y);
len = RARRAY(x)->len + RARRAY(y)->len;
z = rb_ary_new2(len);
MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
@ -2711,10 +2694,10 @@ static VALUE
rb_ary_diff(ary1, ary2)
VALUE ary1, ary2;
{
VALUE tmp, ary3, hash;
VALUE ary3, hash;
long i;
hash = ary_make_hash(make_ary(ary2), 0);
hash = ary_make_hash(to_ary(ary2), 0);
ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
@ -2742,9 +2725,9 @@ rb_ary_and(ary1, ary2)
VALUE hash, ary3, v, vv;
long i;
ary2 = make_ary(ary2);
ary2 = to_ary(ary2);
ary3 = rb_ary_new2(RARRAY(ary1)->len < RARRAY(ary2)->len ?
RARRAY(ary1)->len : RARRAY(ary2)->len);
RARRAY(ary1)->len : RARRAY(ary2)->len);
hash = ary_make_hash(ary2, 0);
for (i=0; i<RARRAY(ary1)->len; i++) {
@ -2776,7 +2759,7 @@ rb_ary_or(ary1, ary2)
VALUE v, vv;
long i;
ary2 = make_ary(ary2);
ary2 = to_ary(ary2);
ary3 = rb_ary_new2(RARRAY(ary1)->len+RARRAY(ary2)->len);
hash = ary_make_hash(ary1, ary2);

View file

@ -1214,15 +1214,8 @@ rb_big_minus(x, y)
}
}
/*
* call-seq:
* big * other => Numeric
*
* Multiplies big and other, returning the result.
*/
VALUE
rb_big_mul(x, y)
static VALUE
rb_big_mul0(x, y)
VALUE x, y;
{
long i, j;
@ -1230,7 +1223,6 @@ rb_big_mul(x, y)
VALUE z;
BDIGIT *zds;
if (FIXNUM_P(x)) x = rb_int2big(FIX2LONG(x));
switch (TYPE(y)) {
case T_FIXNUM:
y = rb_int2big(FIX2LONG(y));
@ -1264,8 +1256,21 @@ rb_big_mul(x, y)
zds[i + j] = n;
}
}
return z;
}
return bignorm(z);
/*
* call-seq:
* big * other => Numeric
*
* Multiplies big and other, returning the result.
*/
VALUE
rb_big_mul(x, y)
VALUE x, y;
{
return bignorm(rb_big_mul0(x, y));
}
static void
@ -1619,9 +1624,9 @@ rb_big_pow(x, y)
if (yy == 0) break;
while (yy % 2 == 0) {
yy /= 2;
x = rb_big_mul(x, x);
x = rb_big_mul0(x, x);
}
z = rb_big_mul(z, x);
z = rb_big_mul0(z, x);
}
return bignorm(z);
}
@ -1979,6 +1984,9 @@ rb_big_coerce(x, y)
if (FIXNUM_P(y)) {
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
}
else if (TYPE(y) == T_BIGNUM) {
return rb_assoc_new(y, x);
}
else {
rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
rb_obj_classname(y));

31
parse.y
View file

@ -247,6 +247,8 @@ static NODE *call_op_gen _((struct parser_params*,NODE*,ID,int,NODE*));
static NODE *new_args_gen _((struct parser_params*,VALUE,NODE*,NODE*,NODE*));
#define new_args(f,o,r,b) new_args_gen(parser, f,o,r,b)
static void shadowing_lvar_gen _((struct parser_params*,ID));
#define shadowing_lvar(name) shadowing_lvar_gen(parser, name)
static NODE *negate_lit _((NODE*));
static NODE *ret_args _((NODE*));
@ -4097,6 +4099,7 @@ f_norm_arg : tCONSTANT
if (!is_local_id($1))
yyerror("formal argument must be local variable");
if (dyna_in_block()) {
shadowing_lvar($1);
dyna_var($1);
}
else {
@ -4110,7 +4113,9 @@ f_norm_arg : tCONSTANT
;
f_arg : f_norm_arg
{ $$ = rb_ary_new3(1, ID2SYM($1)); }
{
$$ = rb_ary_new3(1, ID2SYM($1));
}
| f_arg ',' f_norm_arg
{
$$ = $1;
@ -4126,7 +4131,11 @@ f_opt : tIDENTIFIER '=' arg_value
/*%%%*/
if (!is_local_id($1))
yyerror("formal argument must be local variable");
$$ = assignable($1, $3);
if (dyna_in_block()) {
shadowing_lvar($1);
dyna_var($1);
}
$$ = assignable($1, $3);
/*%
$$ = rb_assoc_new($1, $3);
%*/
@ -4161,6 +4170,10 @@ f_rest_arg : restarg_mark tIDENTIFIER
/*%%%*/
if (!is_local_id($2))
yyerror("rest argument must be local variable");
if (dyna_in_block()) {
shadowing_lvar($2);
dyna_var($2);
}
$$ = assignable($2, 0);
/*%
$$ = dispatch1(restparam, $2);
@ -7303,6 +7316,16 @@ assignable_gen(parser, id, val)
return 0;
}
static void
shadowing_lvar_gen(parser, name)
struct parser_params *parser;
ID name;
{
if (rb_dvar_defined(name) || local_id(name)) {
rb_warningS("shadowing outer local variable - %s", rb_id2name(name));
}
}
static NODE*
new_bv_gen(parser, name, val)
struct parser_params *parser;
@ -7314,9 +7337,7 @@ new_bv_gen(parser, name, val)
rb_id2name(name));
return 0;
}
if (rb_dvar_defined(name) || local_id(name)) {
rb_warningS("shadowing outer local variable - %s", rb_id2name(name));
}
shadowing_lvar(name);
dyna_var(name);
return NEW_DASGN_CURR(name, val);
}