mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
c2b7884076
commit
b93479b8d9
6 changed files with 38 additions and 22 deletions
|
@ -13,6 +13,9 @@ Tue Nov 16 11:19:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
|||
|
||||
Tue Nov 16 01:41:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* 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]
|
||||
|
||||
|
|
30
class.c
30
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;
|
||||
|
|
2
eval.c
2
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))
|
||||
|
|
|
@ -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
|
||||
|
|
2
object.c
2
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)) {
|
||||
|
|
13
string.c
13
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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue