mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (ev_const_get): simplified using rb_const_get_fallback().
* eval.c (ev_const_defined): adopt to ev_const_get() using rb_const_defined_fallback(). * variable.c (rb_const_get_fallback): new function to implement constant search. * variable.c (rb_const_defined_fallback): new function to implement constant definition check. * variable.c (rb_const_get_0): adopt to new behavior. constants are looked up in the order of: current class, super classes (but Object), lexically external classes/modules, and Object. * variable.c (rb_const_defined_0): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d0a3c64fb4
commit
ccf99b9ce6
6 changed files with 84 additions and 69 deletions
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
||||||
|
Fri Feb 17 17:30:20 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (ev_const_get): simplified using rb_const_get_fallback().
|
||||||
|
|
||||||
|
* eval.c (ev_const_defined): adopt to ev_const_get() using
|
||||||
|
rb_const_defined_fallback().
|
||||||
|
|
||||||
|
* variable.c (rb_const_get_fallback): new function to implement
|
||||||
|
constant search.
|
||||||
|
|
||||||
|
* variable.c (rb_const_defined_fallback): new function to
|
||||||
|
implement constant definition check.
|
||||||
|
|
||||||
|
* variable.c (rb_const_get_0): adopt to new behavior. constants
|
||||||
|
are looked up in the order of: current class, super classes (but
|
||||||
|
Object), lexically external classes/modules, and Object.
|
||||||
|
|
||||||
|
* variable.c (rb_const_defined_0): ditto.
|
||||||
|
|
||||||
Fri Feb 17 11:20:53 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Fri Feb 17 11:20:53 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* util.c (ruby_strtod): Float("1e") should fail. [ruby-core:7330]
|
* util.c (ruby_strtod): Float("1e") should fail. [ruby-core:7330]
|
||||||
|
|
36
eval.c
36
eval.c
|
@ -1776,45 +1776,13 @@ ruby_current_class_object()
|
||||||
static VALUE
|
static VALUE
|
||||||
ev_const_defined(ID id, VALUE self)
|
ev_const_defined(ID id, VALUE self)
|
||||||
{
|
{
|
||||||
NODE *cbase = ruby_cref;
|
return rb_const_defined_fallback(ruby_cbase, id, ruby_cref->nd_next);
|
||||||
VALUE result;
|
|
||||||
|
|
||||||
while (cbase && cbase->nd_next) {
|
|
||||||
struct RClass *klass = RCLASS(cbase->nd_clss);
|
|
||||||
|
|
||||||
if (NIL_P(klass)) return rb_const_defined(CLASS_OF(self), id);
|
|
||||||
if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, &result)) {
|
|
||||||
if (result == Qundef && NIL_P(rb_autoload_p((VALUE)klass, id))) {
|
|
||||||
return Qfalse;
|
|
||||||
}
|
|
||||||
return Qtrue;
|
|
||||||
}
|
|
||||||
cbase = cbase->nd_next;
|
|
||||||
}
|
|
||||||
return rb_const_defined(ruby_cbase, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ev_const_get(ID id, VALUE self)
|
ev_const_get(ID id, VALUE self)
|
||||||
{
|
{
|
||||||
NODE *cbase = ruby_cref;
|
return rb_const_get_fallback(ruby_cbase, id, ruby_cref->nd_next);
|
||||||
VALUE result;
|
|
||||||
|
|
||||||
while (cbase && cbase->nd_next) {
|
|
||||||
VALUE klass = cbase->nd_clss;
|
|
||||||
|
|
||||||
if (NIL_P(klass)) return rb_const_get(CLASS_OF(self), id);
|
|
||||||
while (RCLASS(klass)->iv_tbl &&
|
|
||||||
st_lookup(RCLASS(klass)->iv_tbl, id, &result)) {
|
|
||||||
if (result == Qundef) {
|
|
||||||
if (!RTEST(rb_autoload_load(klass, id))) break;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
cbase = cbase->nd_next;
|
|
||||||
}
|
|
||||||
return rb_const_get(ruby_cbase, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
2
intern.h
2
intern.h
|
@ -557,9 +557,11 @@ VALUE rb_mod_remove_const(VALUE, VALUE);
|
||||||
int rb_const_defined(VALUE, ID);
|
int rb_const_defined(VALUE, ID);
|
||||||
int rb_const_defined_at(VALUE, ID);
|
int rb_const_defined_at(VALUE, ID);
|
||||||
int rb_const_defined_from(VALUE, ID);
|
int rb_const_defined_from(VALUE, ID);
|
||||||
|
int rb_const_defined_fallback(VALUE, ID, struct RNode *);
|
||||||
VALUE rb_const_get(VALUE, ID);
|
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);
|
||||||
|
VALUE rb_const_get_fallback(VALUE, ID, struct RNode *);
|
||||||
void rb_const_set(VALUE, ID, VALUE);
|
void rb_const_set(VALUE, ID, VALUE);
|
||||||
VALUE rb_mod_constants(VALUE);
|
VALUE rb_mod_constants(VALUE);
|
||||||
VALUE rb_mod_const_missing(VALUE,VALUE);
|
VALUE rb_mod_const_missing(VALUE,VALUE);
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Test
|
||||||
module Unit
|
module Unit
|
||||||
module Collector
|
module Collector
|
||||||
class ObjectSpace
|
class ObjectSpace
|
||||||
include Collector
|
include Test::Unit::Collector
|
||||||
|
|
||||||
NAME = 'collected from the ObjectSpace'
|
NAME = 'collected from the ObjectSpace'
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ require 'digest'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
include Digest
|
|
||||||
|
|
||||||
module TestDigest
|
module TestDigest
|
||||||
Data1 = "abc"
|
Data1 = "abc"
|
||||||
|
@ -66,55 +65,55 @@ module TestDigest
|
||||||
|
|
||||||
class TestMD5 < Test::Unit::TestCase
|
class TestMD5 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = MD5
|
ALGO = Digest::MD5
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "900150983cd24fb0d6963f7d28e17f72",
|
Data1 => "900150983cd24fb0d6963f7d28e17f72",
|
||||||
Data2 => "8215ef0796a20bcaaae116d3876c664a",
|
Data2 => "8215ef0796a20bcaaae116d3876c664a",
|
||||||
}
|
}
|
||||||
end if defined?(MD5)
|
end if defined?(Digest::MD5)
|
||||||
|
|
||||||
class TestSHA1 < Test::Unit::TestCase
|
class TestSHA1 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = SHA1
|
ALGO = Digest::SHA1
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "a9993e364706816aba3e25717850c26c9cd0d89d",
|
Data1 => "a9993e364706816aba3e25717850c26c9cd0d89d",
|
||||||
Data2 => "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
Data2 => "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||||
}
|
}
|
||||||
end if defined?(SHA1)
|
end if defined?(Digest::SHA1)
|
||||||
|
|
||||||
class TestSHA256 < Test::Unit::TestCase
|
class TestSHA256 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = SHA256
|
ALGO = Digest::SHA256
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
Data1 => "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
||||||
Data2 => "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
|
Data2 => "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
|
||||||
}
|
}
|
||||||
end if defined?(SHA256)
|
end if defined?(Digest::SHA256)
|
||||||
|
|
||||||
class TestSHA384 < Test::Unit::TestCase
|
class TestSHA384 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = SHA384
|
ALGO = Digest::SHA384
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
|
Data1 => "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
|
||||||
Data2 => "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b",
|
Data2 => "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b",
|
||||||
}
|
}
|
||||||
end if defined?(SHA384)
|
end if defined?(Digest::SHA384)
|
||||||
|
|
||||||
class TestSHA512 < Test::Unit::TestCase
|
class TestSHA512 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = SHA512
|
ALGO = Digest::SHA512
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
|
Data1 => "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
|
||||||
Data2 => "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445",
|
Data2 => "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445",
|
||||||
}
|
}
|
||||||
end if defined?(SHA512)
|
end if defined?(Digest::SHA512)
|
||||||
|
|
||||||
class TestRMD160 < Test::Unit::TestCase
|
class TestRMD160 < Test::Unit::TestCase
|
||||||
include TestDigest
|
include TestDigest
|
||||||
ALGO = RMD160
|
ALGO = Digest::RMD160
|
||||||
DATA = {
|
DATA = {
|
||||||
Data1 => "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
|
Data1 => "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
|
||||||
Data2 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
|
Data2 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
|
||||||
}
|
}
|
||||||
end if defined?(RMD160)
|
end if defined?(Digest::RMD160)
|
||||||
end
|
end
|
||||||
|
|
69
variable.c
69
variable.c
|
@ -1275,10 +1275,10 @@ rb_autoload_p(VALUE mod, ID id)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse)
|
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, NODE *fallback)
|
||||||
{
|
{
|
||||||
VALUE value, tmp;
|
VALUE value, tmp;
|
||||||
int mod_retry = 0;
|
int n_retry = 0;
|
||||||
|
|
||||||
tmp = klass;
|
tmp = klass;
|
||||||
retry:
|
retry:
|
||||||
|
@ -1294,34 +1294,47 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse)
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (!recurse && klass != rb_cObject) break;
|
if (!recurse) break;
|
||||||
tmp = RCLASS(tmp)->super;
|
tmp = RCLASS(tmp)->super;
|
||||||
|
if (tmp == rb_cObject) break;
|
||||||
}
|
}
|
||||||
if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
|
if (recurse) {
|
||||||
mod_retry = 1;
|
if (fallback) {
|
||||||
tmp = rb_cObject;
|
tmp = fallback->nd_clss;
|
||||||
goto retry;
|
fallback = fallback->nd_next;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
if (!n_retry) {
|
||||||
|
n_retry = 1;
|
||||||
|
tmp = rb_cObject;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return const_missing(klass, id);
|
return const_missing(klass, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_const_get_from(VALUE klass, ID id)
|
rb_const_get_from(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_get_0(klass, id, Qtrue, Qtrue);
|
return rb_const_get_0(klass, id, Qtrue, Qtrue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_const_get(VALUE klass, ID id)
|
rb_const_get(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_get_0(klass, id, Qfalse, Qtrue);
|
return rb_const_get_0(klass, id, Qfalse, Qtrue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_const_get_at(VALUE klass, ID id)
|
rb_const_get_at(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_get_0(klass, id, Qtrue, Qfalse);
|
return rb_const_get_0(klass, id, Qtrue, Qfalse, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_const_get_fallback(VALUE klass, ID id, NODE *fallback)
|
||||||
|
{
|
||||||
|
return rb_const_get_0(klass, id, Qfalse, Qtrue, fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1436,10 +1449,10 @@ rb_mod_constants(VALUE mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse)
|
rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse, NODE* fallback)
|
||||||
{
|
{
|
||||||
VALUE value, tmp;
|
VALUE value, tmp;
|
||||||
int mod_retry = 0;
|
int n_retry = 0;
|
||||||
|
|
||||||
tmp = klass;
|
tmp = klass;
|
||||||
retry:
|
retry:
|
||||||
|
@ -1449,13 +1462,21 @@ rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
if (!recurse && klass != rb_cObject) break;
|
if (!recurse) break;
|
||||||
tmp = RCLASS(tmp)->super;
|
tmp = RCLASS(tmp)->super;
|
||||||
|
if (tmp == rb_cObject) break;
|
||||||
}
|
}
|
||||||
if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
|
if (recurse) {
|
||||||
mod_retry = 1;
|
if (!n_retry) {
|
||||||
tmp = rb_cObject;
|
n_retry = 1;
|
||||||
goto retry;
|
tmp = rb_cObject;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
if (fallback) {
|
||||||
|
tmp = fallback->nd_clss;
|
||||||
|
fallback = fallback->nd_next;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
@ -1463,19 +1484,25 @@ rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse)
|
||||||
int
|
int
|
||||||
rb_const_defined_from(VALUE klass, ID id)
|
rb_const_defined_from(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_defined_0(klass, id, Qtrue, Qtrue);
|
return rb_const_defined_0(klass, id, Qtrue, Qtrue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_const_defined(VALUE klass, ID id)
|
rb_const_defined(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_defined_0(klass, id, Qfalse, Qtrue);
|
return rb_const_defined_0(klass, id, Qfalse, Qtrue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_const_defined_at(VALUE klass, ID id)
|
rb_const_defined_at(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
return rb_const_defined_0(klass, id, Qtrue, Qfalse);
|
return rb_const_defined_0(klass, id, Qtrue, Qfalse, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_const_defined_fallback(VALUE klass, ID id, NODE *fallback)
|
||||||
|
{
|
||||||
|
return rb_const_defined_0(klass, id, Qfalse, Qtrue, fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue