From 4f51d814183316c3e97da1dc13cf6945b5a76f2f Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 4 Jul 2000 04:17:26 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 22 +++++++++++++++++++++- ToDo | 5 +++-- eval.c | 14 +++++++++++--- ext/socket/socket.c | 26 +++++++++++++++----------- gc.c | 5 +---- io.c | 6 +----- misc/ruby-mode.el | 15 +++++++++------ numeric.c | 8 ++++---- parse.y | 7 +++++-- random.c | 17 +++++++++++++---- ruby.h | 1 + sample/test.rb | 12 ++++-------- util.c | 1 + win32/ruby.def | 1 + 14 files changed, 90 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8362668ec6..7dd28a371c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,27 @@ +Tue Jul 4 13:16:02 2000 Yukihiro Matsumoto + + * util.c (rb_type): should add T_UNDEF. + +Tue Jul 4 09:30:35 2000 Yukihiro Matsumoto + + * parse.y (here_document): supports EOF right after terminator. + + * random.c (rb_f_rand): argument is now optional (rand(max=0)). + Tue Jul 4 01:50:49 2000 WATANABE Hirofumi * win32/ruby.def: remove ruby_mktemp. +Tue Jul 4 01:27:13 2000 Yukihiro Matsumoto + + * eval.c (rb_rescue2): new function to rescue arbitrary exception. + + * numeric.c (do_coerce): should catch NameError explicitly. + +Tue Jul 4 00:15:23 2000 Dave Thomas + + * numeric.c (Init_Numeric): forgot to register Numeric#remainder. + Mon Jul 3 18:35:41 2000 WATANABE Hirofumi * lib/mkmf.rb: use null device if it exists for cross-compiling. @@ -18,7 +38,7 @@ Mon Jul 3 16:47:22 2000 WATANABE Hirofumi * cygwin/GNUmakefile: librubys.a -> lib$(RUBY_INSTALL_NAME)s.a - * configure.in: use AC_CANONICAL_{TARGET,HOST,BUILD}. + * configure.in: use AC_CANONICAL_{HOST,TARGET,BUILD}. Mon Jul 3 13:15:02 2000 Yukihiro Matsumoto diff --git a/ToDo b/ToDo index c4654d9250..297e6e231d 100644 --- a/ToDo +++ b/ToDo @@ -6,7 +6,7 @@ Language Spec. - %w(a\ b\ c abc) => ["a b c", "abc"] - objectify symbols - class variable (prefix @@) -- rescue RuntimeError in err ?? +- rescue RuntimeError =>n err * operator !! for rescue. ??? * objectify characters * ../... outside condition invokes operator method too. @@ -73,6 +73,8 @@ Standard Libraries - 'w' template for pack/unpack - alternative for interator? => block_given? - regex - /p (make obsolete), /m (new) +- consistent /, %, divmod +* Enumerable#sort_by for Schwartzian transformation * String#scanf(?) * Object#fmt(?) * Integer#{bin,oct,hex,heX} @@ -113,5 +115,4 @@ Things To Do Before 1.6 * fix spec. for the following: - * alternative for $! (exception? in? =>? :?) * mkmf.rb - create_makefile("net/socket") diff --git a/eval.c b/eval.c index 7415581d63..b2e2d63074 100644 --- a/eval.c +++ b/eval.c @@ -3679,9 +3679,9 @@ handle_rescue(self, node) } VALUE -rb_rescue(b_proc, data1, r_proc, data2) +rb_rescue2(b_proc, data1, eclass, r_proc, data2) VALUE (*b_proc)(), (*r_proc)(); - VALUE data1, data2; + VALUE data1, eclass, data2; { int state; volatile VALUE result; @@ -3692,7 +3692,7 @@ rb_rescue(b_proc, data1, r_proc, data2) retry_entry: result = (*b_proc)(data1); } - else if (state == TAG_RAISE && rb_obj_is_kind_of(ruby_errinfo, rb_eStandardError)) { + else if (state == TAG_RAISE && rb_obj_is_kind_of(ruby_errinfo, eclass)) { if (r_proc) { PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { @@ -3718,6 +3718,14 @@ rb_rescue(b_proc, data1, r_proc, data2) return result; } +VALUE +rb_rescue(b_proc, data1, r_proc, data2) + VALUE (*b_proc)(), (*r_proc)(); + VALUE data1, data2; +{ + return rb_rescue2(b_proc, data1, rb_eStandardError, r_proc, data2); +} + VALUE rb_protect(proc, data, state) VALUE (*proc)(); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index bd39d7eb7c..8cf8f8d37f 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -519,7 +519,7 @@ mkipaddr0(addr, buf, len) error = getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST); if (error) { - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); } } @@ -605,7 +605,7 @@ ip_addrsetup(host, port) if (hostp && hostp[strlen(hostp)-1] == '\n') { rb_raise(rb_eSocket, "newline at the end of hostname"); } - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); } return res; @@ -662,14 +662,14 @@ ipaddr(sockaddr) error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf), NULL, 0, 0); if (error) { - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); } addr1 = rb_tainted_str_new2(hbuf); } error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV); if (error) { - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getnameinfo %s", gai_strerror(error)); } addr2 = rb_tainted_str_new2(hbuf); if (do_not_reverse_lookup) { @@ -809,7 +809,7 @@ open_inet(class, h, serv, type) } error = getaddrinfo(host, portp, &hints, &res0); if (error) { - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); } fd = -1; @@ -1856,7 +1856,7 @@ sock_s_getaddrinfo(argc, argv) } error = getaddrinfo(hptr, pptr, &hints, &res); if (error) { - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); } ret = mkaddrinfo(res); @@ -1962,7 +1962,7 @@ sock_s_getnameinfo(argc, argv) } #endif error = getaddrinfo(hptr, pptr, &hints, &res); - if (error) goto error_exit; + if (error) goto error_exit_addr; sap = res->ai_addr; } else { @@ -1971,7 +1971,7 @@ sock_s_getnameinfo(argc, argv) error = getnameinfo(sap, SA_LEN(sap), hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), fl); - if (error) goto error_exit; + if (error) goto error_exit_name; if (res) { for (r = res->ai_next; r; r = r->ai_next) { char hbuf2[1024], pbuf2[1024]; @@ -1979,7 +1979,7 @@ sock_s_getnameinfo(argc, argv) sap = r->ai_addr; error = getnameinfo(sap, SA_LEN(sap), hbuf2, sizeof(hbuf2), pbuf2, sizeof(pbuf2), fl); - if (error) goto error_exit; + if (error) goto error_exit_name; if (strcmp(hbuf, hbuf2) != 0|| strcmp(pbuf, pbuf2) != 0) { freeaddrinfo(res); rb_raise(rb_eSocket, "sockaddr resolved to multiple nodename"); @@ -1989,9 +1989,13 @@ sock_s_getnameinfo(argc, argv) } return rb_assoc_new(rb_tainted_str_new2(hbuf), rb_tainted_str_new2(pbuf)); - error_exit: + error_exit_addr: if (res) freeaddrinfo(res); - rb_raise(rb_eSocket, "%s", gai_strerror(error)); + rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); + + error_exit_name: + if (res) freeaddrinfo(res); + rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); } static VALUE mConst; diff --git a/gc.c b/gc.c index c615db031e..5bbd48bf8e 100644 --- a/gc.c +++ b/gc.c @@ -43,12 +43,11 @@ static void run_final(); #if defined(MSDOS) || defined(__human68k__) #define GC_MALLOC_LIMIT 100000 #else -#define GC_MALLOC_LIMIT 400000 +#define GC_MALLOC_LIMIT 4000000 #endif #endif static unsigned long malloc_memories = 0; -static unsigned long alloc_objects = 0; static void mem_error(mesg) @@ -282,7 +281,6 @@ rb_newobj() retry: obj = (VALUE)freelist; freelist = freelist->as.free.next; - alloc_objects++; return obj; } if (dont_gc || during_gc || rb_prohibit_interrupt) add_heap(); @@ -914,7 +912,6 @@ rb_gc() # define STACK_END (stack_end) #endif - alloc_objects = 0; malloc_memories = 0; if (during_gc) return; diff --git a/io.c b/io.c index cbc4719094..725e072fd9 100644 --- a/io.c +++ b/io.c @@ -2938,11 +2938,7 @@ rb_io_s_pipe() r = prep_stdio(rb_fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO); w = prep_stdio(rb_fdopen(pipes[1], "w"), FMODE_WRITABLE|FMODE_SYNC, rb_cIO); - ary = rb_ary_new2(2); - rb_ary_push(ary, r); - rb_ary_push(ary, w); - - return ary; + return rb_assoc_new(r, w); #else rb_notimplement(); return Qnil; /* not reached */ diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 763c076d8a..cffd853bb7 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -547,12 +547,15 @@ The variable ruby-indent-level controls the amount of indentation. (setq bol (point)) (end-of-line) (skip-chars-backward " \t") - (and (re-search-backward "#" (save-excursion - (beginning-of-line) - (point)) t) - (setq state (ruby-parse-region parse-start (point))) - (nth 0 state) - (goto-char (nth 0 state))) + (let ((pos (point))) + (and + (re-search-backward "#" (save-excursion + (beginning-of-line) + (point)) t) + (skip-chars-backward " \t") + (setq state (ruby-parse-region parse-start (point))) + (nth 0 state) + (goto-char pos))) (or (bobp) (forward-char -1)) (and (or (and (looking-at ruby-symbol-re) diff --git a/numeric.c b/numeric.c index af00d23da5..01b0c0d40f 100644 --- a/numeric.c +++ b/numeric.c @@ -70,7 +70,7 @@ do_coerce(x, y) VALUE a[2]; a[0] = *x; a[1] = *y; - ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a); + ary = rb_rescue2(coerce_body, (VALUE)a, rb_eNameError, coerce_rescue, (VALUE)a); if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) { rb_raise(rb_eTypeError, "coerce must return [x, y]"); } @@ -136,7 +136,7 @@ static VALUE num_remainder(x, y) VALUE x, y; { - rb_warn("remainder is deprecated; use % opearator"); + rb_warn("remainder is deprecated; use %% opearator"); return rb_funcall(x, '%', 1, y); } @@ -353,8 +353,7 @@ static VALUE flo_divmod(x, y) VALUE x, y; { - double fy; - VALUE div, mod; + double fy, div, mod; switch (TYPE(y)) { case T_FIXNUM: @@ -1508,6 +1507,7 @@ Init_Numeric() rb_define_method(rb_cNumeric, "===", num_equal, 1); rb_define_method(rb_cNumeric, "eql?", num_eql, 1); rb_define_method(rb_cNumeric, "divmod", num_divmod, 1); + rb_define_method(rb_cNumeric, "remainder", num_remainder, 1); rb_define_method(rb_cNumeric, "abs", num_abs, 0); rb_define_method(rb_cNumeric, "integer?", num_int_p, 0); diff --git a/parse.y b/parse.y index da36f28d72..460e05508f 100644 --- a/parse.y +++ b/parse.y @@ -2627,8 +2627,11 @@ here_document(term, indent) p++; } } - if (strncmp(eos, p, len) == 0 && (p[len] == '\n' || p[len] == '\r')) { - break; + if (strncmp(eos, p, len) == 0) { + if (p[len] == '\n' || p[len] == '\r') + break; + if (len == RSTRING(line)->len) + break; } lex_pbeg = lex_p = RSTRING(line)->ptr; diff --git a/random.c b/random.c index 65fc69ed32..32cb525a32 100644 --- a/random.c +++ b/random.c @@ -130,11 +130,15 @@ rb_f_srand(argc, argv, obj) } static VALUE -rb_f_rand(obj, vmax) - VALUE obj, vmax; +rb_f_rand(argc, argv, obj) + int argc; + VALUE *argv; + VALUE obj; { + VALUE vmax; long val, max; + rb_scan_args(argc, argv, "01", &vmax); if (first) { struct timeval tv; @@ -148,9 +152,14 @@ rb_f_rand(obj, vmax) /* fall through */ case T_BIGNUM: return rb_big_rand(vmax, RANDOM_NUMBER); + case T_NIL: + max = 0; + break; + default: + max = NUM2LONG(vmax); + break; } - max = NUM2LONG(vmax); if (max == 0) { return rb_float_new(RANDOM_NUMBER); } @@ -164,5 +173,5 @@ void Init_Random() { rb_define_global_function("srand", rb_f_srand, -1); - rb_define_global_function("rand", rb_f_rand, 1); + rb_define_global_function("rand", rb_f_rand, -1); } diff --git a/ruby.h b/ruby.h index 8751cc1a70..30c9ef8484 100644 --- a/ruby.h +++ b/ruby.h @@ -467,6 +467,7 @@ VALUE rb_yield _((VALUE)); int rb_block_given_p _((void)); VALUE rb_iterate _((VALUE(*)(),VALUE,VALUE(*)(),VALUE)); VALUE rb_rescue _((VALUE(*)(),VALUE,VALUE(*)(),VALUE)); +VALUE rb_rescue2 _((VALUE(*)(),VALUE,VALUE,VALUE(*)(),VALUE)); VALUE rb_ensure _((VALUE(*)(),VALUE,VALUE(*)(),VALUE)); VALUE rb_catch _((const char*,VALUE(*)(),VALUE)); void rb_throw _((const char*,VALUE)) NORETURN; diff --git a/sample/test.rb b/sample/test.rb index 9da67f5722..91355969c9 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -609,14 +609,10 @@ ok($good) b = 10**80 a = b * 9 + 7 -ok(7 == a % b) -ok(7-b == a % (-b)) -ok(b-7 == (-a) % b) -ok(-7 ==(-a) % (-b)) -ok(7 ==a.remainder(b)) -ok(7 ==a.remainder(-b)) -ok(-7 == (-a).remainder(b)) -ok(-7 == (-a).remainder(-b)) +ok(7 ==a % b) +ok(7 ==a % -b) +ok(-7 == (-a) % b) +ok(-7 == (-a) % (-b)) check "string & char" diff --git a/util.c b/util.c index 7d912999b2..63410a1668 100644 --- a/util.c +++ b/util.c @@ -40,6 +40,7 @@ rb_type(obj) if (obj == Qnil) return T_NIL; if (obj == Qfalse) return T_FALSE; if (obj == Qtrue) return T_TRUE; + if (obj == Qundef) return T_UNDEF; if (SYMBOL_P(obj)) return T_SYMBOL; return BUILTIN_TYPE(obj); diff --git a/win32/ruby.def b/win32/ruby.def index e127d74924..8f5977c53b 100644 --- a/win32/ruby.def +++ b/win32/ruby.def @@ -296,6 +296,7 @@ EXPORTS rb_yield rb_iterate rb_rescue + rb_rescue2 rb_protect rb_ensure rb_with_disable_interrupt -- cgit v1.2.3