Skip to content

Commit 0d1df1c

Browse files
author
matz
committed
* 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
1 parent 27daa53 commit 0d1df1c

File tree

7 files changed

+89
-50
lines changed

7 files changed

+89
-50
lines changed

ChangeLog

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Tue Jul 22 17:22:34 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* variable.c (rb_mod_const_missing): new method. [ruby-core:00441]
4+
5+
* variable.c (rb_const_get_at): allow "const_missing" hook.
6+
7+
* variable.c (rb_const_get_0): ditto.
8+
9+
* eval.c (method_missing): rename from rb_undefined to clarify.
10+
11+
* eval.c (ruby_finalize_0): update exit status if any of END proc
12+
raises SystemExit. [ruby-core:01256]
13+
14+
* signal.c (rb_trap_exit): wrap rb_eval_cmd
15+
16+
* eval.c (rb_exec_end_proc): reduce rb_protect().
17+
118
Tue Jul 22 17:15:57 2003 WATANABE Hirofumi <eban@ruby-lang.org>
219

320
* 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>
2542

2643
Mon Jul 21 01:53:43 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
2744

28-
* string.c: use StringValueCStr to retrieve paths to system calls.
29-
3045
* string.c (rb_string_value_cstr): check null byte in the string
3146
before retrieving C ptr. accessed via macro StringValueCStr.
3247

48+
* file.c: use StringValueCStr to retrieve paths to system calls.
49+
3350
* file.c (sys_fail2): raise error for two operand system calls
3451
such as rename, link, symlink. (ruby-bugs PR#1047)
3552

eval.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,22 +1319,32 @@ ruby_options(argc, argv)
13191319

13201320
void rb_exec_end_proc _((void));
13211321

1322-
void
1323-
ruby_finalize()
1322+
static void
1323+
ruby_finalize_0(exp)
1324+
int *exp;
13241325
{
1325-
int state;
1326-
1326+
ruby_errinfo = 0;
13271327
PUSH_TAG(PROT_NONE);
1328-
if ((state = EXEC_TAG()) == 0) {
1328+
if (EXEC_TAG() == 0) {
13291329
rb_trap_exit();
1330-
rb_exec_end_proc();
1331-
rb_gc_call_finalizer_at_exit();
13321330
}
13331331
POP_TAG();
1332+
rb_exec_end_proc();
1333+
rb_gc_call_finalizer_at_exit();
1334+
if (exp && ruby_errinfo && rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
1335+
VALUE st = rb_iv_get(ruby_errinfo, "status");
1336+
*exp = NUM2INT(st);
1337+
}
13341338
trace_func = 0;
13351339
tracing = 0;
13361340
}
13371341

1342+
void
1343+
ruby_finalize()
1344+
{
1345+
ruby_finalize_0(0);
1346+
}
1347+
13381348
int
13391349
ruby_cleanup(ex)
13401350
int ex;
@@ -1355,7 +1365,7 @@ ruby_cleanup(ex)
13551365

13561366
ex = error_handle(ex);
13571367
POP_TAG();
1358-
ruby_finalize();
1368+
ruby_finalize_0(&ex);
13591369
return ex;
13601370
}
13611371

@@ -4712,7 +4722,7 @@ rb_f_missing(argc, argv, obj)
47124722
}
47134723

47144724
static VALUE
4715-
rb_undefined(obj, id, argc, argv, call_status)
4725+
method_missing(obj, id, argc, argv, call_status)
47164726
VALUE obj;
47174727
ID id;
47184728
int argc;
@@ -5077,23 +5087,23 @@ rb_call(klass, recv, mid, argc, argv, scope)
50775087
ent = cache + EXPR1(klass, mid);
50785088
if (ent->mid == mid && ent->klass == klass) {
50795089
if (!ent->method)
5080-
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
5090+
return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
50815091
klass = ent->origin;
50825092
id = ent->mid0;
50835093
noex = ent->noex;
50845094
body = ent->method;
50855095
}
50865096
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
50875097
if (scope == 3) {
5088-
return rb_undefined(recv, mid, argc, argv, CSTAT_SUPER);
5098+
return method_missing(recv, mid, argc, argv, CSTAT_SUPER);
50895099
}
5090-
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
5100+
return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
50915101
}
50925102

50935103
if (mid != missing) {
50945104
/* receiver specified form for private method */
50955105
if ((noex & NOEX_PRIVATE) && scope == 0)
5096-
return rb_undefined(recv, mid, argc, argv, CSTAT_PRIV);
5106+
return method_missing(recv, mid, argc, argv, CSTAT_PRIV);
50975107

50985108
/* self must be kind of a specified form for protected method */
50995109
if ((noex & NOEX_PROTECTED)) {
@@ -5103,7 +5113,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
51035113
defined_class = RBASIC(defined_class)->klass;
51045114
}
51055115
if (!rb_obj_is_kind_of(ruby_frame->self, rb_class_real(defined_class)))
5106-
return rb_undefined(recv, mid, argc, argv, CSTAT_PROT);
5116+
return method_missing(recv, mid, argc, argv, CSTAT_PROT);
51075117
}
51085118
}
51095119

@@ -6443,15 +6453,23 @@ rb_exec_end_proc()
64436453

64446454
save = link = end_procs;
64456455
while (link) {
6446-
rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status);
6456+
PUSH_TAG(PROT_NONE);
6457+
if ((status = EXEC_TAG()) == 0) {
6458+
(*link->func)(link->data);
6459+
}
6460+
POP_TAG();
64476461
if (status) {
64486462
error_handle(status);
64496463
}
64506464
link = link->next;
64516465
}
64526466
link = end_procs;
64536467
while (link != save) {
6454-
rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status);
6468+
PUSH_TAG(PROT_NONE);
6469+
if ((status = EXEC_TAG()) == 0) {
6470+
(*link->func)(link->data);
6471+
}
6472+
POP_TAG();
64556473
if (status) {
64566474
error_handle(status);
64576475
}
@@ -6460,7 +6478,11 @@ rb_exec_end_proc()
64606478
while (ephemeral_end_procs) {
64616479
link = ephemeral_end_procs;
64626480
ephemeral_end_procs = link->next;
6463-
rb_protect((VALUE(*)_((VALUE)))link->func, link->data, &status);
6481+
PUSH_TAG(PROT_NONE);
6482+
if ((status = EXEC_TAG()) == 0) {
6483+
(*link->func)(link->data);
6484+
}
6485+
POP_TAG();
64646486
if (status) {
64656487
error_handle(status);
64666488
}

intern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ VALUE rb_const_get _((VALUE, ID));
461461
VALUE rb_const_get_at _((VALUE, ID));
462462
VALUE rb_const_get_from _((VALUE, ID));
463463
void rb_const_set _((VALUE, ID, VALUE));
464-
void rb_const_assign _((VALUE, ID, VALUE));
465464
VALUE rb_mod_constants _((VALUE));
465+
VALUE rb_mod_const_missing _((VALUE,VALUE));
466466
VALUE rb_cvar_defined _((VALUE, ID));
467467
#define RB_CVAR_SET_4ARGS 1
468468
void rb_cvar_set _((VALUE, ID, VALUE, int));

lib/complex.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def ** (other)
184184
Complex.polar(r.power!(other), theta * other)
185185
else
186186
x, y = other.coerce(self)
187-
x/y
187+
x**y
188188
end
189189
end
190190

@@ -222,7 +222,7 @@ def % (other)
222222
# plane.
223223
#
224224
def abs
225-
Math.sqrt!((@real*@real + @image*@image).to_f)
225+
Math.hypot(@real, @image)
226226
end
227227

228228
#
@@ -352,6 +352,7 @@ def inspect
352352

353353
# The imaginary part of a complex number.
354354
attr :image
355+
alias imag image
355356

356357
end
357358

@@ -382,6 +383,7 @@ def real
382383
def image
383384
0
384385
end
386+
alias imag image
385387

386388
#
387389
# See Complex#arg.
@@ -390,7 +392,7 @@ def arg
390392
if self >= 0
391393
return 0
392394
else
393-
return Math.atan2(1,1)*4
395+
return Math::PI
394396
end
395397
end
396398

@@ -458,10 +460,12 @@ def sqrt(z)
458460
Complex(0,sqrt!(-z))
459461
end
460462
else
461-
if defined? Rational
462-
z**Rational(1,2)
463+
if z.image < 0
464+
sqrt(z.conjugate).conjugate
463465
else
464-
z**0.5
466+
r = z.abs
467+
x = z.real
468+
Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) )
465469
end
466470
end
467471
end

lib/tmpdir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Dir
1616
if $SAFE > 0
1717
TMPDIR = '/tmp'
1818
else
19-
TMPDIR = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp'
19+
TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
2020
end
2121
end
2222
end

object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ Init_Object()
15171517
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
15181518
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1);
15191519
rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1);
1520+
rb_define_method(rb_cModule, "const_missing", rb_mod_const_missing, 1);
15201521
rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
15211522
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);
15221523

variable.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,22 @@ uninitialized_constant(klass, id)
11161116
}
11171117
}
11181118

1119+
static VALUE
1120+
const_missing(klass, id)
1121+
VALUE klass;
1122+
ID id;
1123+
{
1124+
return rb_funcall(klass, rb_intern("const_missing"), 1, ID2SYM(id));
1125+
}
1126+
1127+
VALUE
1128+
rb_mod_const_missing(klass, name)
1129+
VALUE klass, name;
1130+
{
1131+
uninitialized_constant(klass, rb_to_id(name));
1132+
return Qnil; /* not reached */
1133+
}
1134+
11191135
static struct st_table *
11201136
check_autoload_table(av)
11211137
VALUE av;
@@ -1268,8 +1284,7 @@ rb_const_get_at(klass, id)
12681284
}
12691285
return value;
12701286
}
1271-
uninitialized_constant(klass, id);
1272-
return Qnil; /* not reached */
1287+
return const_missing(klass, id);
12731288
}
12741289

12751290
static VALUE
@@ -1303,8 +1318,7 @@ rb_const_get_0(klass, id, exclude)
13031318
goto retry;
13041319
}
13051320

1306-
uninitialized_constant(klass, id);
1307-
return Qnil; /* not reached */
1321+
return const_missing(klass, id);
13081322
}
13091323

13101324
VALUE
@@ -1526,25 +1540,6 @@ rb_const_set(klass, id, val)
15261540
mod_av_set(klass, id, val, Qtrue);
15271541
}
15281542

1529-
void
1530-
rb_const_assign(klass, id, val)
1531-
VALUE klass;
1532-
ID id;
1533-
VALUE val;
1534-
{
1535-
VALUE tmp = klass;
1536-
1537-
while (tmp) {
1538-
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
1539-
st_insert(RCLASS(tmp)->iv_tbl, id, val);
1540-
return;
1541-
}
1542-
tmp = RCLASS(tmp)->super;
1543-
}
1544-
1545-
uninitialized_constant(klass, id);
1546-
}
1547-
15481543
void
15491544
rb_define_const(klass, name, val)
15501545
VALUE klass;

0 commit comments

Comments
 (0)