From f0221db4626bb589f230bf239a7f9df83d7e444f Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 28 Jun 2002 14:42:46 +0000 Subject: * re.c (rb_reg_expr_str): need to process backslashes properly. * object.c (rb_any_to_a): declare Object#to_a to be obsolete. * object.c (rb_Array): do not convert nil into [] automagically. * object.c (rb_Integer): use "to_int" instead of "to_i". [experimental] * object.c (nil_to_f): new method. * object.c (rb_Integer): Symbols and nil should cause error. * object.c (rb_Float): nil should cause error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 21 +++++++++++++++++++++ ext/tk/lib/tk.rb | 18 +++++++++--------- ext/tk/lib/tkcanvas.rb | 28 ++++++++++++++-------------- ext/tk/lib/tktext.rb | 32 ++++++++++++++++---------------- lib/mkmf.rb | 2 +- lib/pp.rb | 2 +- lib/tracer.rb | 2 +- lib/tsort.rb | 2 +- misc/ruby-mode.el | 1 + object.c | 36 ++++++++++++++++++++++++++++++++---- parse.y | 21 +++++++++------------ re.c | 10 +++++++++- sample/sieve.rb | 2 +- sample/test.rb | 3 +-- 14 files changed, 117 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d2b4b5b61..ac9513e743 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,16 @@ Thu Jun 27 08:28:18 2002 Nobuyoshi Nakada * parse.y (literal_concat_string): non-string last expression in #{} was ignored when followed by literal. +Thu Jun 27 03:42:04 2002 Yukihiro Matsumoto + + * re.c (rb_reg_expr_str): need to process backslashes properly. + +Wed Jun 26 17:33:38 2002 Yukihiro Matsumoto + + * object.c (rb_any_to_a): declare Object#to_a to be obsolete. + + * object.c (rb_Array): do not convert nil into [] automagically. + Wed Jun 26 15:40:00 2002 Nobuyoshi Nakada * parse.y (words, qwords): word list literal rules. @@ -39,6 +49,17 @@ Tue Jun 25 19:24:38 2002 KONISHI Hiromasa * dln.c: remove definition rb_loaderror(). +Tue Jun 25 00:34:54 2002 Yukihiro Matsumoto + + * object.c (rb_Integer): use "to_int" instead of + "to_i". [experimental] + + * object.c (nil_to_f): new method. + + * object.c (rb_Integer): Symbols and nil should cause error. + + * object.c (rb_Float): nil should cause error. + Tue Jun 25 00:21:00 2002 KONISHI Hiromasa * dln.c: remark definition rb_loaderror(). diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 2e33c4294c..bc9cb0676f 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -995,7 +995,7 @@ module Tk tk_call 'wm', 'title', path, *args end def transient(*args) - window(tk_call 'wm', 'transient', path, *args) + window(tk_call('wm', 'transient', path, *args)) end def withdraw tk_call 'wm', 'withdraw', path @@ -1475,7 +1475,7 @@ module TkSelection TkSelection.handle self, func, type, format end def TkSelection.own(win=None, func=None) - window(tk_call 'selection', 'own', win, func) + window(tk_call('selection', 'own', win, func)) end def own(func=None) TkSelection.own self, func @@ -1617,7 +1617,7 @@ module TkWinfo include Tk extend Tk def TkWinfo.atom(name) - number(tk_call 'winfo', 'atom', name) + number(tk_call('winfo', 'atom', name)) end def winfo_atom(name) TkWinfo.atom name @@ -1899,7 +1899,7 @@ module TkWinfo TkWinfo.y self end def TkWinfo.viewable(window) - bool(tk_call 'winfo', 'viewable', window.path) + bool(tk_call('winfo', 'viewable', window.path)) end def winfo_viewable TkWinfo.viewable self @@ -2469,7 +2469,7 @@ class TkObject #include #include +#include VALUE rb_mKernel; VALUE rb_cObject; @@ -134,6 +135,7 @@ static VALUE rb_any_to_a(obj) VALUE obj; { + rb_warn("default `to_a' will be obsolete"); return rb_ary_new3(1, obj); } @@ -337,6 +339,13 @@ nil_to_i(obj) return INT2FIX(0); } +static VALUE +nil_to_f(obj) + VALUE obj; +{ + return rb_float_new(0.0); +} + static VALUE nil_to_s(obj) VALUE obj; @@ -917,6 +926,7 @@ rb_check_convert_type(val, type, tname, method) return v; } + static VALUE rb_to_integer(val, method) VALUE val; @@ -941,6 +951,8 @@ VALUE rb_Integer(val) VALUE val; { + VALUE v; + switch (TYPE(val)) { case T_FLOAT: if (RFLOAT(val)->value <= (double)FIXNUM_MAX @@ -961,7 +973,13 @@ rb_Integer(val) default: break; } - return rb_to_integer(val, "to_i"); + + if (rb_respond_to(val, rb_intern("to_int"))) { + return rb_to_integer(val, "to_int"); + } + else { + return rb_to_integer(val, "to_i"); + } } static VALUE @@ -1073,10 +1091,17 @@ rb_Float(val) return rb_float_new(rb_str_to_dbl(val, Qtrue)); case T_NIL: - return rb_float_new(0.0); + rb_raise(rb_eTypeError, "cannot convert nil into Float"); + break; default: - return rb_convert_type(val, T_FLOAT, "Float", "to_f"); + { + VALUE f = rb_convert_type(val, T_FLOAT, "Float", "to_f"); + if (isnan(RFLOAT(f)->value)) { + rb_raise(rb_eArgError, "invalid value for Float()"); + } + return f; + } } } @@ -1143,6 +1168,9 @@ rb_Array(val) { ID to_ary; + if (NIL_P(val)) { + rb_raise(rb_eTypeError, "cannot convert nil into Array"); + } if (TYPE(val) == T_ARRAY) return val; to_ary = rb_intern("to_ary"); if (rb_respond_to(val, to_ary)) { @@ -1251,7 +1279,7 @@ Init_Object() rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0); rb_define_method(rb_mKernel, "frozen?", rb_obj_frozen_p, 0); - rb_define_method(rb_mKernel, "to_a", rb_any_to_a, 0); + rb_define_method(rb_mKernel, "to_a", rb_any_to_a, 0); /* to be removed */ rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0); rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0); rb_define_method(rb_mKernel, "methods", rb_obj_methods, 0); diff --git a/parse.y b/parse.y index 6ebeb201b8..287a497b8d 100644 --- a/parse.y +++ b/parse.y @@ -233,7 +233,7 @@ static void top_local_setup(); %type words qwords word_list qword_list word %type literal numeric %type bodystmt compstmt stmts stmt expr arg primary command command_call method_call -%type expr_value arg_value primary_value block_call_value +%type expr_value arg_value primary_value %type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type args when_args call_args call_args2 open_args paren_args opt_paren_args %type command_args aref_args opt_block_arg block_arg var_ref var_lhs @@ -605,11 +605,11 @@ command_call : command ; block_command : block_call - | block_call_value '.' operation2 command_args + | block_call '.' operation2 command_args { $$ = new_call($1, $3, $4); } - | block_call_value tCOLON2 operation2 command_args + | block_call tCOLON2 operation2 command_args { $$ = new_call($1, $3, $4); } @@ -1075,6 +1075,7 @@ arg_value : arg aref_args : none | command opt_nl { + rb_warn("parenthesize argument(s) for future version"); $$ = NEW_LIST($1); } | args trailer @@ -1107,10 +1108,12 @@ paren_args : '(' none ')' } | '(' block_call opt_nl ')' { + rb_warn("parenthesize argument for future version"); $$ = NEW_LIST($2); } | '(' args ',' block_call opt_nl ')' { + rb_warn("parenthesize argument for future version"); $$ = list_append($2, $4); } ; @@ -1121,6 +1124,7 @@ opt_paren_args : none call_args : command { + rb_warn("parenthesize argument(s) for future version"); $$ = NEW_LIST($1); } | args opt_block_arg @@ -1623,23 +1627,16 @@ block_call : command do_block $$ = $2; fixpos($$, $2); } - | block_call_value '.' operation2 opt_paren_args + | block_call '.' operation2 opt_paren_args { $$ = new_call($1, $3, $4); } - | block_call_value tCOLON2 operation2 opt_paren_args + | block_call tCOLON2 operation2 opt_paren_args { $$ = new_call($1, $3, $4); } ; -block_call_value : block_call - { - value_expr($$); - $$ = $1; - } - ; - method_call : operation paren_args { $$ = new_fcall($1, $2); diff --git a/re.c b/re.c index 6f7967ae65..0cb048be27 100644 --- a/re.c +++ b/re.c @@ -236,7 +236,14 @@ rb_reg_expr_str(str, s, len) else { p = s; while (p