From 548b5143db2c3d701520671ef1413cf3c39fcedf Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 12 Jun 2000 07:48:31 +0000 Subject: 2000-06-12 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 34 +++++++- ToDo | 2 + configure.in | 10 ++- dir.c | 5 +- ext/extmk.rb.in | 4 +- ext/tk/lib/tk.rb | 205 +++++++++++++++++++++++++++++++++++++++++++++++-- ext/tk/lib/tkcanvas.rb | 107 ++++++++++++++++++++++---- ext/tk/lib/tkentry.rb | 8 ++ ext/tk/lib/tkfont.rb | 14 ++-- file.c | 7 +- io.c | 26 ++++--- lib/jcode.rb | 16 ++-- lib/mkmf.rb | 4 +- misc/ruby-mode.el | 4 +- numeric.c | 38 +++++++++ re.c | 2 +- rubytest.rb | 7 ++ time.c | 89 ++++++++++++++++----- version.h | 4 +- 19 files changed, 494 insertions(+), 92 deletions(-) diff --git a/ChangeLog b/ChangeLog index fdc7bfd67d..3209353025 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,39 @@ +Sat Jun 10 23:10:32 2000 Yukihiro Matsumoto + + * io.c (rb_io_seek): whence is optional, default is SEEK_SET. + +Fri Jun 9 15:11:35 2000 Yukihiro Matsumoto + + * time.c (make_time_t): supports daylight saving time. + + * eval.c (rb_thread_safe_level): should retrive current $SAFE + value if a thread is the current thread. + +Thu Jun 8 14:25:45 2000 Hiroshi Igarashi + + * lib/mkmf.rb: add target `distclean' in Makefile for extlib. + target `clean' doesn't remove Makefile. + +Thu Jun 8 13:34:03 2000 Dave Thomas + + * numeric.c: add nan?, infinite?, and finite? to Float + Thu Jun 8 00:31:04 2000 WATANABE Hirofumi * regex.h: export re_mbctab properly on cygwin. * dln.c: use dlopen instead of LoadLibrary on cygwin. +Thu Jun 8 13:41:34 2000 Tadayoshi Funaba + + * file.c (rb_file_s_basename): might dump core. + +Tue Jun 6 03:29:12 2000 Yukihiro Matsumoto + + * dir.c (dir_foreach): now returns nil for consistency. + + * bignum.c (bigdivmod): modulo by small numbers was wrong. + Mon Jun 5 00:18:08 2000 WATANABE Hirofumi * bignum.c: avoid conflict with USHORT on mingw32. @@ -589,10 +619,6 @@ Sat Apr 1 00:16:05 2000 Yukihiro Matsumoto * object.c (sym_inspect): inspect gives ":sym", to_s gives "sym". -Fri Mar 31 08:56:55 2000 Yukihiro Matsumoto - - * parse.y (yylex): - Thu Mar 30 12:19:44 2000 Katsuyuki Komatsu * enum.c (enum_find): rb_eval_cmd() should be called with array. diff --git a/ToDo b/ToDo index 1e65903b6e..a85e6b8c50 100644 --- a/ToDo +++ b/ToDo @@ -25,6 +25,8 @@ Language Spec. * discourage use of Perlish features by giving warnings. * `exception' method to be alternative for `$!'. ?? * non confusing in-block local variable (is it possible?) + + remove scope by block + + variables appears within block may have independent values. Hacking Interpreter diff --git a/configure.in b/configure.in index 71aaa29ed4..242ce7f172 100644 --- a/configure.in +++ b/configure.in @@ -209,9 +209,13 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\ getpgrp setpgrp getpgid setpgid getgroups getpriority\ dlopen sigprocmask sigaction _setjmp setsid getrlimit) AC_STRUCT_TIMEZONE -if test "$ac_cv_func_strftime" = no; then - AC_TRY_LINK([], - [extern int daylight; int i = daylight;], AC_DEFINE(HAVE_DAYLIGHT)) +AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight, + [AC_TRY_LINK([], + [extern int daylight; int i = daylight;], + rb_cv_have_daylight=yes, + rb_cv_have_daylight=no)]) +if test "$rb_cv_have_daylight" = yes; then + AC_DEFINE(HAVE_DAYLIGHT) fi if test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes; then diff --git a/dir.c b/dir.c index 6792ab6390..a3006f5d0f 100644 --- a/dir.c +++ b/dir.c @@ -783,7 +783,8 @@ dir_foreach(io, dirname) VALUE dir; dir = rb_funcall(rb_cDir, rb_intern("open"), 1, dirname); - return rb_ensure(dir_each, dir, dir_close, dir); + rb_ensure(dir_each, dir, dir_close, dir); + return Qnil; } static VALUE @@ -814,6 +815,8 @@ Init_Dir() rb_define_method(rb_cDir,"rewind", dir_rewind, 0); rb_define_method(rb_cDir,"tell", dir_tell, 0); rb_define_method(rb_cDir,"seek", dir_seek, 1); + rb_define_method(rb_cDir,"pos", dir_tell, 0); + rb_define_method(rb_cDir,"pos=", dir_seek, 1); rb_define_method(rb_cDir,"close", dir_close, 0); rb_define_singleton_method(rb_cDir,"chdir", dir_s_chdir, -1); diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in index 44232da7a1..c97f86a687 100644 --- a/ext/extmk.rb.in +++ b/ext/extmk.rb.in @@ -425,10 +425,12 @@ all: $(DLLIB) clean:; @$(RM) *.#{$OBJEXT} *.so *.sl *.#{$LIBEXT} $(DLLIB) @$(RM) *.ilk *.exp *.pdb *.bak + +distclean: clean @$(RM) Makefile extconf.h conftest.* @$(RM) core ruby$(EXEEXT) *~ -realclean: clean +realclean: distclean EOS mfile.printf <val}) + else + tk_call 'itemconfigure', index, "-#{key}", val + end + end + end + + def itemconfiginfo(index, key=nil) + if key + conf = tk_split_list(tk_send('itemconfigure',index,"-#{key}")) + conf[0] = conf[0][1..-1] + conf + else + tk_split_list(tk_send('itemconfigure', index)).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + end + end end module TkTreatMenuEntryFont @@ -2397,6 +2490,9 @@ class TkMenu@variable, + 'label'=>value, 'value'=>value) + end + def index(index) + @menu.index(index) + end + def invoke(index) + @menu.invoke(index) + end + def insert(index, value) + @menu.add(index, 'radiobutton', 'variable'=>@variable, + 'label'=>value, 'value'=>value) + end + def delete(index, last=None) + @menu.delete(index, last) + end + def yposition(index) + @menu.yposition(index) + end + def menucget(index, key) + @menu.cget(index, key) + end + def menuconfigure(index, key, val=None) + @menu.configure(index, key, val) + end + def menuconfiginfo(index, key=nil) + @menu.configinfo(index, key) + end + def entrycget(index, key) + @menu.entrycget(index, key) + end + def entryconfigure(index, key, val=None) + @menu.entryconfigure(index, key, val) + end + def entryconfiginfo(index, key=nil) + @menu.entryconfiginfo(index, key) + end +end + module TkComposite include Tk extend Tk diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index 914bfe01e3..5f4bdadaee 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -217,7 +217,7 @@ class TkCanvas "(t1)&&(t2)" + # ltag = tag1 | tag2; ltag.path => "(t1)||(t2)" + # ltag = tag1 ^ tag2; ltag.path => "(t1)^(t2)" + # ltag = - tag1; ltag.path => "!(t1)" + def & (tag) + if tag.kind_of? TkObject + TkcTagString.new(@c, '(' + @id + ')&&(' + tag.path + ')') + else + TkcTagString.new(@c, '(' + @id + ')&&(' + tag.to_s + ')') + end + end + + def | (tag) + if tag.kind_of? TkObject + TkcTagString.new(@c, '(' + @id + ')||(' + tag.path + ')') + else + TkcTagString.new(@c, '(' + @id + ')||(' + tag.to_s + ')') + end + end + + def ^ (tag) + if tag.kind_of? TkObject + TkcTagString.new(@c, '(' + @id + ')^(' + tag.path + ')') + else + TkcTagString.new(@c, '(' + @id + ')^(' + tag.to_s + ')') + end + end + + def -@ + TkcTagString.new(@c, '!(' + @id + ')') + end end class TkcTagst_mode)) return Qtrue; - #endif return Qfalse; } @@ -1931,7 +1930,7 @@ rb_stat_sticky(obj) #ifdef S_ISVTX if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue; #endif - return Qnil; + return Qfalse; } static VALUE rb_mConst; diff --git a/io.c b/io.c index 21d76994b5..a35f306b25 100644 --- a/io.c +++ b/io.c @@ -281,27 +281,35 @@ rb_io_tell(io) return rb_int2inum(pos); } +#ifndef SEEK_CUR +# define SEEK_SET 0 +# define SEEK_CUR 1 +# define SEEK_END 2 +#endif + static VALUE -rb_io_seek(io, offset, ptrname) - VALUE io, offset, ptrname; +rb_io_seek(argc, argv, io) + int argc; + VALUE *argv; + VALUE io; { + VALUE offset, ptrname; + int whence; OpenFile *fptr; long pos; + rb_scan_args(argc, argv, "11", &offset, &ptrname); + if (argc == 1) whence = SEEK_SET; + else whence = NUM2INT(ptrname); + GetOpenFile(io, fptr); - pos = fseek(fptr->f, NUM2INT(offset), NUM2INT(ptrname)); + pos = fseek(fptr->f, NUM2INT(offset), whence); if (pos != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); return INT2FIX(0); } -#ifndef SEEK_CUR -# define SEEK_SET 0 -# define SEEK_CUR 1 -# define SEEK_END 2 -#endif - static VALUE rb_io_set_pos(io, offset) VALUE io, offset; diff --git a/lib/jcode.rb b/lib/jcode.rb index a7606d04ce..49262857a8 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -108,10 +108,6 @@ class String h end - def bsquote(str) - str.gsub(/\\/, '\\\\\\\\') - end - HashCache = {} TrPatternCache = {} DeletePatternCache = {} @@ -122,7 +118,7 @@ class String def tr!(from, to) return self.delete!(from) if to.length == 0 - pattern = TrPatternCache[from] ||= /[#{bsquote(from)}]/ + pattern = TrPatternCache[from] ||= /[#{Regexp::quote(from)}]/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) @@ -137,7 +133,7 @@ class String end def delete!(del) - self.gsub!(DeletePatternCache[del] ||= /[#{bsquote(del)}]+/, '') + self.gsub!(DeletePatternCache[del] ||= /[#{Regexp::quote(del)}]+/, '') end def delete(del) @@ -147,7 +143,7 @@ class String def squeeze!(del=nil) pattern = if del - SqueezePatternCache[del] ||= /([#{bsquote(del)}])\1+/ + SqueezePatternCache[del] ||= /([#{Regexp::quote(del)}])\1+/ else /(.|\n)\1+/ end @@ -161,7 +157,7 @@ class String def tr_s!(from, to) return self.delete!(from) if to.length == 0 - pattern = SqueezePatternCache[from] ||= /([#{bsquote(from)}])\1+"/ #" + pattern = SqueezePatternCache[from] ||= /([#{Regexp::quote(from)}])\1+"/ #" if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) @@ -194,11 +190,11 @@ class String def each_char if iterator? - scan(/./) do |x| + scan(/./m) do |x| yield x end else - scan(/./) + scan(/./m) end end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 5dc843f47b..b885690ec5 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -406,10 +406,12 @@ all: $(DLLIB) clean:; @$(RM) *.#{$OBJEXT} *.so *.sl *.a $(DLLIB) @$(RM) $(TARGET).lib $(TARGET).exp $(TARGET).ilk *.pdb + +distclean: clean @$(RM) Makefile extconf.h conftest.* @$(RM) core ruby$(EXEEXT) *~ -realclean: clean +realclean: distclean install: $(archdir)/$(DLLIB) diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index a0a770b473..763c076d8a 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -14,11 +14,11 @@ (substring ruby-mode-revision (match-beginning 0) (match-end 0)))) (defconst ruby-block-beg-re - "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin" + "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do" ) (defconst ruby-non-block-do-re - "while\\|until\\|for\\|rescue" + "\\(while\\|until\\|for\\|rescue\\)\\>" ) (defconst ruby-indent-beg-re diff --git a/numeric.c b/numeric.c index f84bdede1f..589f06bfc0 100644 --- a/numeric.c +++ b/numeric.c @@ -679,6 +679,40 @@ flo_zero_p(num) return Qfalse; } +static VALUE flo_is_nan_p(num) + VALUE num; +{ + + double value = RFLOAT(num)->value; + + return isnan(value) ? Qtrue : Qfalse; +} + +static VALUE flo_is_infinite_p(num) + VALUE num; +{ + double value = RFLOAT(num)->value; + + if (isinf(value)) { + return INT2FIX( value < 0 ? -1 : +1 ); + } + + return Qnil; +} + + +static VALUE flo_is_finite_p(num) + VALUE num; +{ + double value = RFLOAT(num)->value; + + if (isinf(value) || isnan(value)) + return Qfalse; + + return Qtrue; +} + + static VALUE to_integer(val) VALUE val; @@ -1570,4 +1604,8 @@ Init_Numeric() rb_define_method(rb_cFloat, "floor", flo_floor, 0); rb_define_method(rb_cFloat, "ceil", flo_ceil, 0); rb_define_method(rb_cFloat, "round", flo_round, 0); + + rb_define_method(rb_cFloat, "nan?", flo_is_nan_p, 0); + rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0); + rb_define_method(rb_cFloat, "finite?", flo_is_finite_p, 0); } diff --git a/re.c b/re.c index 17d4ea9601..ca1972add6 100644 --- a/re.c +++ b/re.c @@ -613,7 +613,7 @@ rb_reg_search(re, str, pos, reverse) if (result == -2) { rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, - "Stack overfow in regexp matcher", re); + "Stack overflow in regexp matcher", re); } if (result < 0) { diff --git a/rubytest.rb b/rubytest.rb index 20032e303e..a2380e6f4c 100644 --- a/rubytest.rb +++ b/rubytest.rb @@ -3,6 +3,12 @@ require 'rbconfig' include Config +unless File.exist? "./#{CONFIG['ruby_install_name']}" + print "./#{CONFIG['ruby_install_name']} is not found.\n" + print "Try `make' first, then `make test', please.\n" + exit 0 +end + if File.exist? CONFIG['LIBRUBY_SO'] case RUBY_PLATFORM when /-hpux/ @@ -25,6 +31,7 @@ end $stderr.reopen($stdout) error = '' + `./#{CONFIG["ruby_install_name"]} #{CONFIG["srcdir"]}/sample/test.rb`.each do |line| if line =~ /^end of test/ print "test succeeded\n" diff --git a/time.c b/time.c index 68d7bde561..c26ec02e4e 100644 --- a/time.c +++ b/time.c @@ -208,6 +208,7 @@ time_arg(argc, argv, tm) VALUE v[6]; int i; + MEMZERO(tm, struct tm, 1); if (argc == 10) { v[0] = argv[5]; v[1] = argv[4]; @@ -215,6 +216,7 @@ time_arg(argc, argv, tm) v[3] = argv[2]; v[4] = argv[1]; v[5] = argv[0]; + tm->tm_isdst = RTEST(argv[9]) ? 1 : 0; } else { rb_scan_args(argc, argv, "15", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5]); @@ -271,9 +273,9 @@ static VALUE time_localtime _((VALUE)); static VALUE time_get_tm _((VALUE, int)); static time_t -make_time_t(tptr, fn) +make_time_t(tptr, utc_or_local) struct tm *tptr; - struct tm *(*fn)(); + int utc_or_local; { struct timeval tv; time_t oguess, guess; @@ -285,30 +287,73 @@ make_time_t(tptr, fn) } guess = tv.tv_sec; - tm = (*fn)(&guess); + tm = gmtime(&guess); if (!tm) goto error; t = tptr->tm_year; if (t < 69) goto out_of_range; while (diff = t - tm->tm_year) { oguess = guess; - guess += diff * 364 * 24 * 3600; + guess += diff * 363 * 24 * 3600; if (diff > 0 && guess <= oguess) goto out_of_range; - tm = (*fn)(&guess); + tm = gmtime(&guess); if (!tm) goto error; } t = tptr->tm_mon; while (diff = t - tm->tm_mon) { guess += diff * 27 * 24 * 3600; - tm = (*fn)(&guess); + tm = gmtime(&guess); if (!tm) goto error; if (tptr->tm_year != tm->tm_year) goto out_of_range; } - guess += (tptr->tm_mday - tm->tm_mday) * 3600 * 24; + guess += (tptr->tm_mday - tm->tm_mday) * 24 * 3600; guess += (tptr->tm_hour - tm->tm_hour) * 3600; guess += (tptr->tm_min - tm->tm_min) * 60; guess += (tptr->tm_sec - tm->tm_sec); if (guess < 0) goto out_of_range; + if (!utc_or_local) { /* localtime zone adjust */ +#if defined(HAVE_DAYLIGHT) + extern int daylight; + extern long timezone; + + localtime(&guess); + guess += timezone + daylight; +#else + struct tm gt, lt; + long tzsec; + + t = 0; + gt = *gmtime(&guess); + lt = *localtime(&guess); + tzsec = (gt.tm_min-lt.tm_min)*60 + (gt.tm_hour-lt.tm_hour)*3600; + + if(lt.tm_year > gt.tm_year) { + tzsec -= 24*3600; + } + else if(gt.tm_year > lt.tm_year) { + tzsec += 24*3600; + } + else { + tzsec += (gt.tm_yday - lt.tm_yday)*24*3600; + } + + if (lt.tm_isdst) tzsec += 3600; + + guess += tzsec; + if (guess < 0) { + goto out_of_range; + } + tm = localtime(&guess); + if (!tm) goto error; + if (tm->tm_hour != tptr->tm_hour) { + guess -= 3600; + } +#endif + if (guess < 0) { + goto out_of_range; + } + } + return guess; out_of_range: @@ -320,40 +365,37 @@ make_time_t(tptr, fn) } static VALUE -time_gm_or_local(argc, argv, gm_or_local, klass) +time_utc_or_local(argc, argv, utc_or_local, klass) int argc; VALUE *argv; - int gm_or_local; + int utc_or_local; VALUE klass; { struct tm tm; - struct tm *(*fn)(); VALUE time; - fn = (gm_or_local) ? gmtime : localtime; time_arg(argc, argv, &tm); - - time = time_new_internal(klass, make_time_t(&tm, fn), 0); - if (gm_or_local) return time_gmtime(time); + time = time_new_internal(klass, make_time_t(&tm, utc_or_local), 0); + if (utc_or_local) return time_gmtime(time); return time_localtime(time); } static VALUE -time_s_timegm(argc, argv, klass) +time_s_mkutc(argc, argv, klass) int argc; VALUE *argv; VALUE klass; { - return time_gm_or_local(argc, argv, 1, klass); + return time_utc_or_local(argc, argv, Qtrue, klass); } static VALUE -time_s_timelocal(argc, argv, klass) +time_s_mktime(argc, argv, klass) int argc; VALUE *argv; VALUE klass; { - return time_gm_or_local(argc, argv, 0, klass); + return time_utc_or_local(argc, argv, Qfalse, klass); } static VALUE @@ -765,8 +807,12 @@ time_zone(time) time_get_tm(time, tobj->gmt); } +#ifdef HAVE_TZNAME + return rb_str_new2(tobj->tm.tm_zone); +#else len = strftime(buf, 64, "%Z", &tobj->tm); return rb_str_new(buf, len); +#endif } static VALUE @@ -990,9 +1036,10 @@ Init_Time() rb_define_singleton_method(rb_cTime, "now", time_s_now, 0); rb_define_singleton_method(rb_cTime, "new", time_s_new, -1); rb_define_singleton_method(rb_cTime, "at", time_s_at, -1); - rb_define_singleton_method(rb_cTime, "gm", time_s_timegm, -1); - rb_define_singleton_method(rb_cTime, "local", time_s_timelocal, -1); - rb_define_singleton_method(rb_cTime, "mktime", time_s_timelocal, -1); + rb_define_singleton_method(rb_cTime, "utc", time_s_mkutc, -1); + rb_define_singleton_method(rb_cTime, "gm", time_s_mkutc, -1); + rb_define_singleton_method(rb_cTime, "local", time_s_mktime, -1); + rb_define_singleton_method(rb_cTime, "mktime", time_s_mktime, -1); rb_define_singleton_method(rb_cTime, "times", time_s_times, 0); diff --git a/version.h b/version.h index 4eba36d043..51e086cb95 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.5.4" -#define RUBY_RELEASE_DATE "2000-06-05" +#define RUBY_RELEASE_DATE "2000-06-12" #define RUBY_VERSION_CODE 154 -#define RUBY_RELEASE_CODE 20000605 +#define RUBY_RELEASE_CODE 20000612 -- cgit v1.2.3