diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-16 04:55:14 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-16 04:55:14 +0000 |
commit | b93479b8d9b8f0f95844d8e53ad954445177af00 (patch) | |
tree | 2ab3eafa7c7820209707824cabea6de573c1244e | |
parent | c2b7884076865795a309a93eda6589a66150e968 (diff) |
* 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
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | class.c | 30 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib/cgi/session.rb | 10 | ||||
-rw-r--r-- | object.c | 2 | ||||
-rw-r--r-- | string.c | 13 |
6 files changed, 38 insertions, 22 deletions
@@ -13,6 +13,9 @@ Tue Nov 16 11:19:07 2004 Nobuyoshi Nakada <[email protected]> Tue Nov 16 01:41:31 2004 Yukihiro Matsumoto <[email protected]> + * 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] @@ -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; @@ -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 @@ -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)) { @@ -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"); } |