From 99020d6e50702eb371111d73280eb80b4b29ba5b Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 25 Dec 2000 06:29:27 +0000 Subject: 001225 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 34 ++++++++++++++++++++++++++++++++-- Makefile.in | 14 +++++++------- ToDo | 1 + array.c | 3 --- bignum.c | 35 +++++++++++++++++++---------------- eval.c | 6 ++++-- hash.c | 13 +++++++++---- lib/date.rb | 1 + lib/mkmf.rb | 6 +++--- lib/singleton.rb | 4 ++-- misc/ruby-mode.el | 3 ++- object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ parse.y | 13 ++++++++++--- process.c | 20 -------------------- string.c | 47 +++++++++++++++++++++++++++++------------------ version.h | 4 ++-- 16 files changed, 164 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index b09d9317d4..c6cd432b49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,36 @@ Mon Dec 25 04:43:02 2000 Minero Aoki * lib/net/http.rb: does not send HEAD on closing socket. +Mon Dec 25 00:44:48 2000 Yukihiro Matsumoto + + * hash.c (rb_any_cmp): should use rb_str_cmp() if TYPE == T_STRING + and CLASS_OF == rb_cString. + + * string.c (rb_str_new4): should copy class of original too. + +Mon Dec 25 00:04:54 2000 Nobuyoshi Nakada + + * eval.c (rb_thread_schedule): initial value of `max' changed to -1. + +Fri Dec 22 17:59:30 2000 Yukihiro Matsumoto + + * stable version 1.6.2 released. + +Mon Dec 25 00:16:14 2000 Yukihiro Matsumoto + + * string.c (rb_str_replace_m): copy-on-write replace. + + * parse.y (yylex): should handle => after identifier as well as == + and =~. + +Sat Dec 23 23:55:57 2000 Yukihiro Matsumoto + + * bignum.c (rb_cstr2inum): Integer("") should not return 0. + +Sat Dec 23 11:55:57 2000 Yukihiro Matsumoto + + * array.c (rb_ary_and): Array#& should preverve original order. + Sat Dec 23 03:44:16 2000 Minero Aoki * lib/net/protocol.rb: set @closed false in Socket#reopen. @@ -22,9 +52,9 @@ Sat Dec 23 03:44:16 2000 Minero Aoki * lib/net/http.rb: refactoring. -Fri Dec 22 17:59:30 2000 Yukihiro Matsumoto +Fri Dec 22 23:11:12 2000 Ueno Katsuhiro - * stable version 1.6.2 released. + * eval.c (rb_feature_p): ext might be null. Fri Dec 22 17:04:12 2000 Nobuyoshi Nakada diff --git a/Makefile.in b/Makefile.in index 34e6dda080..b1b0166b89 100644 --- a/Makefile.in +++ b/Makefile.in @@ -237,21 +237,21 @@ win32.@OBJEXT@: $(srcdir)/win32/win32.c ### parse.@OBJEXT@: parse.y ruby.h config.h defines.h intern.h env.h node.h st.h regex.h util.h lex.c ### -array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h st.h +array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h util.h st.h bignum.@OBJEXT@: bignum.c ruby.h config.h defines.h intern.h -class.@OBJEXT@: class.c ruby.h config.h defines.h intern.h node.h st.h +class.@OBJEXT@: class.c ruby.h config.h defines.h intern.h rubysig.h node.h st.h compar.@OBJEXT@: compar.c ruby.h config.h defines.h intern.h dir.@OBJEXT@: dir.c ruby.h config.h defines.h intern.h dln.@OBJEXT@: dln.c config.h defines.h dln.h dmyext.@OBJEXT@: dmyext.c -enum.@OBJEXT@: enum.c ruby.h config.h defines.h intern.h +enum.@OBJEXT@: enum.c ruby.h config.h defines.h intern.h node.h error.@OBJEXT@: error.c ruby.h config.h defines.h intern.h env.h version.h eval.@OBJEXT@: eval.c ruby.h config.h defines.h intern.h node.h env.h rubysig.h st.h dln.h -file.@OBJEXT@: file.c ruby.h config.h defines.h intern.h rubyio.h rubysig.h +file.@OBJEXT@: file.c ruby.h config.h defines.h intern.h rubyio.h rubysig.h dln.h gc.@OBJEXT@: gc.c ruby.h config.h defines.h intern.h rubysig.h st.h node.h env.h re.h regex.h hash.@OBJEXT@: hash.c ruby.h config.h defines.h intern.h st.h rubysig.h util.h inits.@OBJEXT@: inits.c ruby.h config.h defines.h intern.h -io.@OBJEXT@: io.c ruby.h config.h defines.h intern.h rubyio.h rubysig.h env.h +io.@OBJEXT@: io.c ruby.h config.h defines.h intern.h rubyio.h rubysig.h env.h util.h main.@OBJEXT@: main.c ruby.h config.h defines.h intern.h marshal.@OBJEXT@: marshal.c ruby.h config.h defines.h intern.h rubyio.h st.h prec.@OBJEXT@: prec.c ruby.h config.h defines.h intern.h @@ -263,8 +263,8 @@ process.@OBJEXT@: process.c ruby.h config.h defines.h intern.h rubysig.h st.h random.@OBJEXT@: random.c ruby.h config.h defines.h intern.h range.@OBJEXT@: range.c ruby.h config.h defines.h intern.h re.@OBJEXT@: re.c ruby.h config.h defines.h intern.h re.h regex.h -regex.@OBJEXT@: regex.c config.h regex.h util.h -ruby.@OBJEXT@: ruby.c ruby.h config.h defines.h intern.h dln.h util.h +regex.@OBJEXT@: regex.c config.h regex.h +ruby.@OBJEXT@: ruby.c ruby.h config.h defines.h intern.h dln.h node.h util.h signal.@OBJEXT@: signal.c ruby.h config.h defines.h intern.h rubysig.h sprintf.@OBJEXT@: sprintf.c ruby.h config.h defines.h intern.h st.@OBJEXT@: st.c config.h st.h diff --git a/ToDo b/ToDo index 5d46a525eb..5f67a42b25 100644 --- a/ToDo +++ b/ToDo @@ -51,6 +51,7 @@ Hacking Interpreter * export rb_io_{addstr,printf,puts,print} * autoload should work with threads [ruby-talk:4589] * remove stdio dependency from IOs. +* warn for inconsistent local variable usage (lv m and method m at the same time). Standard Libraries diff --git a/array.c b/array.c index 5e91ae9293..638b392753 100644 --- a/array.c +++ b/array.c @@ -1463,9 +1463,6 @@ rb_ary_and(ary1, ary2) long i; ary2 = to_ary(ary2); - if (RARRAY(ary1)->len < RARRAY(ary2)->len) { /* swap */ - VALUE tmp = ary1; ary1 = ary2; ary2 = tmp; - } hash = ary_make_hash(ary2, 0); for (i=0; ilen; i++) { diff --git a/bignum.c b/bignum.c index 1e847dd7af..daf131b042 100644 --- a/bignum.c +++ b/bignum.c @@ -219,12 +219,8 @@ rb_cstr2inum(str, base) } else { base = 8; - if (!str[1]) return INT2FIX(0); } } - else if (str[0] == 0) { - return INT2FIX(0); - } else { base = 10; } @@ -256,7 +252,7 @@ rb_cstr2inum(str, base) while (*end && ISSPACE(*end)) end++; if (*end) { /* trailing garbage */ bad: - rb_raise(rb_eArgError, "invalid literal for Integer: %s", s); + rb_raise(rb_eArgError, "invalid value for Integer: \"%s\"", s); } } @@ -282,28 +278,28 @@ rb_cstr2inum(str, base) for (i=len;i--;) zds[i]=0; while (c = *str++) { switch (c) { + case '8': case '9': + if (base == 8) { + c = base; + break; + } case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '5': case '6': case '7': c = c - '0'; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - c = c - 'a' + 10; + if (base != 16) c = base; + else c = c - 'a' + 10; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - c = c - 'A' + 10; + if (base != 16) c = base; + else c = c - 'A' + 10; break; case '_': continue; default: - if (badcheck) { - if (ISSPACE(c)) { - while (*str && ISSPACE(*str)) str++; - if (!*str) break; - } - rb_raise(rb_eArgError, "invalid literal for Integer: %s", s); - } c = base; break; } @@ -323,7 +319,14 @@ rb_cstr2inum(str, base) break; } } - if (badcheck && s+2 < str && str[-2] == '_') goto bad; + if (badcheck) { + str--; + if (s+1 < str && str[-1] == '_') goto bad; + if (ISSPACE(c)) { + while (*str && ISSPACE(*str)) str++; + } + if (*str) goto bad; + } return bignorm(z); } diff --git a/eval.c b/eval.c index 2588427411..ae2ce62da9 100644 --- a/eval.c +++ b/eval.c @@ -5162,7 +5162,7 @@ rb_feature_p(feature, wait) load_wait: if (loading_tbl) { char *ext = strrchr(f, '.'); - if (strcmp(ext, ".rb") == 0) { + if (ext && strcmp(ext, ".rb") == 0) { rb_thread_t th; while (st_lookup(loading_tbl, f, &th)) { @@ -7177,7 +7177,7 @@ rb_thread_schedule() } again: - max = 0; + max = -1; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); @@ -8332,6 +8332,7 @@ rb_thread_inspect(thread) void rb_thread_atfork() { +#if 0 /* enable on 1.7 */ rb_thread_t th; if (rb_thread_alone()) return; @@ -8344,6 +8345,7 @@ rb_thread_atfork() main_thread = curr_thread; curr_thread->next = curr_thread; curr_thread->prev = curr_thread; +#endif } static VALUE rb_cCont; diff --git a/hash.c b/hash.c index 513eeb4347..2a5803c96e 100644 --- a/hash.c +++ b/hash.c @@ -59,11 +59,15 @@ rb_any_cmp(a, b) VALUE a, b; { VALUE args[2]; - if (FIXNUM_P(a)) { - if (FIXNUM_P(b)) return a != b; + if (FIXNUM_P(a) && FIXNUM_P(b)) { + return a != b; } - else if (TYPE(a) == T_STRING) { - if (TYPE(b) == T_STRING) return rb_str_cmp(a, b); + if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString && + TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) { + return rb_str_cmp(a, b); + } + if (SYMBOL_P(a) && SYMBOL_P(b)) { + return a != b; } args[0] = a; @@ -79,6 +83,7 @@ rb_any_hash(a) switch (TYPE(a)) { case T_FIXNUM: + case T_SYMBOL: hval = a; break; diff --git a/lib/date.rb b/lib/date.rb index 4abf75f431..58179a7153 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -202,6 +202,7 @@ class Date for id in ids module_eval <<-"end;" alias_method :__#{id.to_i}__, :#{id.id2name} + private :__#{id.to_i}__ def #{id.id2name}(*args, &block) (@__#{id.to_i}__ ||= [__#{id.to_i}__(*args, &block)])[0] end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 788a957792..317200ba79 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -44,7 +44,7 @@ else end LINK = "#{CONFIG['CC']} -o conftest -I#{$hdrdir} #{CFLAGS} -I#{CONFIG['includedir']} %s #{CONFIG['LDFLAGS']} %s conftest.c %s %s #{CONFIG['LIBS']}" -CPP = "#{CONFIG['CPP']} -E -I#{$hdrdir} #{CFLAGS} -I#{CONFIG['includedir']} %s %s conftest.c" +CPP = "#{CONFIG['CPP']} -E %s -I#{$hdrdir} #{CFLAGS} -I#{CONFIG['includedir']} %s %s conftest.c" def rm_f(*files) targets = [] @@ -104,7 +104,7 @@ def try_cpp(src, opt="") cfile.print src cfile.close begin - xsystem(format(CPP, $CFLAGS, opt)) + xsystem(format(CPP, $CPPFLAGS, $CFLAGS, opt)) ensure rm_f "conftest*" end @@ -115,7 +115,7 @@ def egrep_cpp(pat, src, opt="") cfile.print src cfile.close begin - xsystem(format(CPP+"|egrep #{pat}", $CFLAGS, opt)) + xsystem(format(CPP+"|egrep #{pat}", $CPPFLAGS, $CFLAGS, opt)) ensure rm_f "conftest*" end diff --git a/lib/singleton.rb b/lib/singleton.rb index 235ba898fd..aa245b32b2 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -16,10 +16,10 @@ module Singleton klass.instance_eval %{ @__instance__ = nil def instance - Thread.critical = true unless @__instance__ + Thread.critical = true begin - @__instance__ = new + @__instance__ ||= new ensure Thread.critical = false end diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index cfb0b3a0de..c0754efad4 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -663,13 +663,14 @@ An end of a defun is found by moving forward from the beginning of one." (or (boundp 'font-lock-variable-name-face) (setq font-lock-variable-name-face font-lock-type-face)) + (add-hook 'ruby-mode-hook '(lambda () (make-local-variable 'font-lock-syntactic-keywords) (setq font-lock-syntactic-keywords '(("\\$\\([#\"'`$\\]\\)" 1 (1 . nil)) ("\\(#\\)[{$@]" 1 (1 . nil)) - ("\\(/\\)\\([^/]\\|\\\\/\\)*\\(/\\)" + ("\\(/\\)\\([^/\n]\\|\\\\/\\)*\\(/\\)" (1 (7 . ?')) (3 (7 . ?'))))) (make-local-variable 'font-lock-defaults) diff --git a/object.c b/object.c index e7f202a5eb..4e3d5dd856 100644 --- a/object.c +++ b/object.c @@ -15,6 +15,7 @@ #include "ruby.h" #include "st.h" #include +#include VALUE rb_mKernel; VALUE rb_cObject; @@ -946,6 +947,48 @@ rb_Float(val) case T_BIGNUM: return rb_float_new(rb_big2dbl(val)); + case T_STRING: + { + char *q, *p, *end; + double d; + + q = p = STR2CSTR(val); + while (*p && ISSPACE(*p)) p++; + again: + d = strtod(p, &end); + if (p == end) { + bad: + rb_raise(rb_eArgError, "invalid value for Float: \"%s\"", q); + } + if (*end) { + if (*end == '_') { + char *buf = ALLOCA_N(char, strlen(p)); + char *n = buf, *last; + + while (*p) { + if (*p == '_') { + last = ++p; + continue; + } + *n++ = *p++; + } + while (*last && (*last == '_' || ISSPACE(*last))) + last++; + if (!*last) goto bad; + *n = '\0'; + p = buf; + goto again; + } + while (*end && ISSPACE(*end)) end++; + if (*end) goto bad; + } + if (errno == ERANGE) { + errno = 0; + rb_raise(rb_eArgError, "Float %s out of range", p); + } + return rb_float_new(d); + } + case T_NIL: return rb_float_new(0.0); diff --git a/parse.y b/parse.y index ea0e33f609..d1f1a32321 100644 --- a/parse.y +++ b/parse.y @@ -3244,9 +3244,11 @@ yylex() tokadd(c); seen_e++; is_float++; - if ((c = nextc()) == '-' || c == '+') + while ((c = nextc()) == '_') + seen_uc = 1; + if (c == '-' || c == '+') tokadd(c); - else + else continue; break; @@ -3628,7 +3630,12 @@ yylex() } else { if (lex_state == EXPR_FNAME) { - if ((c = nextc()) == '=' && !peek('=') && !peek('~')) { +#if 0 + if ((c = nextc()) == '=' && !peek('=') && !peek('~') && !peek('>')) { +#else + if ((c = nextc()) == '=' && !peek('~') && !peek('>') && + (!peek('=') || lex_p + 1 < lex_pend && lex_p[1] == '>')) { +#endif result = tIDENTIFIER; tokadd(c); } diff --git a/process.c b/process.c index 657b316864..3537841d43 100644 --- a/process.c +++ b/process.c @@ -530,21 +530,6 @@ rb_f_exec(argc, argv) return Qnil; /* dummy */ } -static VALUE -fork_rescue(data, errinfo) - VALUE data, errinfo; -{ - int status = 1; - - if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) { - VALUE st = rb_iv_get(errinfo, "status"); - - status = NUM2INT(st); - } - ruby_finalize(); - _exit(status); -} - static VALUE rb_f_fork(obj) VALUE obj; @@ -560,15 +545,10 @@ rb_f_fork(obj) #endif rb_thread_atfork(); if (rb_block_given_p()) { -#if 0 - rb_rescue2(rb_yield, Qnil, fork_rescue, 0, rb_eException, 0); - _exit(0); -#else int status; rb_protect(rb_yield, Qnil, &status); ruby_stop(status); -#endif } return Qnil; diff --git a/string.c b/string.c index 573d6944b5..ddf50e2eed 100644 --- a/string.c +++ b/string.c @@ -97,19 +97,29 @@ VALUE rb_str_new4(orig) VALUE orig; { - if (OBJ_FROZEN(orig)) return orig; + VALUE klass; + + klass = CLASS_OF(orig); + while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) { + klass = (VALUE)RCLASS(klass)->super; + } + if (RSTRING(orig)->orig) { + VALUE str; + if (FL_TEST(orig, STR_NO_ORIG)) { - orig = rb_str_new(RSTRING(orig)->ptr, RSTRING(orig)->len); - OBJ_FREEZE(orig); - return orig; + str = rb_str_new(RSTRING(orig)->ptr, RSTRING(orig)->len); } - OBJ_FREEZE(RSTRING(orig)->orig); - return RSTRING(orig)->orig; + else { + str = rb_str_new3(RSTRING(orig)->orig); + } + OBJ_FREEZE(str); + RBASIC(str)->klass = klass; + return str; } else { NEWOBJ(str, struct RString); - OBJSETUP(str, rb_cString, T_STRING); + OBJSETUP(str, klass, T_STRING); str->len = RSTRING(orig)->len; str->ptr = RSTRING(orig)->ptr; @@ -203,14 +213,7 @@ rb_str_dup(str) str2 = rb_str_new3(RSTRING(str)->orig); } else { - NEWOBJ(dup, struct RString); - OBJSETUP(dup, klass, T_STRING); - - str2 = rb_str_new4(str); - dup->len = RSTRING(str2)->len; - dup->ptr = RSTRING(str2)->ptr; - dup->orig = str2; - str2 = (VALUE)dup; + str2 = rb_str_new3(rb_str_new4(str)); } OBJ_INFECT(str2, str); RBASIC(str2)->klass = klass; @@ -1315,10 +1318,18 @@ rb_str_replace_m(str, str2) { if (TYPE(str2) != T_STRING) str2 = rb_str_to_str(str2); rb_str_modify(str); - rb_str_resize(str, RSTRING(str2)->len); - memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len); - if (OBJ_TAINTED(str2)) OBJ_TAINT(str); + if (RSTRING(str2)->orig && FL_TEST(str2, STR_NO_ORIG)) { + RSTRING(str)->len = RSTRING(str2)->len; + RSTRING(str)->ptr = RSTRING(str2)->ptr; + RSTRING(str)->orig = RSTRING(str2)->orig; + } + else { + rb_str_resize(str, RSTRING(str2)->len); + memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len); + } + + if (OBJ_TAINTED(str2)) OBJ_TAINT(str); return str; } diff --git a/version.h b/version.h index 7a8db96961..71d484b8fd 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.6.2" -#define RUBY_RELEASE_DATE "2000-12-22" +#define RUBY_RELEASE_DATE "2000-12-25" #define RUBY_VERSION_CODE 162 -#define RUBY_RELEASE_CODE 20001222 +#define RUBY_RELEASE_CODE 20001225 -- cgit v1.2.3