From b93479b8d9b8f0f95844d8e53ad954445177af00 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 16 Nov 2004 04:55:14 +0000 Subject: * string.c (str_mod_check): frozen check should be separated. [ruby-core:3742] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 3 +++ class.c | 30 ++++++++++++++---------------- eval.c | 2 +- lib/cgi/session.rb | 10 +++++++--- object.c | 2 +- string.c | 13 ++++++++++++- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d987d84c5d..d8aa14071b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ Tue Nov 16 11:19:07 2004 Nobuyoshi Nakada Tue Nov 16 01:41:31 2004 Yukihiro Matsumoto + * string.c (str_mod_check): frozen check should be separated. + [ruby-core:3742] + * array.c (rb_ary_update): pedantic check to detect rb_ary_to_ary() to modify the receiver. [ruby-dev:24861] diff --git a/class.c b/class.c index 0601d54aff..7fdfac8813 100644 --- a/class.c +++ b/class.c @@ -34,17 +34,28 @@ rb_class_boot(super) return (VALUE)klass; } +void +rb_check_inheritable(super) + VALUE super; +{ + if (TYPE(super) != T_CLASS) { + rb_raise(rb_eTypeError, "superclass must be a Class (%s given)", + rb_obj_classname(super)); + } + if (RBASIC(super)->flags & FL_SINGLETON) { + rb_raise(rb_eTypeError, "can't make subclass of singleton class"); + } +} + VALUE rb_class_new(super) VALUE super; { Check_Type(super, T_CLASS); + rb_check_inheritable(super); if (super == rb_cClass) { rb_raise(rb_eTypeError, "can't make subclass of Class"); } - if (FL_TEST(super, FL_SINGLETON)) { - rb_raise(rb_eTypeError, "can't make subclass of virtual class"); - } return rb_class_boot(super); } @@ -182,19 +193,6 @@ rb_define_class_id(id, super) return klass; } -void -rb_check_inheritable(super) - VALUE super; -{ - if (TYPE(super) != T_CLASS) { - rb_raise(rb_eTypeError, "superclass must be a Class (%s given)", - rb_obj_classname(super)); - } - if (RBASIC(super)->flags & FL_SINGLETON) { - rb_raise(rb_eTypeError, "can't make subclass of virtual class"); - } -} - VALUE rb_class_inherited(super, klass) VALUE super, klass; diff --git a/eval.c b/eval.c index cf886db648..dfb77c952e 100644 --- a/eval.c +++ b/eval.c @@ -3837,7 +3837,7 @@ rb_eval(self, n) result = rb_eval(self, node->nd_recv); if (FIXNUM_P(result) || SYMBOL_P(result)) { - rb_raise(rb_eTypeError, "no virtual class for %s", + rb_raise(rb_eTypeError, "no singleton class for %s", rb_obj_classname(result)); } if (ruby_safe_level >= 4 && !OBJ_TAINTED(result)) diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb index 6ca85e1806..401ce089c0 100644 --- a/lib/cgi/session.rb +++ b/lib/cgi/session.rb @@ -159,7 +159,7 @@ class CGI attr_reader :session_id def Session::callback(dbman) #:nodoc: - lambda{ + Proc.new{ dbman[0].close unless dbman.empty? } end @@ -351,17 +351,21 @@ class CGI # on Unix systems). # prefix:: the prefix to add to the session id when generating # the filename for this session's FileStore file. + # Defaults to "cgi_sid_". + # suffix:: the prefix to add to the session id when generating + # the filename for this session's FileStore file. # Defaults to the empty string. # # This session's FileStore file will be created if it does # not exist, or opened if it does. def initialize(session, option={}) dir = option['tmpdir'] || Dir::tmpdir - prefix = option['prefix'] || '' + prefix = option['prefix'] || 'cgi_sid_' + suffix = option['suffix'] || '' id = session.session_id require 'digest/md5' md5 = Digest::MD5.hexdigest(id)[0,16] - @path = dir+"/"+prefix+md5 + @path = dir+"/"+prefix+md5+suffix unless File::exist? @path @hash = {} end diff --git a/object.c b/object.c index 24536d446a..ab3edb69c7 100644 --- a/object.c +++ b/object.c @@ -1521,7 +1521,7 @@ rb_obj_alloc(klass) rb_raise(rb_eTypeError, "can't instantiate uninitialized class"); } if (FL_TEST(klass, FL_SINGLETON)) { - rb_raise(rb_eTypeError, "can't create instance of virtual class"); + rb_raise(rb_eTypeError, "can't create instance of singleton class"); } obj = rb_funcall(klass, ID_ALLOCATOR, 0, 0); if (rb_obj_class(obj) != rb_class_real(klass)) { diff --git a/string.c b/string.c index bf95d610c1..7648e446aa 100644 --- a/string.c +++ b/string.c @@ -45,11 +45,20 @@ str_mod_check(s, p, len) char *p; long len; { - if (RSTRING(s)->ptr != p || RSTRING(s)->len != len || OBJ_FROZEN(s)) { + if (RSTRING(s)->ptr != p || RSTRING(s)->len != len){ rb_raise(rb_eRuntimeError, "string modified"); } } +static inline void +str_frozen_check(s) + VALUE s; +{ + if (OBJ_FROZEN(s)) { + rb_raise(rb_eRuntimeError, "string frozen"); + } +} + static VALUE str_alloc _((VALUE)); static VALUE str_alloc(klass) @@ -1963,6 +1972,7 @@ rb_str_sub_bang(argc, argv, str) rb_match_busy(match); repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); str_mod_check(str, p, len); + str_frozen_check(str); rb_backref_set(match); } else { @@ -2082,6 +2092,7 @@ str_gsub(argc, argv, str, bang) rb_match_busy(match); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); str_mod_check(str, sp, slen); + str_frozen_check(str); if (val == dest) { /* paranoid chack [ruby-dev:24827] */ rb_raise(rb_eRuntimeError, "block should not cheat"); } -- cgit v1.2.3