diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | eval.c | 56 | ||||
-rw-r--r-- | intern.h | 2 | ||||
-rw-r--r-- | lib/complex.rb | 16 | ||||
-rw-r--r-- | lib/tmpdir.rb | 2 | ||||
-rw-r--r-- | object.c | 1 | ||||
-rw-r--r-- | variable.c | 41 |
7 files changed, 89 insertions, 50 deletions
@@ -1,3 +1,20 @@ +Tue Jul 22 17:22:34 2003 Yukihiro Matsumoto <matz@ruby-lang.org> + + * variable.c (rb_mod_const_missing): new method. [ruby-core:00441] + + * variable.c (rb_const_get_at): allow "const_missing" hook. + + * variable.c (rb_const_get_0): ditto. + + * eval.c (method_missing): rename from rb_undefined to clarify. + + * eval.c (ruby_finalize_0): update exit status if any of END proc + raises SystemExit. [ruby-core:01256] + + * signal.c (rb_trap_exit): wrap rb_eval_cmd + + * eval.c (rb_exec_end_proc): reduce rb_protect(). + Tue Jul 22 17:15:57 2003 WATANABE Hirofumi <eban@ruby-lang.org> * MANIFEST (lib/cgi/session/pstore.rb, lib/yaml/baseemitter.rb): @@ -25,11 +42,11 @@ Tue Jul 22 00:19:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Jul 21 01:53:43 2003 Yukihiro Matsumoto <matz@ruby-lang.org> - * string.c: use StringValueCStr to retrieve paths to system calls. - * string.c (rb_string_value_cstr): check null byte in the string before retrieving C ptr. accessed via macro StringValueCStr. + * file.c: use StringValueCStr to retrieve paths to system calls. + * file.c (sys_fail2): raise error for two operand system calls such as rename, link, symlink. (ruby-bugs PR#1047) @@ -1319,22 +1319,32 @@ ruby_options(argc, argv) void rb_exec_end_proc _((void)); -void -ruby_finalize() +static void +ruby_finalize_0(exp) + int *exp; { - int state; - + ruby_errinfo = 0; PUSH_TAG(PROT_NONE); - if ((state = EXEC_TAG()) == 0) { + if (EXEC_TAG() == 0) { rb_trap_exit(); - rb_exec_end_proc(); - rb_gc_call_finalizer_at_exit(); } POP_TAG(); + rb_exec_end_proc(); + rb_gc_call_finalizer_at_exit(); + if (exp && ruby_errinfo && rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) { + VALUE st = rb_iv_get(ruby_errinfo, "status"); + *exp = NUM2INT(st); + } trace_func = 0; tracing = 0; } +void +ruby_finalize() +{ + ruby_finalize_0(0); +} + int ruby_cleanup(ex) int ex; @@ -1355,7 +1365,7 @@ ruby_cleanup(ex) ex = error_handle(ex); POP_TAG(); - ruby_finalize(); + ruby_finalize_0(&ex); return ex; } @@ -4712,7 +4722,7 @@ rb_f_missing(argc, argv, obj) } static VALUE -rb_undefined(obj, id, argc, argv, call_status) +method_missing(obj, id, argc, argv, call_status) VALUE obj; ID id; int argc; @@ -5077,7 +5087,7 @@ rb_call(klass, recv, mid, argc, argv, scope) ent = cache + EXPR1(klass, mid); if (ent->mid == mid && ent->klass == klass) { if (!ent->method) - return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0); + return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0); klass = ent->origin; id = ent->mid0; noex = ent->noex; @@ -5085,15 +5095,15 @@ rb_call(klass, recv, mid, argc, argv, scope) } else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) { if (scope == 3) { - return rb_undefined(recv, mid, argc, argv, CSTAT_SUPER); + return method_missing(recv, mid, argc, argv, CSTAT_SUPER); } - return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0); + return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0); } if (mid != missing) { /* receiver specified form for private method */ if ((noex & NOEX_PRIVATE) && scope == 0) - return rb_undefined(recv, mid, argc, argv, CSTAT_PRIV); + return method_missing(recv, mid, argc, argv, CSTAT_PRIV); /* self must be kind of a specified form for protected method */ if ((noex & NOEX_PROTECTED)) { @@ -5103,7 +5113,7 @@ rb_call(klass, recv, mid, argc, argv, scope) defined_class = RBASIC(defined_class)->klass; } if (!rb_obj_is_kind_of(ruby_frame->self, rb_class_real(defined_class))) - return rb_undefined(recv, mid, argc, argv, CSTAT_PROT); + return method_missing(recv, mid, argc, argv, CSTAT_PROT); } } @@ -6443,7 +6453,11 @@ rb_exec_end_proc() save = link = end_procs; while (link) { - rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status); + PUSH_TAG(PROT_NONE); + if ((status = EXEC_TAG()) == 0) { + (*link->func)(link->data); + } + POP_TAG(); if (status) { error_handle(status); } @@ -6451,7 +6465,11 @@ rb_exec_end_proc() } link = end_procs; while (link != save) { - rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status); + PUSH_TAG(PROT_NONE); + if ((status = EXEC_TAG()) == 0) { + (*link->func)(link->data); + } + POP_TAG(); if (status) { error_handle(status); } @@ -6460,7 +6478,11 @@ rb_exec_end_proc() while (ephemeral_end_procs) { link = ephemeral_end_procs; ephemeral_end_procs = link->next; - rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status); + PUSH_TAG(PROT_NONE); + if ((status = EXEC_TAG()) == 0) { + (*link->func)(link->data); + } + POP_TAG(); if (status) { error_handle(status); } @@ -461,8 +461,8 @@ VALUE rb_const_get _((VALUE, ID)); VALUE rb_const_get_at _((VALUE, ID)); VALUE rb_const_get_from _((VALUE, ID)); void rb_const_set _((VALUE, ID, VALUE)); -void rb_const_assign _((VALUE, ID, VALUE)); VALUE rb_mod_constants _((VALUE)); +VALUE rb_mod_const_missing _((VALUE,VALUE)); VALUE rb_cvar_defined _((VALUE, ID)); #define RB_CVAR_SET_4ARGS 1 void rb_cvar_set _((VALUE, ID, VALUE, int)); diff --git a/lib/complex.rb b/lib/complex.rb index 53d0f5e0bb..2ee7274a1c 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -184,7 +184,7 @@ class Complex < Numeric Complex.polar(r.power!(other), theta * other) else x, y = other.coerce(self) - x/y + x**y end end @@ -222,7 +222,7 @@ class Complex < Numeric # plane. # def abs - Math.sqrt!((@real*@real + @image*@image).to_f) + Math.hypot(@real, @image) end # @@ -352,6 +352,7 @@ class Complex < Numeric # The imaginary part of a complex number. attr :image + alias imag image end @@ -382,6 +383,7 @@ class Numeric def image 0 end + alias imag image # # See Complex#arg. @@ -390,7 +392,7 @@ class Numeric if self >= 0 return 0 else - return Math.atan2(1,1)*4 + return Math::PI end end @@ -458,10 +460,12 @@ module Math Complex(0,sqrt!(-z)) end else - if defined? Rational - z**Rational(1,2) + if z.image < 0 + sqrt(z.conjugate).conjugate else - z**0.5 + r = z.abs + x = z.real + Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) ) end end end diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 8a21cdc789..6fde398ed4 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -16,7 +16,7 @@ class Dir if $SAFE > 0 TMPDIR = '/tmp' else - TMPDIR = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp' + TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp') end end end @@ -1517,6 +1517,7 @@ Init_Object() rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2); rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1); rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1); + rb_define_method(rb_cModule, "const_missing", rb_mod_const_missing, 1); rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0); rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1); diff --git a/variable.c b/variable.c index 6aa98035f1..77c1c37240 100644 --- a/variable.c +++ b/variable.c @@ -1116,6 +1116,22 @@ uninitialized_constant(klass, id) } } +static VALUE +const_missing(klass, id) + VALUE klass; + ID id; +{ + return rb_funcall(klass, rb_intern("const_missing"), 1, ID2SYM(id)); +} + +VALUE +rb_mod_const_missing(klass, name) + VALUE klass, name; +{ + uninitialized_constant(klass, rb_to_id(name)); + return Qnil; /* not reached */ +} + static struct st_table * check_autoload_table(av) VALUE av; @@ -1268,8 +1284,7 @@ rb_const_get_at(klass, id) } return value; } - uninitialized_constant(klass, id); - return Qnil; /* not reached */ + return const_missing(klass, id); } static VALUE @@ -1303,8 +1318,7 @@ rb_const_get_0(klass, id, exclude) goto retry; } - uninitialized_constant(klass, id); - return Qnil; /* not reached */ + return const_missing(klass, id); } VALUE @@ -1527,25 +1541,6 @@ rb_const_set(klass, id, val) } void -rb_const_assign(klass, id, val) - VALUE klass; - ID id; - VALUE val; -{ - VALUE tmp = klass; - - while (tmp) { - if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) { - st_insert(RCLASS(tmp)->iv_tbl, id, val); - return; - } - tmp = RCLASS(tmp)->super; - } - - uninitialized_constant(klass, id); -} - -void rb_define_const(klass, name, val) VALUE klass; const char *name; |