mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_become): should not free ptr if it's shared.
* eval.c (rb_alias): prohibit making an alias named "allocate" if klass is a metaclass. * string.c (rb_string_value_ptr): StringValuePtr() should never return NULL pointer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3bf972993f
commit
40bc4f5ae4
14 changed files with 218 additions and 179 deletions
14
ChangeLog
14
ChangeLog
|
@ -7,6 +7,13 @@ Thu Aug 29 00:55:55 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
* marshal.c (r_object): yield loaded objects, not intermediates.
|
* marshal.c (r_object): yield loaded objects, not intermediates.
|
||||||
(ruby-bugs-ja:PR#296)
|
(ruby-bugs-ja:PR#296)
|
||||||
|
|
||||||
|
Thu Aug 29 00:06:54 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (rb_ary_become): should not free ptr if it's shared.
|
||||||
|
|
||||||
|
* eval.c (rb_alias): prohibit making an alias named "allocate" if
|
||||||
|
klass is a metaclass.
|
||||||
|
|
||||||
Wed Aug 28 23:59:15 2002 Michal Rokos <michal@ruby-lang.org>
|
Wed Aug 28 23:59:15 2002 Michal Rokos <michal@ruby-lang.org>
|
||||||
|
|
||||||
* signal.c: remove #ifdef SIGINT for struct signals.
|
* signal.c: remove #ifdef SIGINT for struct signals.
|
||||||
|
@ -17,6 +24,11 @@ Wed Aug 28 23:34:32 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* io.c (appendline): data was lost when raw mode.
|
* io.c (appendline): data was lost when raw mode.
|
||||||
|
|
||||||
|
Wed Aug 28 22:57:34 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_string_value_ptr): StringValuePtr() should never
|
||||||
|
return NULL pointer.
|
||||||
|
|
||||||
Wed Aug 28 19:12:46 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Wed Aug 28 19:12:46 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* ext/stringio/stringio.c (strio_initialize): RSTRING(mode)->ptr
|
* ext/stringio/stringio.c (strio_initialize): RSTRING(mode)->ptr
|
||||||
|
@ -34,7 +46,7 @@ Wed Aug 28 17:45:03 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
Wed Aug 28 16:36:40 2002 WATANABE Hirofumi <eban@ruby-lang.org>
|
Wed Aug 28 16:36:40 2002 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in (ar): don't check twice for ar.
|
* configure.in (ar): don't check ar twice.
|
||||||
|
|
||||||
Wed Aug 28 15:00:29 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed Aug 28 15:00:29 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
|
5
ToDo
5
ToDo
|
@ -32,10 +32,11 @@ Language Spec.
|
||||||
* .. or something like defadvice in Emacs.
|
* .. or something like defadvice in Emacs.
|
||||||
* property - for methods, or for objects in general.
|
* property - for methods, or for objects in general.
|
||||||
* "in" modifier, to annotate, or to encourage assertion.
|
* "in" modifier, to annotate, or to encourage assertion.
|
||||||
* selector namespace - something like generic-flet in CLOS, to help RubyBehevior
|
* selector namespace - something like generic-flet in CLOS, to help RubyBehavior
|
||||||
* private instance variable (as in Python?) @_foo in class Foo => @_Foo_foo
|
* private instance variable (as in Python?) @_foo in class Foo => @_Foo_foo
|
||||||
* warn/error "bare word" method, like "foo", you should type "foo()"
|
* warn/error "bare word" method, like "foo", you should type "foo()"
|
||||||
* clarify evaluation order of operator argument (=~, .., ...)
|
* clarify evaluation order of operator argument (=~, .., ...)
|
||||||
|
* :symbol => value hash in the form of {symbol: value, ...} ??
|
||||||
|
|
||||||
Hacking Interpreter
|
Hacking Interpreter
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ Extension Libraries
|
||||||
|
|
||||||
Ruby Libraries
|
Ruby Libraries
|
||||||
|
|
||||||
* add uri.rb
|
- add uri.rb
|
||||||
* urllib.rb, nttplib.rb, etc.
|
* urllib.rb, nttplib.rb, etc.
|
||||||
* format like perl's
|
* format like perl's
|
||||||
|
|
||||||
|
|
3
array.c
3
array.c
|
@ -801,7 +801,8 @@ rb_ary_become(copy, orig)
|
||||||
{
|
{
|
||||||
orig = to_ary(orig);
|
orig = to_ary(orig);
|
||||||
ary_make_shared(orig);
|
ary_make_shared(orig);
|
||||||
if (RARRAY(copy)->ptr) free(RARRAY(copy)->ptr);
|
if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
|
||||||
|
free(RARRAY(copy)->ptr);
|
||||||
RARRAY(copy)->ptr = RARRAY(orig)->ptr;
|
RARRAY(copy)->ptr = RARRAY(orig)->ptr;
|
||||||
RARRAY(copy)->len = RARRAY(orig)->len;
|
RARRAY(copy)->len = RARRAY(orig)->len;
|
||||||
RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
|
RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
|
||||||
|
|
|
@ -1018,7 +1018,7 @@ case "$target_os" in
|
||||||
CFLAGS="$CFLAGS -pipe -no-precomp"
|
CFLAGS="$CFLAGS -pipe -no-precomp"
|
||||||
;;
|
;;
|
||||||
darwin*)
|
darwin*)
|
||||||
CFLAGS="$CFLAGS -pipe -no-precomp"
|
CFLAGS="$CFLAGS -pipe"
|
||||||
;;
|
;;
|
||||||
os2_emx)
|
os2_emx)
|
||||||
CFLAGS="$CFLAGS -DOS2"
|
CFLAGS="$CFLAGS -DOS2"
|
||||||
|
|
12
eval.c
12
eval.c
|
@ -1700,6 +1700,7 @@ rb_alias(klass, name, def)
|
||||||
{
|
{
|
||||||
VALUE origin;
|
VALUE origin;
|
||||||
NODE *orig, *body;
|
NODE *orig, *body;
|
||||||
|
VALUE singleton = 0;
|
||||||
|
|
||||||
rb_frozen_class_p(klass);
|
rb_frozen_class_p(klass);
|
||||||
if (name == def) return;
|
if (name == def) return;
|
||||||
|
@ -1715,6 +1716,12 @@ rb_alias(klass, name, def)
|
||||||
if (!orig || !orig->nd_body) {
|
if (!orig || !orig->nd_body) {
|
||||||
print_undef(klass, def);
|
print_undef(klass, def);
|
||||||
}
|
}
|
||||||
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
||||||
|
singleton = rb_iv_get(klass, "__attached__");
|
||||||
|
if (name == alloc && TYPE(singleton) == T_CLASS) {
|
||||||
|
rb_raise(rb_eNameError, "cannot make alias named `allocate'");
|
||||||
|
}
|
||||||
|
}
|
||||||
body = orig->nd_body;
|
body = orig->nd_body;
|
||||||
orig->nd_cnt++;
|
orig->nd_cnt++;
|
||||||
if (nd_type(body) == NODE_FBODY) { /* was alias */
|
if (nd_type(body) == NODE_FBODY) { /* was alias */
|
||||||
|
@ -1726,9 +1733,8 @@ rb_alias(klass, name, def)
|
||||||
rb_clear_cache_by_id(name);
|
rb_clear_cache_by_id(name);
|
||||||
st_insert(RCLASS(klass)->m_tbl, name,
|
st_insert(RCLASS(klass)->m_tbl, name,
|
||||||
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
|
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
|
||||||
if (FL_TEST(klass, FL_SINGLETON)) {
|
if (singleton) {
|
||||||
rb_funcall(rb_iv_get(klass, "__attached__"),
|
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
|
||||||
singleton_added, 1, ID2SYM(name));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_funcall(klass, added, 1, ID2SYM(name));
|
rb_funcall(klass, added, 1, ID2SYM(name));
|
||||||
|
|
8
file.c
8
file.c
|
@ -2027,8 +2027,12 @@ rb_stat_become(obj, orig)
|
||||||
struct stat *nst;
|
struct stat *nst;
|
||||||
|
|
||||||
/* need better argument type check */
|
/* need better argument type check */
|
||||||
if (!rb_obj_is_kind_of(orig, rb_obj_class(obj))) {
|
if (!rb_obj_is_instance_of(orig, rb_obj_class(obj))) {
|
||||||
rb_raise(rb_eTypeError, "wrong argument type");
|
rb_raise(rb_eTypeError, "wrong argument class");
|
||||||
|
}
|
||||||
|
if (DATA_PTR(obj)) {
|
||||||
|
free(DATA_PTR(obj));
|
||||||
|
DATA_PTR(obj) = 0;
|
||||||
}
|
}
|
||||||
if (DATA_PTR(orig)) {
|
if (DATA_PTR(orig)) {
|
||||||
nst = ALLOC(struct stat);
|
nst = ALLOC(struct stat);
|
||||||
|
|
2
gc.c
2
gc.c
|
@ -1356,7 +1356,7 @@ static VALUE
|
||||||
call_final(os, obj)
|
call_final(os, obj)
|
||||||
VALUE os, obj;
|
VALUE os, obj;
|
||||||
{
|
{
|
||||||
rb_warn("ObjectSpace::call_final is deprecated; use define_finalizer");
|
rb_warn("ObjectSpace::call_finalizer is deprecated; use define_finalizer");
|
||||||
need_call_final = 1;
|
need_call_final = 1;
|
||||||
FL_SET(obj, FL_FINALIZE);
|
FL_SET(obj, FL_FINALIZE);
|
||||||
return obj;
|
return obj;
|
||||||
|
|
6
hash.c
6
hash.c
|
@ -265,9 +265,15 @@ rb_hash_become(copy, orig)
|
||||||
if (FL_TEST(orig, HASH_PROC_DEFAULT)) {
|
if (FL_TEST(orig, HASH_PROC_DEFAULT)) {
|
||||||
FL_SET(copy, HASH_PROC_DEFAULT);
|
FL_SET(copy, HASH_PROC_DEFAULT);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
FL_UNSET(copy, HASH_PROC_DEFAULT);
|
||||||
|
}
|
||||||
if (FL_TEST(orig, HASH_DELETED)) {
|
if (FL_TEST(orig, HASH_DELETED)) {
|
||||||
FL_SET(copy, HASH_DELETED);
|
FL_SET(copy, HASH_DELETED);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
FL_UNSET(copy, HASH_DELETED);
|
||||||
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
283
lib/finalize.rb
283
lib/finalize.rb
|
@ -43,159 +43,144 @@
|
||||||
|
|
||||||
module Finalizer
|
module Finalizer
|
||||||
RCS_ID='-$Id: finalize.rb,v 1.4 1998/02/27 05:34:33 keiju Exp keiju $-'
|
RCS_ID='-$Id: finalize.rb,v 1.4 1998/02/27 05:34:33 keiju Exp keiju $-'
|
||||||
|
|
||||||
# @dependency: {id => [[dependant, method, *opt], ...], ...}
|
class <<self
|
||||||
|
# @dependency: {id => [[dependant, method, *opt], ...], ...}
|
||||||
# add dependency R_method(obj, dependant)
|
|
||||||
def add_dependency(obj, dependant, method = :finalize, *opt)
|
# add dependency R_method(obj, dependant)
|
||||||
ObjectSpace.call_finalizer(obj)
|
def add_dependency(obj, dependant, method = :finalize, *opt)
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
ObjectSpace.call_finalizer(obj)
|
||||||
assoc = [dependant, method].concat(opt)
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
if dep = @dependency[obj.id]
|
assoc = [dependant, method].concat(opt)
|
||||||
dep.push assoc
|
if dep = @dependency[obj.id]
|
||||||
else
|
dep.push assoc
|
||||||
@dependency[obj.id] = [assoc]
|
else
|
||||||
end
|
@dependency[obj.id] = [assoc]
|
||||||
end
|
|
||||||
alias add add_dependency
|
|
||||||
|
|
||||||
# delete dependency R_method(obj, dependant)
|
|
||||||
def delete_dependency(id, dependant, method = :finalize)
|
|
||||||
id = id.id unless id.kind_of?(Integer)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for assoc in @dependency[id]
|
|
||||||
assoc.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d == dependant && m == method
|
|
||||||
end
|
|
||||||
@dependency.delete(id) if assoc.empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias delete delete_dependency
|
|
||||||
|
|
||||||
# delete dependency R_*(obj, dependant)
|
|
||||||
def delete_all_dependency(id, dependant)
|
|
||||||
id = id.id unless id.kind_of?(Integer)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for assoc in @dependency[id]
|
|
||||||
assoc.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d == dependant
|
|
||||||
end
|
|
||||||
@dependency.delete(id) if assoc.empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# delete dependency R_method(*, dependant)
|
|
||||||
def delete_by_dependant(dependant, method = :finalize)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for id in @dependency.keys
|
|
||||||
delete(id, dependant, method)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# delete dependency R_*(*, dependant)
|
|
||||||
def delete_all_by_dependant(dependant)
|
|
||||||
for id in @dependency.keys
|
|
||||||
delete_all_dependency(id, dependant)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# finalize the depandant connected by dependency R_method(obj, dependtant)
|
|
||||||
def finalize_dependency(id, dependant, method = :finalize)
|
|
||||||
id = id.id unless id.kind_of?(Integer)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for assocs in @dependency[id]
|
|
||||||
assocs.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d.send(m, id, *o) if ret = d == dependant && m == method
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
@dependency.delete(id) if assoc.empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias finalize finalize_dependency
|
|
||||||
|
|
||||||
# finalize all dependants connected by dependency R_*(obj, dependtant)
|
|
||||||
def finalize_all_dependency(id, dependant)
|
|
||||||
id = id.id unless id.kind_of?(Integer)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for assoc in @dependency[id]
|
|
||||||
assoc.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d.send(m, id, *o) if ret = d == dependant
|
|
||||||
end
|
|
||||||
@dependency.delete(id) if assoc.empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# finalize the dependant connected by dependency R_method(*, dependtant)
|
|
||||||
def finalize_by_dependant(dependant, method = :finalize)
|
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
|
||||||
for id in @dependency.keys
|
|
||||||
finalize(id, dependant, method)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# finalize all dependants connected by dependency R_*(*, dependtant)
|
|
||||||
def finalize_all_by_dependant(dependant)
|
|
||||||
for id in @dependency.keys
|
|
||||||
finalize_all_dependency(id, dependant)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# finalize all dependants registered to the Finalizer.
|
|
||||||
def finalize_all
|
|
||||||
for id, assocs in @dependency
|
|
||||||
for dependant, method, *opt in assocs
|
|
||||||
dependant.send(method, id, *opt)
|
|
||||||
end
|
|
||||||
assocs.clear
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# method to call finalize_* safely.
|
|
||||||
def safe
|
|
||||||
old_status = Thread.critical
|
|
||||||
Thread.critical = true
|
|
||||||
ObjectSpace.remove_finalizer(@proc)
|
|
||||||
yield
|
|
||||||
ObjectSpace.add_finalizer(@proc)
|
|
||||||
Thread.critical = old_status
|
|
||||||
end
|
|
||||||
|
|
||||||
# registering function to ObjectSpace#add_finalizer
|
|
||||||
def final_of(id)
|
|
||||||
if assocs = @dependency.delete(id)
|
|
||||||
for dependant, method, *opt in assocs
|
|
||||||
dependant.send(method, id, *opt)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
alias add add_dependency
|
||||||
|
|
||||||
|
# delete dependency R_method(obj, dependant)
|
||||||
|
def delete_dependency(id, dependant, method = :finalize)
|
||||||
|
id = id.id unless id.kind_of?(Integer)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for assoc in @dependency[id]
|
||||||
|
assoc.delete_if do
|
||||||
|
|d, m, *o|
|
||||||
|
d == dependant && m == method
|
||||||
|
end
|
||||||
|
@dependency.delete(id) if assoc.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
alias delete delete_dependency
|
||||||
|
|
||||||
|
# delete dependency R_*(obj, dependant)
|
||||||
|
def delete_all_dependency(id, dependant)
|
||||||
|
id = id.id unless id.kind_of?(Integer)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for assoc in @dependency[id]
|
||||||
|
assoc.delete_if do
|
||||||
|
|d, m, *o|
|
||||||
|
d == dependant
|
||||||
|
end
|
||||||
|
@dependency.delete(id) if assoc.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# delete dependency R_method(*, dependant)
|
||||||
|
def delete_by_dependant(dependant, method = :finalize)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for id in @dependency.keys
|
||||||
|
delete(id, dependant, method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# delete dependency R_*(*, dependant)
|
||||||
|
def delete_all_by_dependant(dependant)
|
||||||
|
for id in @dependency.keys
|
||||||
|
delete_all_dependency(id, dependant)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# finalize the depandant connected by dependency R_method(obj, dependtant)
|
||||||
|
def finalize_dependency(id, dependant, method = :finalize)
|
||||||
|
id = id.id unless id.kind_of?(Integer)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for assocs in @dependency[id]
|
||||||
|
assocs.delete_if do
|
||||||
|
|d, m, *o|
|
||||||
|
d.send(m, id, *o) if ret = d == dependant && m == method
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
@dependency.delete(id) if assoc.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
alias finalize finalize_dependency
|
||||||
|
|
||||||
|
# finalize all dependants connected by dependency R_*(obj, dependtant)
|
||||||
|
def finalize_all_dependency(id, dependant)
|
||||||
|
id = id.id unless id.kind_of?(Integer)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for assoc in @dependency[id]
|
||||||
|
assoc.delete_if do
|
||||||
|
|d, m, *o|
|
||||||
|
d.send(m, id, *o) if ret = d == dependant
|
||||||
|
end
|
||||||
|
@dependency.delete(id) if assoc.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# finalize the dependant connected by dependency R_method(*, dependtant)
|
||||||
|
def finalize_by_dependant(dependant, method = :finalize)
|
||||||
|
method = method.intern unless method.kind_of?(Integer)
|
||||||
|
for id in @dependency.keys
|
||||||
|
finalize(id, dependant, method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# finalize all dependants connected by dependency R_*(*, dependtant)
|
||||||
|
def finalize_all_by_dependant(dependant)
|
||||||
|
for id in @dependency.keys
|
||||||
|
finalize_all_dependency(id, dependant)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# finalize all dependants registered to the Finalizer.
|
||||||
|
def finalize_all
|
||||||
|
for id, assocs in @dependency
|
||||||
|
for dependant, method, *opt in assocs
|
||||||
|
dependant.send(method, id, *opt)
|
||||||
|
end
|
||||||
|
assocs.clear
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# method to call finalize_* safely.
|
||||||
|
def safe
|
||||||
|
old_status = Thread.critical
|
||||||
|
Thread.critical = true
|
||||||
|
ObjectSpace.remove_finalizer(@proc)
|
||||||
|
begin
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ObjectSpace.add_finalizer(@proc)
|
||||||
|
Thread.critical = old_status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# registering function to ObjectSpace#add_finalizer
|
||||||
|
def final_of(id)
|
||||||
|
if assocs = @dependency.delete(id)
|
||||||
|
for dependant, method, *opt in assocs
|
||||||
|
dependant.send(method, id, *opt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@dependency = Hash.new
|
@dependency = Hash.new
|
||||||
@proc = proc{|id| final_of(id)}
|
@proc = proc{|id| final_of(id)}
|
||||||
ObjectSpace.add_finalizer(@proc)
|
ObjectSpace.add_finalizer(@proc)
|
||||||
|
|
||||||
module_function :add
|
|
||||||
module_function :add_dependency
|
|
||||||
|
|
||||||
module_function :delete
|
|
||||||
module_function :delete_dependency
|
|
||||||
module_function :delete_all_dependency
|
|
||||||
module_function :delete_by_dependant
|
|
||||||
module_function :delete_all_by_dependant
|
|
||||||
|
|
||||||
module_function :finalize
|
|
||||||
module_function :finalize_dependency
|
|
||||||
module_function :finalize_all_dependency
|
|
||||||
module_function :finalize_by_dependant
|
|
||||||
module_function :finalize_all_by_dependant
|
|
||||||
module_function :finalize_all
|
|
||||||
|
|
||||||
module_function :safe
|
|
||||||
|
|
||||||
module_function :final_of
|
|
||||||
private_class_method :final_of
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
25
marshal.c
25
marshal.c
|
@ -466,11 +466,15 @@ w_object(obj, arg, limit)
|
||||||
|
|
||||||
case T_HASH:
|
case T_HASH:
|
||||||
w_uclass(obj, rb_cHash, arg);
|
w_uclass(obj, rb_cHash, arg);
|
||||||
if (!NIL_P(RHASH(obj)->ifnone)) {
|
if (NIL_P(RHASH(obj)->ifnone)) {
|
||||||
w_byte(TYPE_HASH_DEF, arg);
|
w_byte(TYPE_HASH, arg);
|
||||||
|
}
|
||||||
|
else if (FL_TEST(obj, FL_USER2)) {
|
||||||
|
/* FL_USER2 means HASH_PROC_DEFAULT (see hash.c) */
|
||||||
|
rb_raise(rb_eArgError, "cannot dump hash with default proc");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
w_byte(TYPE_HASH, arg);
|
w_byte(TYPE_HASH_DEF, arg);
|
||||||
}
|
}
|
||||||
w_long(RHASH(obj)->tbl->num_entries, arg);
|
w_long(RHASH(obj)->tbl->num_entries, arg);
|
||||||
st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
|
st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
|
||||||
|
@ -1047,12 +1051,17 @@ r_object0(arg, proc)
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
|
||||||
klass = rb_path2class(r_unique(arg));
|
klass = rb_path2class(r_unique(arg));
|
||||||
if (!rb_respond_to(klass, s_alloc)) {
|
if (rb_respond_to(klass, s_alloc)) {
|
||||||
rb_raise(rb_eTypeError,
|
static int warn = Qtrue;
|
||||||
"class %s needs to have class method `_alloc'",
|
if (warn) {
|
||||||
rb_class2name(klass));
|
rb_warn("define `allocate' instead of `_alloc'");
|
||||||
|
warn = Qfalse;
|
||||||
|
}
|
||||||
|
v = rb_funcall(klass, s_alloc, 0);
|
||||||
}
|
}
|
||||||
v = rb_funcall(klass, s_alloc, 0);
|
else {
|
||||||
|
v = rb_obj_alloc(klass);
|
||||||
|
}
|
||||||
if (TYPE(v) != T_DATA) {
|
if (TYPE(v) != T_DATA) {
|
||||||
rb_raise(rb_eArgError, "dump format error");
|
rb_raise(rb_eArgError, "dump format error");
|
||||||
}
|
}
|
||||||
|
|
2
re.c
2
re.c
|
@ -1333,7 +1333,7 @@ rb_reg_become(clone, re)
|
||||||
VALUE re;
|
VALUE re;
|
||||||
{
|
{
|
||||||
/* need better argument type check */
|
/* need better argument type check */
|
||||||
if (!rb_obj_is_kind_of(re, rb_obj_class(clone))) {
|
if (!rb_obj_is_instance_of(re, rb_obj_class(clone))) {
|
||||||
rb_raise(rb_eTypeError, "wrong argument type");
|
rb_raise(rb_eTypeError, "wrong argument type");
|
||||||
}
|
}
|
||||||
RREGEXP(clone)->ptr = 0;
|
RREGEXP(clone)->ptr = 0;
|
||||||
|
|
3
ruby.h
3
ruby.h
|
@ -211,6 +211,7 @@ void rb_check_type _((VALUE,int));
|
||||||
|
|
||||||
VALUE rb_str_to_str _((VALUE));
|
VALUE rb_str_to_str _((VALUE));
|
||||||
VALUE rb_string_value _((volatile VALUE*));
|
VALUE rb_string_value _((volatile VALUE*));
|
||||||
|
char *rb_string_value_ptr _((volatile VALUE*));
|
||||||
|
|
||||||
#define StringValue(v) if (TYPE(v) != T_STRING) rb_string_value(&(v))
|
#define StringValue(v) if (TYPE(v) != T_STRING) rb_string_value(&(v))
|
||||||
void rb_check_safe_str _((VALUE));
|
void rb_check_safe_str _((VALUE));
|
||||||
|
@ -218,7 +219,7 @@ void rb_check_safe_str _((VALUE));
|
||||||
StringValue(v);\
|
StringValue(v);\
|
||||||
rb_check_safe_str(v);\
|
rb_check_safe_str(v);\
|
||||||
} while (0)
|
} while (0)
|
||||||
#define StringValuePtr(v) RSTRING((TYPE(v) == T_STRING) ? (v) : rb_string_value(&(v)))->ptr
|
#define StringValuePtr(v) rb_string_value_ptr(&(v))
|
||||||
/* obsolete macro - use SafeStringValue(v) */
|
/* obsolete macro - use SafeStringValue(v) */
|
||||||
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
|
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
|
||||||
|
|
||||||
|
|
28
string.c
28
string.c
|
@ -440,6 +440,21 @@ rb_string_value(ptr)
|
||||||
return *ptr = rb_str_to_str(*ptr);
|
return *ptr = rb_str_to_str(*ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
rb_string_value_ptr(ptr)
|
||||||
|
volatile VALUE *ptr;
|
||||||
|
{
|
||||||
|
VALUE s = *ptr;
|
||||||
|
if (TYPE(s) != T_STRING) {
|
||||||
|
s = rb_str_to_str(s);
|
||||||
|
*ptr = s;
|
||||||
|
}
|
||||||
|
if (!RSTRING(s)->ptr) {
|
||||||
|
str_make_independent(s);
|
||||||
|
}
|
||||||
|
return RSTRING(s)->ptr;
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_str_substr(str, beg, len)
|
rb_str_substr(str, beg, len)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
@ -1609,18 +1624,17 @@ rb_str_replace(str, str2)
|
||||||
}
|
}
|
||||||
RSTRING(str)->len = RSTRING(str2)->len;
|
RSTRING(str)->len = RSTRING(str2)->len;
|
||||||
RSTRING(str)->ptr = RSTRING(str2)->ptr;
|
RSTRING(str)->ptr = RSTRING(str2)->ptr;
|
||||||
if (FL_TEST(str2, ELTS_SHARED|STR_ASSOC)) {
|
FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
|
||||||
FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
|
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
|
||||||
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
RSTRING(str)->aux.capa = RSTRING(str2)->aux.capa;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_str_modify(str);
|
rb_str_modify(str);
|
||||||
rb_str_resize(str, RSTRING(str2)->len);
|
rb_str_resize(str, RSTRING(str2)->len);
|
||||||
memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
|
memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
|
||||||
|
if (FL_TEST(str2, STR_ASSOC)) {
|
||||||
|
FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
|
||||||
|
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJ_INFECT(str, str2);
|
OBJ_INFECT(str, str2);
|
||||||
|
|
4
struct.c
4
struct.c
|
@ -424,8 +424,8 @@ static VALUE
|
||||||
rb_struct_become(clone, s)
|
rb_struct_become(clone, s)
|
||||||
VALUE clone, s;
|
VALUE clone, s;
|
||||||
{
|
{
|
||||||
if (!rb_obj_is_kind_of(s, rb_obj_class(clone))) {
|
if (!rb_obj_is_instance_of(s, rb_obj_class(clone))) {
|
||||||
rb_raise(rb_eTypeError, "wrong argument type");
|
rb_raise(rb_eTypeError, "wrong argument class");
|
||||||
}
|
}
|
||||||
RSTRUCT(clone)->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
|
RSTRUCT(clone)->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
|
||||||
RSTRUCT(clone)->len = RSTRUCT(s)->len;
|
RSTRUCT(clone)->len = RSTRUCT(s)->len;
|
||||||
|
|
Loading…
Add table
Reference in a new issue