From dde62bcd2efbb3825d982326896ab774e73e4218 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 17 Jan 2000 08:37:53 +0000 Subject: [PATCH] 2000-01-17 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 41 +++++++++ ToDo | 1 + enum.c | 165 ++++++++++++++-------------------- eval.c | 18 +++- ext/socket/socket.c | 8 +- ext/tk/lib/tk.rb | 196 +++++++++++++++++++++++++++++------------ ext/tk/lib/tkcanvas.rb | 18 ++-- ext/tk/lib/tktext.rb | 55 ++++++++++-- file.c | 5 +- io.c | 11 +-- lib/complex.rb | 32 ++++--- lib/parsedate.rb | 2 +- lib/timeout.rb | 2 - marshal.c | 4 +- missing/isnan.c | 13 +++ node.h | 3 + parse.y | 25 +++--- random.c | 8 +- rubyio.h | 3 +- string.c | 29 +----- version.h | 8 +- 21 files changed, 391 insertions(+), 256 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ab70f5e1b..f98ee50df9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +Sat Jan 15 22:21:08 2000 Nobuyoshi Nakada + + * eval.c (search_method): argument klass may be 0. + +Sat Jan 15 15:03:46 2000 Yukihiro Matsumoto + + * enum.c (enum_index): remove this method. + + * enum.c: remove use of pointers to local variables. find, + find_all, min, max, index, member?, each_with_index, + + * eval.c (massign): multiple assignment does not use to_a anymore. + experimental. + +Fri Jan 14 12:22:04 2000 Yukihiro Matsumoto + + * string.c (rb_str_replace): use memmove instead of memcpy for + overwrapping strings (e.g. a[1] = a). + +Thu Jan 13 11:12:40 2000 Yukihiro Matsumoto + + * parse.y (arg_add): use new node, ARGSPUSH. + +Mon Jan 10 18:32:28 2000 Koji Arai + + * marshal.c (w_object): forgot an argument to call w_ivar(). + +Sun Jan 9 18:13:51 2000 Katsuyuki Komatsu + + * random.c: first was not defined unless HAVE_RANDOM. + +Sat Jan 8 19:02:49 2000 Yukihiro Matsumoto + + * io.c (rb_io_sysread): raise IOError for buffered IO. + + * ext/socket/socket.c (s_recv): ditto. + Fri Jan 7 00:59:29 2000 Masahiro Tomita * io.c (io_fread): TRAP_BEG/TRAP_END added around getc(). @@ -123,6 +160,10 @@ Tue Dec 21 17:21:28 1999 Koji Oda * ext/socket/socket.c (sock_finalize): mswin32: fix FILE* leak. +Mon Dec 20 19:08:12 1999 Nobuyoshi Nakada + + * file.c (rb_file_s_expand_path): handle dir separetor correctly. + Sun Dec 19 22:56:31 1999 KANEKO Naoshi * lib/find.rb: support dosish root directory. diff --git a/ToDo b/ToDo index 66847b927a..dfd9a16cb1 100644 --- a/ToDo +++ b/ToDo @@ -34,6 +34,7 @@ Hacking Interpreter * syntax tree -> bytecode ??? * scrambled script, or script filter * setuid ruby +* freeze all object Standard Libraries diff --git a/enum.c b/enum.c index f6927c4e77..8d842bbd76 100644 --- a/enum.c +++ b/enum.c @@ -11,6 +11,7 @@ ************************************************/ #include "ruby.h" +#include "node.h" VALUE rb_mEnumerable; static ID id_each, id_eqq, id_cmp; @@ -58,19 +59,14 @@ enum_grep(obj, pat) return tmp; } -struct find_arg { - int found; - VALUE val; -}; - static VALUE -find_i(i, arg) +find_i(i, memo) VALUE i; - struct find_arg *arg; + NODE *memo; { if (RTEST(rb_yield(i))) { - arg->found = Qtrue; - arg->val = i; + memo->u2.value = Qtrue; + memo->u1.value = i; rb_iter_break(); } return Qnil; @@ -82,18 +78,19 @@ enum_find(argc, argv, obj) VALUE* argv; VALUE obj; { - struct find_arg arg; + NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, Qfalse, 0); VALUE if_none; rb_scan_args(argc, argv, "01", &if_none); - arg.found = Qfalse; - rb_iterate(rb_each, obj, find_i, (VALUE)&arg); - if (arg.found) { - return arg.val; + rb_iterate(rb_each, obj, find_i, (VALUE)memo); + if (memo->u2.value) { + rb_gc_force_recycle((VALUE)memo); + return memo->u1.value; } if (!NIL_P(if_none)) { rb_eval_cmd(if_none, Qnil); } + rb_gc_force_recycle((VALUE)memo); return Qnil; } @@ -189,33 +186,35 @@ enum_sort(obj) } static VALUE -min_i(i, min) - VALUE i, *min; +min_i(i, memo) + VALUE i; + NODE *memo; { VALUE cmp; - if (NIL_P(*min)) - *min = i; + if (NIL_P(memo->u1.value)) + memo->u1.value = i; else { - cmp = rb_funcall(i, id_cmp, 1, *min); + cmp = rb_funcall(i, id_cmp, 1, memo->u1.value); if (NUM2LONG(cmp) < 0) - *min = i; + memo->u1.value = i; } return Qnil; } static VALUE -min_ii(i, min) - VALUE i, *min; +min_ii(i, memo) + VALUE i; + NODE *memo; { VALUE cmp; - if (NIL_P(*min)) - *min = i; + if (NIL_P(memo->u1.value)) + memo->u1.value = i; else { - cmp = rb_yield(rb_assoc_new(i, *min)); + cmp = rb_yield(rb_assoc_new(i, memo->u1.value)); if (NUM2LONG(cmp) < 0) - *min = i; + memo->u1.value = i; } return Qnil; } @@ -224,40 +223,43 @@ static VALUE enum_min(obj) VALUE obj; { - VALUE min = Qnil; + NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0); - rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)&min); - return min; + rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)memo); + rb_gc_force_recycle((VALUE)memo); + return memo->u1.value; } static VALUE -max_i(i, max) - VALUE i, *max; +max_i(i, memo) + VALUE i; + NODE *memo; { VALUE cmp; - if (NIL_P(*max)) - *max = i; + if (NIL_P(memo->u1.value)) + memo->u1.value = i; else { - cmp = rb_funcall(i, id_cmp, 1, *max); + cmp = rb_funcall(i, id_cmp, 1, memo->u1.value); if (NUM2LONG(cmp) > 0) - *max = i; + memo->u1.value = i; } return Qnil; } static VALUE -max_ii(i, max) - VALUE i, *max; +max_ii(i, memo) + VALUE i; + NODE *memo; { VALUE cmp; - if (NIL_P(*max)) - *max = i; + if (NIL_P(memo->u1.value)) + memo->u1.value = i; else { - cmp = rb_yield(rb_assoc_new(i, *max)); + cmp = rb_yield(rb_assoc_new(i, memo->u1.value)); if (NUM2LONG(cmp) > 0) - *max = i; + memo->u1.value = i; } return Qnil; } @@ -266,54 +268,20 @@ static VALUE enum_max(obj) VALUE obj; { - VALUE max = Qnil; + NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0); - rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)&max); - return max; + rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)memo); + rb_gc_force_recycle((VALUE)memo); + return memo->u1.value; } -struct i_v_pair { - int i; - VALUE v; - int found; -}; - static VALUE -index_i(item, iv) +member_i(item, memo) VALUE item; - struct i_v_pair *iv; + NODE *memo; { - if (rb_equal(item, iv->v)) { - iv->found = 1; - rb_iter_break(); - } - else { - iv->i++; - } - return Qnil; -} - -static VALUE -enum_index(obj, val) - VALUE obj, val; -{ - struct i_v_pair iv; - - iv.i = 0; - iv.v = val; - iv.found = 0; - rb_iterate(rb_each, obj, index_i, (VALUE)&iv); - if (iv.found) return INT2FIX(iv.i); - return Qnil; /* not found */ -} - -static VALUE -member_i(item, iv) - VALUE item; - struct i_v_pair *iv; -{ - if (rb_equal(item, iv->v)) { - iv->i = 1; + if (rb_equal(item, memo->u1.value)) { + memo->u2.value = Qtrue; rb_iter_break(); } return Qnil; @@ -323,26 +291,23 @@ static VALUE enum_member(obj, val) VALUE obj, val; { - struct i_v_pair iv; + VALUE result; - iv.i = 0; - iv.v = val; - rb_iterate(rb_each, obj, member_i, (VALUE)&iv); - if (iv.i) return Qtrue; - return Qfalse; + NODE *memo = rb_node_newnode(NODE_MEMO, val, Qfalse, 0); + + rb_iterate(rb_each, obj, member_i, (VALUE)memo); + result = memo->u2.value; + rb_gc_force_recycle((VALUE)memo); + return result; } static VALUE -each_with_index_i(val, indexp) +each_with_index_i(val, memo) VALUE val; - int *indexp; + NODE *memo; { -#if 1 - rb_yield(rb_assoc_new(val, INT2FIX(*indexp))); -#else - rb_yield(rb_ary_concat(rb_Array(val), INT2FIX(*indexp))); -#endif - (*indexp)++; + rb_yield(rb_assoc_new(val, INT2FIX(memo->u3.cnt))); + memo->u3.cnt++; return Qnil; } @@ -350,9 +315,10 @@ static VALUE enum_each_with_index(obj) VALUE obj; { - int index = 0; + NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0); - rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&index); + rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo); + rb_gc_force_recycle((VALUE)memo); return Qnil; } @@ -374,7 +340,6 @@ Init_Enumerable() rb_define_method(rb_mEnumerable,"collect", enum_collect, 0); rb_define_method(rb_mEnumerable,"min", enum_min, 0); rb_define_method(rb_mEnumerable,"max", enum_max, 0); - rb_define_method(rb_mEnumerable,"index", enum_index, 1); rb_define_method(rb_mEnumerable,"member?", enum_member, 1); rb_define_method(rb_mEnumerable,"include?", enum_member, 1); rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0); diff --git a/eval.c b/eval.c index 7eb1cc7598..cbf6d8ceaa 100644 --- a/eval.c +++ b/eval.c @@ -239,6 +239,7 @@ search_method(klass, id, origin) { NODE *body; + if (!klass) return 0; while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) { klass = RCLASS(klass)->super; if (!klass) return 0; @@ -2284,6 +2285,11 @@ rb_eval(self, node) rb_eval(self, node->nd_body)); break; + case NODE_ARGSPUSH: + result = rb_ary_push(rb_eval(self, node->nd_head), + rb_eval(self, node->nd_body)); + break; + case NODE_CALL: { VALUE recv; @@ -3333,10 +3339,13 @@ rb_yield_0(val, self, klass, acheck) !FL_TEST(ruby_dyna_vars, DVAR_DONT_RECYCLE)) { struct RVarmap *vars = ruby_dyna_vars; - do { + while (vars && vars->id != 0) { rb_gc_force_recycle((VALUE)vars); vars = vars->next; - } while (vars && vars->id != 0); + } + if (ruby_dyna_vars->id == 0) { + rb_gc_force_recycle((VALUE)ruby_dyna_vars); + } } POP_VARS(); ruby_block = block; @@ -3379,7 +3388,10 @@ massign(self, node, val, check) if (val) { if (TYPE(val) != T_ARRAY) { - val = rb_Array(val); + if (NIL_P(val)) + val = rb_ary_new2(0); + else + val = rb_ary_new3(1, val); } len = RARRAY(val)->len; for (i=0; list && if)) { + rb_raise(rb_eIOError, "recv for buffered IO"); + } + fd = fileno(fptr->f); + str = rb_str_new(0, NUM2INT(len)); - GetOpenFile(sock, fptr); - fd = fileno(fptr->f); rb_thread_wait_fd(fd); TRAP_BEG; retry: diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index fd0a3bb2e4..931cb90819 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -235,7 +235,7 @@ module TkComm return format("rb_out %s", id); end def uninstall_cmd(id) - id = $1 if /rb_out (c\d+)/ + id = $1 if /rb_out (c\d+)/ =~ id Tk_CMDTBL[id] = nil end private :install_cmd, :uninstall_cmd @@ -347,15 +347,6 @@ module TkComm def _bind_append(what, context, cmd, args=nil) _bind_core('+', what, context, cmd, args) end - private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append - - def bind_all(context, cmd=Proc.new, args=nil) - _bind(['bind', 'all'], context, cmd, args) - end - - def bind_append_all(context, cmd=Proc.new, args=nil) - _bind_append(['bind', 'all'], context, cmd, args) - end def _bindinfo(what, context=nil) if context @@ -372,11 +363,33 @@ module TkComm } end end + private :install_bind, :tk_event_sequence, + :_bind_core, :_bind, :_bind_append, :_bindinfo + + def bind(tagOrClass, context, cmd=Proc.new, args=nil) + _bind(["bind", tagOrClass], context, cmd, args) + end + + def bind_append(tagOrClass, context, cmd=Proc.new, args=nil) + _bind_append(["bind", tagOrClass], context, cmd, args) + end def bindinfo(tagOrClass, context=nil) _bindinfo(['bind', tagOrClass], context) end + def bind_all(context, cmd=Proc.new, args=nil) + _bind(['bind', 'all'], context, cmd, args) + end + + def bind_append_all(context, cmd=Proc.new, args=nil) + _bind_append(['bind', 'all'], context, cmd, args) + end + + def bindinfo_all(context=nil) + _bindinfo(['bind', 'all'], context) + end + def pack(*args) TkPack.configure *args end @@ -401,7 +414,7 @@ module TkCore INTERP = TclTkIp.new - INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {return -code $st $ret} {return $ret}") + INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {if {[regsub -all {!} $args {\\!} newargs] == 0} {return -code $st $ret} {if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $newargs]} ret]] != 0} {return -code $st $ret} {return $ret}}} {return $ret}") def callback_break raise TkCallbackBreak, "Tk callback returns 'break' status" @@ -575,8 +588,8 @@ module Tk module Wm include TkComm def aspect(*args) - w = window(tk_call('wm', 'grid', path, *args)) - w.split.collect{|s|s.to_i} if args.length == 0 + w = tk_call('wm', 'aspect', path, *args) + list(w) if args.length == 0 end def client(name=None) tk_call 'wm', 'client', path, name @@ -594,17 +607,18 @@ module Tk tk_call 'wm', 'focusmodel', path, *args end def frame - tk_call 'wm', 'frame', path + tk_call('wm', 'frame', path) end def geometry(*args) - list(tk_call('wm', 'geometry', path, *args)) + tk_call('wm', 'geometry', path, *args) end def grid(*args) w = tk_call('wm', 'grid', path, *args) list(w) if args.size == 0 end def group(*args) - tk_call 'wm', 'group', path, *args + w = tk_call 'wm', 'group', path, *args + window(w) if args.size == 0 end def iconbitmap(*args) tk_call 'wm', 'iconbitmap', path, *args @@ -628,7 +642,7 @@ module Tk end def maxsize(*args) w = tk_call('wm', 'maxsize', path, *args) - list(w) if not args.size == 0 + list(w) if args.size == 0 end def minsize(*args) w = tk_call('wm', 'minsize', path, *args) @@ -661,7 +675,7 @@ module Tk end end def sizefrom(*args) - list(tk_call('wm', 'sizefrom', path, *args)) + tk_call('wm', 'sizefrom', path, *args) end def state tk_call 'wm', 'state', path @@ -670,7 +684,7 @@ module Tk tk_call 'wm', 'title', path, *args end def transient(*args) - tk_call 'wm', 'transient', path, *args + window(tk_call 'wm', 'transient', path, *args) end def withdraw tk_call 'wm', 'withdraw', path @@ -678,6 +692,46 @@ module Tk end end +module TkBindCore + def bind(context, cmd=Proc.new, args=nil) + Tk.bind(to_eval, context, cmd, args) + end + + def bind_append(context, cmd=Proc.new, args=nil) + Tk.bind_append(to_eval, context, cmd, args) + end + + def bindinfo(context=nil) + Tk.bindinfo(to_eval, context) + end +end + +class TkBindTag + include TkBindCore + + BTagID_TBL = {} + Tk_BINDTAG_ID = ["btag00000"] + + def TkBindTag.id2obj(id) + BTagID_TBL[id]? BTagID_TBL[id]: id + end + + def initialize(*args) + @id = Tk_BINDTAG_ID[0] + Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ + BTagID_TBL[@id] = self + bind(*args) if args != [] + end + + def to_eval + @id + end + + def inspect + format "#", @id + end +end + class TkVariable include Tk extend TkCore @@ -790,7 +844,7 @@ class TkVariable end def inspect - format "", @id + format "#", @id end def ==(other) @@ -1063,19 +1117,19 @@ module TkWinfo include Tk extend Tk def TkWinfo.atom(name) - tk_call 'winfo', name + number(tk_call 'winfo', 'atom', name) end def winfo_atom(name) TkWinfo.atom name end def TkWinfo.atomname(id) - tk_call 'winfo', id + tk_call 'winfo', 'atomname', id end def winfo_atomname(id) TkWinfo.atomname id end def TkWinfo.cells(window) - number(tk_call('winfo', window.path)) + number(tk_call('winfo', 'cells', window.path)) end def winfo_cells TkWinfo.cells self @@ -1093,6 +1147,12 @@ module TkWinfo def winfo_classname TkWinfo.classname self end + def TkWinfo.colormapfull(window) + bool(tk_call('winfo', 'colormapfull', window.path)) + end + def winfo_colormapfull + TkWinfo.colormapfull self + end def TkWinfo.containing(rootX, rootY) path = tk_call('winfo', 'containing', rootX, rootY) window(path) @@ -1119,7 +1179,7 @@ module TkWinfo TkWinfo.fpixels self, number end def TkWinfo.geometry(window) - list(tk_call('winfo', 'geometry', window.path)) + tk_call('winfo', 'geometry', window.path) end def winfo_geometry TkWinfo.geometry self @@ -1131,15 +1191,15 @@ module TkWinfo TkWinfo.height self end def TkWinfo.id(window) - number(tk_call('winfo', 'id', window.path)) + tk_call('winfo', 'id', window.path) end def winfo_id TkWinfo.id self end def TkWinfo.interps(window=nil) if window - tk_split_simplelist(tk_call('winfo', '-displayof', window.path, - 'interps')) + tk_split_simplelist(tk_call('winfo', 'interps', + '-displayof', window.path)) else tk_split_simplelist(tk_call('winfo', 'interps')) end @@ -1153,8 +1213,14 @@ module TkWinfo def winfo_mapped? TkWinfo.mapped? self end + def TkWinfo.manager(window) + tk_call('winfo', 'manager', window.path) + end + def winfo_manager + TkWinfo.manager self + end def TkWinfo.appname(window) - bool(tk_call('winfo', 'name', window.path)) + tk_call('winfo', 'name', window.path) end def winfo_appname TkWinfo.appname self @@ -1255,6 +1321,12 @@ module TkWinfo def winfo_screenwidth TkWinfo.screenwidth self end + def TkWinfo.server(window) + tk_call 'winfo', 'server', window.path + end + def winfo_server + TkWinfo.server self + end def TkWinfo.toplevel(window) window(tk_call('winfo', 'toplevel', window.path)) end @@ -1267,7 +1339,24 @@ module TkWinfo def winfo_visual TkWinfo.visual self end - def TkWinfo.vrootheigh(window) + def TkWinfo.visualid(window) + tk_call 'winfo', 'visualid', window.path + end + def winfo_visualid + TkWinfo.visualid self + end + def TkWinfo.visualsavailable(window, includeids=false) + if includeids + v = tk_call('winfo', 'visualsavailable', window.path, "includeids") + else + v = tk_call('winfo', 'visualsavailable', window.path) + end + list(v) + end + def winfo_visualsavailable(includeids=false) + TkWinfo.visualsavailable self, includeids + end + def TkWinfo.vrootheight(window) number(tk_call('winfo', 'vrootheight', window.path)) end def winfo_vrootheight @@ -1540,6 +1629,7 @@ end class TkObject buf && *(p - 1) == '/') p--; } - else if (isdirsep(*s)) { + else { while (*s && isdirsep(*s)) { *p++ = '/'; s++; @@ -1267,7 +1267,8 @@ rb_file_s_expand_path(argc, argv) } else { *++p = '.'; - *++p = '.'; + do *++p = '.'; while (*++s == '.'); + --s; } break; case '/': diff --git a/io.c b/io.c index 9bc1c6014f..6222d9047e 100644 --- a/io.c +++ b/io.c @@ -160,13 +160,11 @@ rb_io_check_writable(fptr) } } -void -rb_read_check(fp) +int +rb_read_pending(fp) FILE *fp; { - if (!READ_DATA_PENDING(fp)) { - rb_thread_wait_fd(fileno(fp)); - } + return READ_DATA_PENDING(fp); } /* writing functions */ @@ -1076,6 +1074,9 @@ rb_io_sysread(io, len) GetOpenFile(io, fptr); rb_io_check_readable(fptr); + if (READ_DATA_PENDING(fptr->f)) { + rb_raise(rb_eIOError, "sysread for buffered IO"); + } str = rb_str_new(0, ilen); rb_thread_wait_fd(fileno(fptr->f)); diff --git a/lib/complex.rb b/lib/complex.rb index 0af8c20b89..56dd040ac1 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -20,7 +20,7 @@ # Complex::/ # Complex::** # Complex::% -# Complex::divmod +# Complex::divmod -- obsolete # Complex::abs # Complex::abs2 # Complex::arg @@ -51,6 +51,12 @@ def Complex(a, b = 0) if a.kind_of?(Complex) and b == 0 a + elsif b.kind_of?(Complex) + if a.kind_of?(Complex) + Complex(a.real-b.image, a.image + b.real) + else + Complex(a-b.image, b.real) + end elsif b == 0 and defined? Complex::Unify a else @@ -181,18 +187,18 @@ class Complex < Numeric end end - def divmod(other) - if other.kind_of?(Complex) - rdiv, rmod = @real.divmod(other.real) - idiv, imod = @image.divmod(other.image) - return Complex(rdiv, idiv), Complex(rmod, rdiv) - elsif Complex.generic?(other) - Complex(@real.divmod(other), @image.divmod(other)) - else - x , y = other.coerce(self) - x.divmod(y) - end - end +# def divmod(other) +# if other.kind_of?(Complex) +# rdiv, rmod = @real.divmod(other.real) +# idiv, imod = @image.divmod(other.image) +# return Complex(rdiv, idiv), Complex(rmod, rmod) +# elsif Complex.generic?(other) +# Complex(@real.divmod(other), @image.divmod(other)) +# else +# x , y = other.coerce(self) +# x.divmod(y) +# end +# end def abs Math.sqrt!((@real*@real + @image*@image).to_f) diff --git a/lib/parsedate.rb b/lib/parsedate.rb index 29b3fa43b9..7bf1affb42 100644 --- a/lib/parsedate.rb +++ b/lib/parsedate.rb @@ -27,7 +27,7 @@ module ParseDate if date.sub!(/(#{DAYPAT})[a-z]*,?/i, ' ') wday = DAYS[$1.downcase] end - if date.sub!(/(\d+):(\d+)(?::(\d+))?(?:\s*(am|pm))?(?:\s+([a-z]{1,4}(?:\s+[a-z]{1,4})?|[-+]\d{4}))?/i, ' ') + if date.sub!(/(\d+):(\d+)(?::(\d+))?(?:\s*(am|pm))?(?:\s+([a-z]{1,4}(?:\s+[a-z]{1,4}|[-+]\d{4})?))?/i, ' ') hour = $1.to_i min = $2.to_i if $3 diff --git a/lib/timeout.rb b/lib/timeout.rb index 75340d52dd..b6bda6cece 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -25,8 +25,6 @@ class TimeoutErroriv_tbl); + w_ivar(ROBJECT(obj)->iv_tbl, &c_arg); } break; diff --git a/missing/isnan.c b/missing/isnan.c index 96bb93ba6a..3c56765807 100644 --- a/missing/isnan.c +++ b/missing/isnan.c @@ -1,3 +1,15 @@ +#ifdef _MSC_VER + +#include +int +isnan(n) + double n; +{ + return _isnan(n); +} + +#else + static int double_ne(); int @@ -14,3 +26,4 @@ double_ne(n1, n2) { return n1 != n2; } +#endif diff --git a/node.h b/node.h index 6c98d79a9b..46e9b1525a 100644 --- a/node.h +++ b/node.h @@ -84,6 +84,7 @@ enum node_type { NODE_DREGX_ONCE, NODE_ARGS, NODE_ARGSCAT, + NODE_ARGSPUSH, NODE_RESTARGS, NODE_BLOCK_ARG, NODE_BLOCK_PASS, @@ -114,6 +115,7 @@ enum node_type { #ifdef C_ALLOCA NODE_ALLOCA, #endif + NODE_MEMO, }; typedef struct RNode { @@ -290,6 +292,7 @@ typedef struct RNode { #define NEW_ZSUPER() rb_node_newnode(NODE_ZSUPER,0,0,0) #define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f) #define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0) +#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_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) diff --git a/parse.y b/parse.y index 725d616206..f15684fb99 100644 --- a/parse.y +++ b/parse.y @@ -3007,11 +3007,8 @@ yylex() case ':': c = nextc(); if (c == ':') { - if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { - lex_state = EXPR_BEG; - return tCOLON3; - } - if (lex_state == EXPR_ARG && space_seen) { + if (lex_state == EXPR_BEG || lex_state == EXPR_MID || + (lex_state == EXPR_ARG && space_seen)) { lex_state = EXPR_BEG; return tCOLON3; } @@ -3284,7 +3281,7 @@ yylex() tokfix(); { - int result; + int result = 0; switch (tok()[0]) { case '$': @@ -3312,22 +3309,25 @@ yylex() } } - if (ISUPPER(tok()[0])) { - result = tCONSTANT; - } - else if (toklast() == '!' || toklast() == '?') { + if (toklast() == '!' || toklast() == '?') { result = tFID; } else { - result = tIDENTIFIER; if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) { if ((c = nextc()) == '=' && !peek('=')) { + result = tIDENTIFIER; tokadd(c); } else { pushback(c); } } + if (result == 0 && ISUPPER(tok()[0])) { + result = tCONSTANT; + } + else { + result = tIDENTIFIER; + } } if (lex_state == EXPR_BEG || lex_state == EXPR_DOT || @@ -3841,6 +3841,7 @@ arg_concat(node1, node2) NODE *node1; NODE *node2; { + if (!node2) return node1; return NEW_ARGSCAT(node1, node2); } @@ -3854,7 +3855,7 @@ arg_add(node1, node2) return list_append(node1, node2); } else { - return NEW_ARGSCAT(node1, node2); + return NEW_ARGSPUSH(node1, node2); } } diff --git a/random.c b/random.c index e8c9d1cb28..99f4c59bf2 100644 --- a/random.c +++ b/random.c @@ -76,8 +76,8 @@ void srand48 _((long)); #endif /* not HAVE_DRAND48 */ -#ifdef HAVE_RANDOM static int first = 1; +#if !defined HAVE_DRAND48 && defined HAVE_RANDOM static char state[256]; #endif @@ -88,15 +88,15 @@ rand_init(seed) int old; static unsigned int saved_seed; -#ifdef HAVE_RANDOM +#if !defined HAVE_DRAND48 && defined HAVE_RANDOM if (first == 1) { initstate(1, state, sizeof state); - first = 0; } else { setstate(state); } #endif + first = 0; SRANDOM(seed); old = saved_seed; @@ -135,8 +135,6 @@ rb_f_rand(obj, vmax) { long val, max; - static initialized = 0; - if (first) { struct timeval tv; diff --git a/rubyio.h b/rubyio.h index 145b420696..014ca4acd7 100644 --- a/rubyio.h +++ b/rubyio.h @@ -58,6 +58,5 @@ void rb_io_synchronized _((OpenFile*)); void rb_io_check_closed _((OpenFile*)); void rb_eof_error _((void)); -void rb_read_check _((FILE*)); /* thread aware check */ - +int rb_read_pending _((FILE*)); #endif diff --git a/string.c b/string.c index e1f213496a..635bbcf18f 100644 --- a/string.c +++ b/string.c @@ -863,7 +863,7 @@ rb_str_replace(str, beg, len, val) if (RSTRING(str)->len < beg && len < 0) { MEMZERO(RSTRING(str)->ptr + RSTRING(str)->len, char, -len); } - memcpy(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len); + memmove(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len); RSTRING(str)->len += RSTRING(val)->len - len; RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; } @@ -2193,32 +2193,6 @@ rb_str_each_line(argc, argv, str) return str; } -#ifdef STR_TO_A_USE_EACH -static VALUE -to_a_push(str, ary) - VALUE str, ary; -{ - return rb_ary_push(ary, str); -} -#endif - -static VALUE -rb_str_to_a(str) - VALUE str; -{ -#ifdef STR_TO_A_USE_EACH - VALUE ary; - - if (RSTRING(str)->len == 0) return rb_ary_new3(1, str); - ary = rb_ary_new(); - rb_iterate(rb_each, str, to_a_push, ary); - - return ary; -#else - return rb_ary_new3(1, str); -#endif -} - static VALUE rb_str_each_byte(str) VALUE str; @@ -2652,7 +2626,6 @@ Init_String() rb_define_method(rb_cString, "to_i", rb_str_to_i, 0); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); - rb_define_method(rb_cString, "to_a", rb_str_to_a, 0); rb_define_method(rb_cString, "to_s", rb_str_to_s, 0); rb_define_method(rb_cString, "to_str", rb_str_to_s, 0); rb_define_method(rb_cString, "inspect", rb_str_inspect, 0); diff --git a/version.h b/version.h index 38a712eb28..5ccc8370b3 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ -#define RUBY_VERSION "1.5.0" -#define RUBY_RELEASE_DATE "2000-01-08" -#define RUBY_VERSION_CODE 150 -#define RUBY_RELEASE_CODE 20000108 +#define RUBY_VERSION "1.5.2" +#define RUBY_RELEASE_DATE "2000-01-17" +#define RUBY_VERSION_CODE 152 +#define RUBY_RELEASE_CODE 20000117