1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]

* eval.c (rb_exec_end_proc): reduce rb_protect().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-07-22 08:42:47 +00:00
parent 27daa53c54
commit 0d1df1cd7d
7 changed files with 93 additions and 54 deletions

View file

@ -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> Tue Jul 22 17:15:57 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* MANIFEST (lib/cgi/session/pstore.rb, lib/yaml/baseemitter.rb): * 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> 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 * string.c (rb_string_value_cstr): check null byte in the string
before retrieving C ptr. accessed via macro StringValueCStr. 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 * file.c (sys_fail2): raise error for two operand system calls
such as rename, link, symlink. (ruby-bugs PR#1047) such as rename, link, symlink. (ruby-bugs PR#1047)

64
eval.c
View file

@ -1319,20 +1319,30 @@ ruby_options(argc, argv)
void rb_exec_end_proc _((void)); void rb_exec_end_proc _((void));
static void
ruby_finalize_0(exp)
int *exp;
{
ruby_errinfo = 0;
PUSH_TAG(PROT_NONE);
if (EXEC_TAG() == 0) {
rb_trap_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 void
ruby_finalize() ruby_finalize()
{ {
int state; ruby_finalize_0(0);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
rb_trap_exit();
rb_exec_end_proc();
rb_gc_call_finalizer_at_exit();
}
POP_TAG();
trace_func = 0;
tracing = 0;
} }
int int
@ -1355,7 +1365,7 @@ ruby_cleanup(ex)
ex = error_handle(ex); ex = error_handle(ex);
POP_TAG(); POP_TAG();
ruby_finalize(); ruby_finalize_0(&ex);
return ex; return ex;
} }
@ -4712,7 +4722,7 @@ rb_f_missing(argc, argv, obj)
} }
static VALUE static VALUE
rb_undefined(obj, id, argc, argv, call_status) method_missing(obj, id, argc, argv, call_status)
VALUE obj; VALUE obj;
ID id; ID id;
int argc; int argc;
@ -5077,7 +5087,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
ent = cache + EXPR1(klass, mid); ent = cache + EXPR1(klass, mid);
if (ent->mid == mid && ent->klass == klass) { if (ent->mid == mid && ent->klass == klass) {
if (!ent->method) 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; klass = ent->origin;
id = ent->mid0; id = ent->mid0;
noex = ent->noex; 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) { else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
if (scope == 3) { 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) { if (mid != missing) {
/* receiver specified form for private method */ /* receiver specified form for private method */
if ((noex & NOEX_PRIVATE) && scope == 0) 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 */ /* self must be kind of a specified form for protected method */
if ((noex & NOEX_PROTECTED)) { if ((noex & NOEX_PROTECTED)) {
@ -5103,7 +5113,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
defined_class = RBASIC(defined_class)->klass; defined_class = RBASIC(defined_class)->klass;
} }
if (!rb_obj_is_kind_of(ruby_frame->self, rb_class_real(defined_class))) 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; save = link = end_procs;
while (link) { 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) { if (status) {
error_handle(status); error_handle(status);
} }
@ -6451,7 +6465,11 @@ rb_exec_end_proc()
} }
link = end_procs; link = end_procs;
while (link != save) { 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) { if (status) {
error_handle(status); error_handle(status);
} }
@ -6460,7 +6478,11 @@ rb_exec_end_proc()
while (ephemeral_end_procs) { while (ephemeral_end_procs) {
link = ephemeral_end_procs; link = ephemeral_end_procs;
ephemeral_end_procs = link->next; 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) { if (status) {
error_handle(status); error_handle(status);
} }

View file

@ -461,8 +461,8 @@ VALUE rb_const_get _((VALUE, ID));
VALUE rb_const_get_at _((VALUE, ID)); VALUE rb_const_get_at _((VALUE, ID));
VALUE rb_const_get_from _((VALUE, ID)); VALUE rb_const_get_from _((VALUE, ID));
void rb_const_set _((VALUE, ID, VALUE)); void rb_const_set _((VALUE, ID, VALUE));
void rb_const_assign _((VALUE, ID, VALUE));
VALUE rb_mod_constants _((VALUE)); VALUE rb_mod_constants _((VALUE));
VALUE rb_mod_const_missing _((VALUE,VALUE));
VALUE rb_cvar_defined _((VALUE, ID)); VALUE rb_cvar_defined _((VALUE, ID));
#define RB_CVAR_SET_4ARGS 1 #define RB_CVAR_SET_4ARGS 1
void rb_cvar_set _((VALUE, ID, VALUE, int)); void rb_cvar_set _((VALUE, ID, VALUE, int));

View file

@ -184,7 +184,7 @@ class Complex < Numeric
Complex.polar(r.power!(other), theta * other) Complex.polar(r.power!(other), theta * other)
else else
x, y = other.coerce(self) x, y = other.coerce(self)
x/y x**y
end end
end end
@ -222,7 +222,7 @@ class Complex < Numeric
# plane. # plane.
# #
def abs def abs
Math.sqrt!((@real*@real + @image*@image).to_f) Math.hypot(@real, @image)
end end
# #
@ -352,6 +352,7 @@ class Complex < Numeric
# The imaginary part of a complex number. # The imaginary part of a complex number.
attr :image attr :image
alias imag image
end end
@ -382,6 +383,7 @@ class Numeric
def image def image
0 0
end end
alias imag image
# #
# See Complex#arg. # See Complex#arg.
@ -390,7 +392,7 @@ class Numeric
if self >= 0 if self >= 0
return 0 return 0
else else
return Math.atan2(1,1)*4 return Math::PI
end end
end end
@ -458,10 +460,12 @@ module Math
Complex(0,sqrt!(-z)) Complex(0,sqrt!(-z))
end end
else else
if defined? Rational if z.image < 0
z**Rational(1,2) sqrt(z.conjugate).conjugate
else else
z**0.5 r = z.abs
x = z.real
Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) )
end end
end end
end end

View file

@ -16,7 +16,7 @@ class Dir
if $SAFE > 0 if $SAFE > 0
TMPDIR = '/tmp' TMPDIR = '/tmp'
else else
TMPDIR = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp' TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
end end
end end
end end

View file

@ -1517,6 +1517,7 @@ Init_Object()
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2); 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_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_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_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1); rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);

View file

@ -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 * static struct st_table *
check_autoload_table(av) check_autoload_table(av)
VALUE av; VALUE av;
@ -1268,8 +1284,7 @@ rb_const_get_at(klass, id)
} }
return value; return value;
} }
uninitialized_constant(klass, id); return const_missing(klass, id);
return Qnil; /* not reached */
} }
static VALUE static VALUE
@ -1303,8 +1318,7 @@ rb_const_get_0(klass, id, exclude)
goto retry; goto retry;
} }
uninitialized_constant(klass, id); return const_missing(klass, id);
return Qnil; /* not reached */
} }
VALUE VALUE
@ -1526,25 +1540,6 @@ rb_const_set(klass, id, val)
mod_av_set(klass, id, val, Qtrue); mod_av_set(klass, id, val, Qtrue);
} }
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 void
rb_define_const(klass, name, val) rb_define_const(klass, name, val)
VALUE klass; VALUE klass;