mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* variable.c (rb_cvar_set): class variables become private to the
particular class/module. [Ruby2] * variable.c (rb_cvar_get): ditto. * io.c (rb_io_sync): need not to check writable. [ruby-core:02674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
91de9894fc
commit
610b5d7975
9 changed files with 57 additions and 87 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,12 @@
|
|||
Fri Mar 19 15:15:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* variable.c (rb_cvar_set): class variables become private to the
|
||||
particular class/module. [Ruby2]
|
||||
|
||||
* variable.c (rb_cvar_get): ditto.
|
||||
|
||||
* variable.c (rb_cvar_defined): ditto.
|
||||
|
||||
Fri Mar 19 11:31:32 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* lib/mkmf.rb ($beos, $solaris): add OS flags.
|
||||
|
@ -7,6 +16,10 @@ Fri Mar 19 11:31:32 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
|||
|
||||
* lib/mkmf.rb (CLEANLIBS, CLEANOBJS): should remove *.exp with *.so.
|
||||
|
||||
Fri Mar 19 01:55:57 2004 Mauricio Fernandez <batsman.geo@yahoo.com>
|
||||
|
||||
* io.c (rb_io_sync): need not to check writable. [ruby-core:02674]
|
||||
|
||||
Thu Mar 18 19:47:44 2004 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* instruby.rb, rubytest.rb: do not depend on srcdir.
|
||||
|
|
2
eval.c
2
eval.c
|
@ -8137,7 +8137,7 @@ static VALUE method_arity _((VALUE));
|
|||
* returns -1, as it can accept (and ignore) an arbitrary number of
|
||||
* parameters.
|
||||
*
|
||||
* Proc.new {}.arity #=> -1
|
||||
* Proc.new {}.arity #=> 0
|
||||
* Proc.new {||}.arity #=> 0
|
||||
* Proc.new {|a|}.arity #=> 1
|
||||
* Proc.new {|a,b|}.arity #=> 2
|
||||
|
|
1
io.c
1
io.c
|
@ -775,7 +775,6 @@ rb_io_fsync(io)
|
|||
FILE *f;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
rb_io_check_writable(fptr);
|
||||
f = GetWriteFile(fptr);
|
||||
|
||||
io_fflush(f, fptr);
|
||||
|
|
|
@ -1979,7 +1979,7 @@ $_ = foobar
|
|||
test_ok($_ == foobar)
|
||||
|
||||
class Gods
|
||||
@@rule = "Uranus"
|
||||
@@rule = "Uranus" # private to Gods
|
||||
def ruler0
|
||||
@@rule
|
||||
end
|
||||
|
@ -1995,25 +1995,29 @@ class Gods
|
|||
end
|
||||
|
||||
module Olympians
|
||||
@@rule ="Zeus"
|
||||
def ruler3
|
||||
@@rule ="Zeus"
|
||||
def ruler3
|
||||
@@rule
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Titans < Gods
|
||||
@@rule = "Cronus"
|
||||
include Olympians # OK to cause warning (intentional)
|
||||
@@rule = "Cronus" # do not affect @@rule in Gods
|
||||
include Olympians
|
||||
def ruler4
|
||||
@@rule
|
||||
end
|
||||
end
|
||||
|
||||
test_ok(Gods.new.ruler0 == "Cronus")
|
||||
test_ok(Gods.ruler1 == "Cronus")
|
||||
test_ok(Gods.ruler2 == "Cronus")
|
||||
test_ok(Titans.ruler1 == "Cronus")
|
||||
test_ok(Titans.ruler2 == "Cronus")
|
||||
test_ok(Gods.new.ruler0 == "Uranus")
|
||||
test_ok(Gods.ruler1 == "Uranus")
|
||||
test_ok(Gods.ruler2 == "Uranus")
|
||||
test_ok(Titans.ruler1 == "Uranus")
|
||||
test_ok(Titans.ruler2 == "Uranus")
|
||||
atlas = Titans.new
|
||||
test_ok(atlas.ruler0 == "Cronus")
|
||||
test_ok(atlas.ruler0 == "Uranus")
|
||||
test_ok(atlas.ruler3 == "Zeus")
|
||||
test_ok(atlas.ruler4 == "Cronus")
|
||||
|
||||
test_check "trace"
|
||||
$x = 1234
|
||||
|
|
|
@ -12,9 +12,15 @@ class DRbService
|
|||
)
|
||||
@@ruby += " -d" if $DEBUG
|
||||
@@dir = File.dirname(File.expand_path(__FILE__))
|
||||
def self.manager
|
||||
@@manager
|
||||
end
|
||||
def self.add_service_command(nm)
|
||||
DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}"
|
||||
end
|
||||
|
||||
%w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eval.rb).each do |nm|
|
||||
DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}"
|
||||
add_service_command(nm)
|
||||
end
|
||||
@server = @@server = DRb::DRbServer.new(nil, @@manager, {})
|
||||
def self.manager
|
||||
|
|
|
@ -10,7 +10,7 @@ if Object.const_defined?("OpenSSL")
|
|||
|
||||
class DRbSSLService < DRbService
|
||||
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
|
||||
DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}"
|
||||
add_service_command(nm)
|
||||
end
|
||||
config = Hash.new
|
||||
|
||||
|
@ -30,7 +30,7 @@ class DRbSSLService < DRbService
|
|||
end
|
||||
|
||||
uri = ARGV.shift if $0 == __FILE__
|
||||
@server = DRb::DRbServer.new(uri || 'drbssl://:0', @@manager, config)
|
||||
@server = DRb::DRbServer.new(uri || 'drbssl://:0', self.manager, config)
|
||||
end
|
||||
|
||||
class TestDRbSSLCore < Test::Unit::TestCase
|
||||
|
|
|
@ -10,11 +10,11 @@ if Object.const_defined?("UNIXServer")
|
|||
|
||||
class DRbUNIXService < DRbService
|
||||
%w(ut_drb_drbunix.rb ut_array_drbunix.rb).each do |nm|
|
||||
DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}"
|
||||
add_service_command(nm)
|
||||
end
|
||||
|
||||
uri = ARGV.shift if $0 == __FILE__
|
||||
@server = DRb::DRbServer.new(uri || 'drbunix:', @@manager, {})
|
||||
@server = DRb::DRbServer.new(uri || 'drbunix:', self.manager, {})
|
||||
end
|
||||
|
||||
class TestDRbUNIXCore < Test::Unit::TestCase
|
||||
|
|
|
@ -25,8 +25,11 @@ class TestVariable < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
class Titans < Gods
|
||||
@@rule = "Cronus"
|
||||
include Olympians # OK to cause warning (intentional)
|
||||
@@rule = "Cronus" # do not affect @@rule in Gods
|
||||
include Olympians
|
||||
def ruler4
|
||||
@@rule
|
||||
end
|
||||
end
|
||||
|
||||
def test_variable
|
||||
|
@ -41,13 +44,14 @@ class TestVariable < Test::Unit::TestCase
|
|||
$_ = foobar
|
||||
assert_equal(foobar, $_)
|
||||
|
||||
assert_equal("Cronus", Gods.new.ruler0)
|
||||
assert_equal("Cronus", Gods.ruler1)
|
||||
assert_equal("Cronus", Gods.ruler2)
|
||||
assert_equal("Cronus", Titans.ruler1)
|
||||
assert_equal("Cronus", Titans.ruler2)
|
||||
assert_equal("Uranus", Gods.new.ruler0)
|
||||
assert_equal("Uranus", Gods.ruler1)
|
||||
assert_equal("Uranus", Gods.ruler2)
|
||||
assert_equal("Uranus", Titans.ruler1)
|
||||
assert_equal("Uranus", Titans.ruler2)
|
||||
atlas = Titans.new
|
||||
assert_equal("Cronus", atlas.ruler0)
|
||||
assert_equal("Uranus", atlas.ruler0)
|
||||
assert_equal("Zeus", atlas.ruler3)
|
||||
assert_equal("Cronus", atlas.ruler4)
|
||||
end
|
||||
end
|
||||
|
|
64
variable.c
64
variable.c
|
@ -1702,26 +1702,6 @@ original_module(c)
|
|||
return c;
|
||||
}
|
||||
|
||||
static void
|
||||
cvar_override_check(id, a)
|
||||
ID id;
|
||||
VALUE a;
|
||||
{
|
||||
VALUE base = original_module(a);
|
||||
|
||||
a = RCLASS(a)->super;
|
||||
while (a) {
|
||||
if (RCLASS(a)->iv_tbl) {
|
||||
if (st_lookup(RCLASS(a)->iv_tbl,id,0)) {
|
||||
rb_warning("class variable %s of %s is overridden by %s",
|
||||
rb_id2name(id), rb_class2name(original_module(a)),
|
||||
rb_class2name(base));
|
||||
}
|
||||
}
|
||||
a = RCLASS(a)->super;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_cvar_set(klass, id, val, warn)
|
||||
VALUE klass;
|
||||
|
@ -1729,26 +1709,6 @@ rb_cvar_set(klass, id, val, warn)
|
|||
VALUE val;
|
||||
int warn;
|
||||
{
|
||||
VALUE tmp;
|
||||
|
||||
tmp = klass;
|
||||
while (tmp) {
|
||||
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
|
||||
if (OBJ_FROZEN(tmp)) rb_error_frozen("class/module");
|
||||
if (!OBJ_TAINTED(tmp) && rb_safe_level() >= 4)
|
||||
rb_raise(rb_eSecurityError, "Insecure: can't modify class variable");
|
||||
if (warn && RTEST(ruby_verbose) && klass != tmp) {
|
||||
rb_warning("already initialized class variable %s", rb_id2name(id));
|
||||
}
|
||||
st_insert(RCLASS(tmp)->iv_tbl,id,val);
|
||||
if (RTEST(ruby_verbose)) {
|
||||
cvar_override_check(id, tmp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmp = RCLASS(tmp)->super;
|
||||
}
|
||||
|
||||
mod_av_set(klass, id, val, Qfalse);
|
||||
}
|
||||
|
||||
|
@ -1760,17 +1720,8 @@ rb_cvar_get(klass, id)
|
|||
VALUE value;
|
||||
VALUE tmp;
|
||||
|
||||
tmp = klass;
|
||||
while (tmp) {
|
||||
if (RCLASS(tmp)->iv_tbl) {
|
||||
if (st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
|
||||
if (RTEST(ruby_verbose)) {
|
||||
cvar_override_check(id, tmp);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
tmp = RCLASS(tmp)->super;
|
||||
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl,id,&value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
rb_name_error(id,"uninitialized class variable %s in %s",
|
||||
|
@ -1783,16 +1734,9 @@ rb_cvar_defined(klass, id)
|
|||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
VALUE tmp;
|
||||
|
||||
tmp = klass;
|
||||
while (tmp) {
|
||||
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
|
||||
return Qtrue;
|
||||
}
|
||||
tmp = RCLASS(tmp)->super;
|
||||
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl,id,0)) {
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue