ruby-changes:55481
From: git <ko1@a...>
Date: Tue, 23 Apr 2019 11:54:51 +0900 (JST)
Subject: [ruby-changes:55481] git:63bdeecf80 (ruby_1_9_3): * 2019-04-23
git 2019-04-23 10:37:40 +0900 (Tue, 23 Apr 2019) New Revision: 63bdeecf80 https://git.ruby-lang.org/ruby.git/commit/?id=63bdeecf80 Log: * 2019-04-23 Modified files: version.h Index: v1_1r/lib/parsedate.rb =================================================================== --- v1_1r/lib/parsedate.rb (revision 62) +++ v1_1r/lib/parsedate.rb (revision 63) @@ -4,39 +4,66 @@ module ParseDate https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/parsedate.rb#L4 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 } MONTHPAT = MONTHS.keys.join('|') - DAYPAT = 'mon|tue|wed|thu|fri|sat|sun' + DAYS = { + 'sun' => 0, 'mon' => 1, 'tue' => 2, 'wed' => 3, + 'thu' => 4, 'fri' => 5, 'sat' => 6 } + DAYPAT = DAYS.keys.join('|') def parsedate(date) - if date.sub!(/(#{DAYPAT})/i, ' ') - dayofweek = $1 + # ISO 8601? + if date =~ /(\d\d\d\d)-?(?:(\d\d)-?(\d\d)?)? *(?:(\d\d):(\d\d)(?::(\d\d))?)?/ + return $1.to_i, + if $2 then $2.to_i else 1 end, + if $3 then $3.to_i else 1 end, + nil, + if $4 then $4.to_i end, + if $5 then $5.to_i end, + if $6 then $6.to_i end, + nil + end + date = date.dup + if date.sub!(/(#{DAYPAT})[a-z]*,?/i, ' ') + wday = DAYS[$1.downcase] + end + if date.sub!(/(\d+):(\d+)(?::(\d+))?\s*(am|pm)?\s*(?:\s+([a-z]{1,4}(?:\s+[a-z]{1,4})|[-+]\d{4}))?/i, ' ') + hour = $1.to_i + min = $2.to_i + if $3 + sec = $3.to_i + end + if $4 == 'pm' + hour += 12 + end + if $5 + zone = $5 + end + end + if date.sub!(/(\d+)\S*\s+(#{MONTHPAT})\S*(?:\s+(\d+))?/i, ' ') + mday = $1.to_i + mon = MONTHS[$2.downcase] + if $3 + year = $3.to_i + end + elsif date.sub!(/(#{MONTHPAT})\S*\s+(\d+)\S*\s*,?(?:\s+(\d+))?/i, ' ') + mon = MONTHS[$1.downcase] + mday = $2.to_i + if $3 + year = $3.to_i + end + elsif date.sub!(/(\d+)\/(\d+)(?:\/(\d+))/, ' ') + mon = $1.to_i + mday = $2.to_i + if $3 + year = $3.to_i + end end - if date.sub!(/\s+(\d+:\d+(:\d+)?)/, ' ') - time = $1 - end - if date =~ /(19|20)(\d\d)/ - year = Integer($2) - end - if date.sub!(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/i, ' ') - dayofmonth = $1.to_i - monthname = $2 - elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/i, ' ') - monthname = $1 - dayofmonth = $2.to_i - elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/i, ' ') - monthname = $1 - dayofmonth = $2.to_i - elsif date.sub!(/\s*(\d\d?)\/(\d\d?)/, ' ') - month = $1 - dayofmonth = $2.to_i - end - if monthname - month = MONTHS[monthname.downcase] - end - if ! year && date =~ /\d\d/ - year = Integer($&) - end - return year, month, dayofmonth + return year, mon, mday, wday, hour, min, sec, zone end module_function :parsedate end + +if __FILE__ == $0 + p Time.now.asctime + p ParseDate.parsedate(Time.now.asctime) +end Index: v1_1r/lib/date.rb =================================================================== --- v1_1r/lib/date.rb (revision 62) +++ v1_1r/lib/date.rb (revision 63) @@ -1,8 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/date.rb#L1 # # Date.rb - # $Release Version: $ -# $Revision: 1.1.1.1.4.1 $ -# $Date: 1998/01/16 12:36:04 $ +# $Revision: 1.1.1.1.4.2 $ +# $Date: 1998/02/02 04:49:13 $ # by Yasuo OHBA(SHL Japan Inc. Technology Dept.) # # -- @@ -32,10 +32,16 @@ class Date https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/date.rb#L32 } def initialize(y = 1, m = 1, d = 1) - if y.kind_of?(String) && y.size == 8 - @year = y[0,4].to_i - @month = y[4,2].to_i - @day = y[6,2].to_i + if y.kind_of?(String) + case y + when /(\d\d\d\d)-?(?:(\d\d)-?(\d\d)?)?/ + @year = $1.to_i + @month = if $2 then $2.to_i else 1 end + @day = if $3 then $3.to_i else 1 end + else + require 'parsedate' + @year, @month, @day = ParseDate.parsedate(y) + end else if m.kind_of?(String) m = Monthtab[m.downcase] @@ -66,18 +72,25 @@ class Date https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/date.rb#L72 def period return Date.period!(@year, @month, @day) end - + + def jd + return period + 1721423 + end + + def mjd + return jd - 2400000.5 + end + + def to_s + format("%.3s, %.3s %2d %4d", name_of_week, name_of_month, @day, @year) + end + + def inspect + to_s + end + def day_of_week - dl = Date.daylist(@year) - d = Date.jan1!(@year) - for m in 1..(@month - 1) - d += dl[m] - end - d += @day - 1 - if @year == 1752 && @month == 9 && @day >= 14 - d -= (14 - 3) - end - return (d % 7) + return (period + 5) % 7 end def name_of_week @@ -141,6 +154,9 @@ class Date https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/date.rb#L154 end def _check_date + if @year == nil or @month == nil or @day == nil + raise ArgumentError, "argument contains nil" + end m = Date.daylist(@year) if @month < 1 || @month > 12 raise ArgumentError, "argument(month) out of range." Index: v1_1r/lib/tracer.rb =================================================================== --- v1_1r/lib/tracer.rb (revision 62) +++ v1_1r/lib/tracer.rb (revision 63) @@ -1,7 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/tracer.rb#L1 +#!/usr/local/bin/ruby +# +# tracer.rb - +# $Release Version: 0.2$ +# $Revision: 1.6 $ +# $Date: 1998/02/02 08:12:02 $ +# by Keiju ISHITSUKA(Nippon Rational Inc.) +# +# -- +# +# +# + +# +# tracer main class +# class Tracer - MY_FILE_NAME_PATTERN = /^tracer\.(rb)?/ - Threads = Hash.new - Sources = Hash.new + RCS_ID='-$Id: tracer.rb,v 1.6 1998/02/02 08:12:02 keiju Exp keiju $-' + + MY_FILE_NAME = caller(0)[0].scan(/^(.*):[0-9]+$/)[0] EVENT_SYMBOL = { "line" => "-", @@ -10,11 +26,31 @@ class Tracer https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/tracer.rb#L26 "class" => "C", "end" => "E"} + def initialize + @threads = Hash.new + if defined? Thread.main + @threads[Thread.main.id] = 0 + else + @threads[Thread.current.id] = 0 + end + + @sources = Hash.new + end + def on - set_trace_func proc{|event, file, line, id, binding| - trace_func event, file, line, id, binding - } - print "Trace on\n" + if iterator? + on + begin + yield + ensure + off + end + else + set_trace_func proc{|event, file, line, id, binding| + trace_func event, file, line, id, binding + } + print "Trace on\n" + end end def off @@ -22,27 +58,38 @@ class Tracer https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/tracer.rb#L58 print "Trace off\n" end - def get_thread_no - unless no = Threads[Thread.current.id] - Threads[Thread.current.id] = no = Threads.size + def get_line(file, line) + unless list = @sources[file] +# print file if $DEBUG + begin + f = open(file) + begin + @sources[file] = list = f.readlines + ensure + f.close + end + rescue + @sources[file] = list = [] + end + end + if l = list[line - 1] + l + else + "-\n" end - no end - def get_line(file, line) - unless list = Sources[file] - f =open(file) - begin - Sources[file] = list = f.readlines - ensure - f.close - end + def get_thread_no + if no = @threads[Thread.current.id] + no + else + @threads[Thread.current.id] = @threads.size end - list[line - 1] end def trace_func(event, file, line, id, binding) - return if File.basename(file) =~ MY_FILE_NAME_PATTERN + return if file == MY_FILE_NAME + #printf "Th: %s\n", Thread.current.inspect Thread.critical = TRUE printf("#%d:%s:%d:%s: %s", @@ -65,11 +112,15 @@ class Tracer https://github.com/ruby/ruby/blob/trunk/v1_1r/lib/tracer.rb#L112 end -if File.basename($0) =~ Tracer::MY_FILE_NAME_PATTERN - $0 = ARGV.shift - - Tracer.on - load $0 -else - Tracer.on +if caller(0).size == 1 + if $0 == Tracer::MY_FILE_NAME + # direct call + + $0 = ARGV[0] + ARGV.shift + Tracer.on + require $0 + else + Tracer.on + end end Index: v1_1r/numeric.c =================================================================== --- v1_1r/numeric.c (revision 62) +++ v1_1r/numeric.c (revision 63) @@ -824,7 +824,7 @@ fix_rshift(x, y) https://github.com/ruby/ruby/blob/trunk/v1_1r/numeric.c#L824 long i, val; i = NUM2INT(y); - if (y < 32) { + if (i < sizeof(INT) * 8) { val = RSHIFT(FIX2INT(x), i); return INT2FIX(val); } Index: v1_1r/intern.h =================================================================== --- v1_1r/intern.h (revision 62) +++ v1_1r/intern.h (revision 63) @@ -216,12 +216,13 @@ VALUE reg_match _((VALUE, VALUE)); https://github.com/ruby/ruby/blob/trunk/v1_1r/intern.h#L216 VALUE reg_match2 _((VALUE)); void rb_set_kcode _((char *)); /* ruby.c */ -void rb_require_modules _((void)); void rb_load_file _((char *)); void ruby_script _((char *)); void ruby_prog_init _((void)); void ruby_set_argv _((int, char **)); void ruby_process_options _((int, char **)); +void ruby_require_modules _((void)); +void ruby_load_script _((void)); /* signal.c */ VALUE f_kill _((int, VALUE *)); void gc_mark_trap_list _((void)); Index: v1_1r/ChangeLog =================================================================== --- v1_1r/ChangeLog (revision 62) +++ v1_1r/ChangeLog (revision 63) @@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/v1_1r/ChangeLog#L1 +Tue Feb 3 12:24:07 1998 Yukihiro Matsumoto <matz@n...> + + * re.c (match_to_a): non matching element should be nil. + + * ruby.c (ruby_load_script): load script after all initialization. + + * bignum.c (str2inum): need to interpret prefix `0' of `0x'. + +Tue Feb 3 10:00:18 1998 WATANABE Hirofumi <watanabe@a...> + + * numeric.c (fix_rshift): use `sizeof(INT)*8' instead of 32. + +Mon Feb 2 14:09:24 1998 Yukihiro Matsumoto <matz@n...> + + * ruby.c (set_arg0): grab environment region too. + Thu Jan 29 18:36:25 1998 WATANABE Hirofumi <watanabe@a...> * process.c (rb_proc_exec): check `sh' to be exist. Index: v1_1r/ruby.c =================================================================== --- v1_1r/ruby.c (revision 62) +++ v1_1r/ruby.c (revision 63) @@ -56,12 +56,25 @@ static void forbid_setid _((char *)); https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L56 static VALUE do_loop = FALSE, do_print = FALSE; static VALUE do_check = FALSE, do_line = FALSE; static VALUE do_split = FALSE; - +static int do_search = FALSE; static char *script; +static char *e_body; static int origargc; static char **origargv; +#if defined(NeXT) && defined(__DYNAMIC__) + +#include <mach-o/dyld.h> +extern char *** environ_pointer; +#define environ (*environ_pointer) +#else +#ifndef NT +extern char **environ; +#endif +#endif +static char **origenviron; + extern int sourceline; extern char *sourcefile; @@ -124,7 +137,7 @@ add_modules(mod) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L137 } void -rb_require_modules() +ruby_require_modules() { struct req_list *list = req_list; struct req_list *tmp; @@ -145,7 +158,7 @@ proc_options(argcp, argvp) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L158 { int argc = *argcp; char **argv = *argvp; - int script_given, do_search; + int script_given; char *s; if (argc == 0) return; @@ -219,11 +232,11 @@ proc_options(argcp, argvp) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L232 script_given++; if (script == 0) script = "-e"; if (argv[1]) { - compile_string("-e", argv[1], strlen(argv[1])); + e_body = argv[1]; argc--,argv++; } else { - compile_string("-e", "", 0); + e_body = ""; } break; @@ -365,35 +378,20 @@ proc_options(argcp, argvp) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L378 if (argc == 0) { /* no more args */ if (verbose == 3) exit(0); script = "-"; - load_stdin(); } else { script = argv[0]; if (script[0] == '\0') { script = "-"; - load_stdin(); } else { - if (do_search) { - char *path = getenv("RUBYPATH"); - - script = 0; - if (path) { - script = dln_find_file(argv[0], path); - } - if (!script) { - script = dln_find_file(argv[0], getenv("PATH")); - } - if (!script) script = argv[0]; - } - load_file(script, 1); + script = argv[0]; } argc--; argv++; } } if (verbose) verbose = TRUE; - xflag = FALSE; *argvp = argv; *argcp = argc; @@ -420,6 +418,41 @@ proc_options(argcp, argvp) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L418 } +void +ruby_load_script() +{ + if (script[0] == '-') { + if (script[1] == '\0') { + load_stdin(); + } + else if (script[1] == 'e') { + compile_string("-e", e_body, strlen(e_body)); + } + } + else { + if (do_search) { + char *path = getenv("RUBYPATH"); + char *s = 0; + + if (path) { + s = dln_find_file(script, path); + } + if (!s) { + s = dln_find_file(script, getenv("PATH")); + } + if (s) script = s; + } + load_file(script, 1); + } + xflag = FALSE; + if (do_print) { + yyappend_print(); + } + if (do_loop) { + yywhile_loop(do_line, do_split); + } +} + static void load_file(fname, script) char *fname; @@ -514,6 +547,9 @@ load_file(fname, script) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L547 RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0'; argc = 2; argv[0] = 0; argv[1] = p + 5; proc_options(&argc, &argvp); +#if 0 + proc_sflag(&argc, &argvp); +#endif } } } @@ -553,7 +589,7 @@ set_arg0(val, id) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L589 int i; static int len; - if (origargv == 0) Fail("$0 not initialized"); + if (origargv == 0) ArgError("$0 not initialized"); Check_Type(val, T_STRING); if (len == 0) { s = origargv[0]; @@ -563,6 +599,14 @@ set_arg0(val, id) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L599 if (origargv[i] == s + 1) s += strlen(++s); /* this one is ok too */ } + /* can grab env area too? */ + if (origenviron && origenviron[0] == s + 1) { + setenv("NoNe SuCh", "Ruby Compiler :-)", 1); + /* force copy of environment */ + for (i = 0; origenviron[i]; i++) + if (origenviron[i] == s + 1) + s += strlen(++s); + } len = s - origargv[0]; } s = RSTRING(val)->ptr; @@ -729,6 +773,11 @@ ruby_process_options(argc, argv) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L773 int i; origargc = argc; origargv = argv; +#if defined(NeXT) && defined(__DYNAMIC__) + _dyld_lookup_and_bind("__environ", (unsigned long*)&environ_pointer, NULL); +#endif /* environ */ + origenviron = environ; + ruby_script(argv[0]); /* for the time being */ rb_argv0 = str_taint(str_new2(argv[0])); #if defined(USE_DLN_A_OUT) @@ -742,10 +791,4 @@ ruby_process_options(argc, argv) https://github.com/ruby/ruby/blob/trunk/v1_1r/ruby.c#L791 printf("Syntax OK\n"); exit(0); } - if (do_print) { - yyappend_print(); - } - if (do_loop) { - yywhile_loop(do_line, do_split); - } } Index: v1_1r/re.c =================================================================== --- v1_1r/re.c (revision 62) +++ v1_1r/re.c (revision 63) @@ -570,7 +570,7 @@ match_to_a(match) https://github.com/ruby/ruby/blob/trunk/v1_1r/re.c#L570 int i; for (i=0; i<regs->num_regs; i++) { - if (regs->beg[0] == -1) ary_push(ary, Qnil); + if (regs->beg[i] == -1) ary_push(ary, Qnil); else ary_push(ary, str_new(ptr+regs->beg[i], regs->end[i]-regs->beg[i])); } Index: v1_1r/eval.c =================================================================== --- v1_1r/eval.c (revision 62) +++ v1_1r/eval.c (revision 63) @@ -733,15 +733,13 @@ ruby_options(argc, argv) https://github.com/ruby/ruby/blob/trunk/v1_1r/eval.c#L733 PUSH_TAG(PROT_NONE) if ((state = EXEC_TAG()) == 0) { - NODE *save; ruby_process_options(argc, argv); - save = eval_tree; - eval_tree = 0; Init_ext(); ext_init = 1; - rb_require_modules(); - eval_tree = save; + ruby_require_modules(); + eval_tree = 0; + ruby_load_script(); } POP_TAG(); if (state) { Index: v1_1r/object.c =================================================================== --- v1_1r/object.c (revision 62) +++ v1_1r/object.c (revision 63) @@ -100,8 +100,8 @@ obj_clone(obj) https://github.com/ruby/ruby/blob/trunk/v1_1r/object.c#L100 CLONESETUP(clone,obj); if (ROBJECT(obj)->iv_tbl) { ROBJECT(clone)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl); - RBASIC(clone)->class = singleton_class_clone(RBASIC(obj)->class); - RBASIC(clone)->flags = RBASIC(obj)->flags; + RBASIC(clone)->class = singleton_class_clone(RBASIC(obj)->class); + RBASIC(clone)->flags = RBASIC(obj)->flags; } return clone; Index: v1_1r/bignum.c =================================================================== --- v1_1r/bignum.c (revision 62) +++ v1_1r/bignum.c (revision 63) @@ -195,12 +195,16 @@ str2inum(str, base) https://github.com/ruby/ruby/blob/trunk/v1_1r/bignum.c#L195 base = 10; } } - len = strlen(str); if (base == 8) { - len = 3*len*sizeof(char); + while (str[0] == '0') str++; + len = 3*strlen(str)*sizeof(char); } else { /* base == 10 or 16 */ - len = 4*len*sizeof(char); + if (base == 16 && str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) { + str += 2; + } + while (str[0] == '0') str++; + len = 4*strlen(str)*sizeof(char); } if (len <= (sizeof(VALUE)*CHAR_BIT)) { Index: v1_1r/time.c =================================================================== --- v1_1r/time.c (revision 62) +++ v1_1r/time.c (revision 63) @@ -421,6 +421,23 @@ time_asctime(time) https://github.com/ruby/ruby/blob/trunk/v1_1r/time.c#L421 if (tobj->tm_got == 0) { time_localtime(time); } + len = strftime(buf, 64, "%c", &(tobj->tm)); + + return str_new(buf, len); +} + +static VALUE +time_to_s(time) + VALUE time; +{ + struct time_object *tobj; + char buf[64]; + int len; + + GetTimeval(time, tobj); + if (tobj->tm_got == 0) { + time_localtime(time); + } #ifndef HAVE_TM_ZONE if (tobj->gmt == 1) { len = strftime(buf, 64, "%a %b %d %H:%M:%S GMT %Y", &(tobj->tm)); @@ -774,8 +791,8 @@ Init_Time() https://github.com/ruby/ruby/blob/trunk/v1_1r/time.c#L791 rb_define_method(cTime, "gmtime", time_gmtime, 0); rb_define_method(cTime, "ctime", time_asctime, 0); rb_define_method(cTime, "asctime", time_asctime, 0); - rb_define_method(cTime, "to_s", time_asctime, 0); - rb_define_method(cTime, "inspect", time_asctime, 0); + rb_define_method(cTime, "to_s", time_to_s, 0); + rb_define_method(cTime, "inspect", time_to_s, 0); rb_define_method(cTime, "to_a", time_to_a, 0); rb_define_method(cTime, "+", time_plus, 1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/