зеркало из https://github.com/github/ruby.git
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
23dd3051c0
Коммит
448e63d627
13
ChangeLog
13
ChangeLog
|
@ -1,8 +1,19 @@
|
|||
Mon Jul 17 04:29:50 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
|
||||
* lib/mkmf.rb: converts extention of $objs into $OBJEXT.
|
||||
|
||||
Sun Jul 16 03:02:34 2000 Dave Thomas <dave@thomases.com>
|
||||
|
||||
* lib/weakref.rb: Change to use new ObjectSpace calls.
|
||||
|
||||
Sat Jul 15 21:59:58 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* eval.c (rb_eval): should not redefine __id__ nor __send__.
|
||||
|
||||
* gc.c (define_final): integrate final.rb features into the
|
||||
interpreter. define_finalizer and undefine_finalizer was
|
||||
added to ObjectSpace.
|
||||
added to ObjectSpace. plus, add_finalizer, remove_finalizer,
|
||||
and call_finalizer are deprecated now.
|
||||
|
||||
Sat Jul 15 01:32:34 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
|
|
1
ToDo
1
ToDo
|
@ -76,7 +76,6 @@ Standard Libraries
|
|||
- consistent /, %, divmod
|
||||
- unbound method object
|
||||
- integrate final.rb into the core.
|
||||
* make clone depend on dup
|
||||
* Enumerable#sort_by for Schwartzian transformation
|
||||
* String#scanf(?)
|
||||
* Object#fmt(?)
|
||||
|
|
28
array.c
28
array.c
|
@ -676,21 +676,6 @@ rb_ary_clone(ary)
|
|||
return clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_ary_dup(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
VALUE klass = CLASS_OF(ary);
|
||||
VALUE dup;
|
||||
|
||||
while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
|
||||
klass = (VALUE)RCLASS(klass)->super;
|
||||
}
|
||||
dup = rb_ary_s_create(RARRAY(ary)->len, RARRAY(ary)->ptr, klass);
|
||||
if (OBJ_TAINTED(ary)) OBJ_TAINT(dup);
|
||||
return dup;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
to_ary(ary)
|
||||
VALUE ary;
|
||||
|
@ -928,7 +913,7 @@ static VALUE
|
|||
rb_ary_reverse_m(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
return rb_ary_reverse(rb_ary_dup(ary));
|
||||
return rb_ary_reverse(rb_obj_dup(ary));
|
||||
}
|
||||
|
||||
static ID cmp;
|
||||
|
@ -991,7 +976,7 @@ VALUE
|
|||
rb_ary_sort(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
ary = rb_ary_dup(ary);
|
||||
ary = rb_obj_dup(ary);
|
||||
rb_ary_sort_bang(ary);
|
||||
return ary;
|
||||
}
|
||||
|
@ -1004,7 +989,7 @@ rb_ary_collect(ary)
|
|||
VALUE collect;
|
||||
|
||||
if (!rb_block_given_p()) {
|
||||
return rb_ary_dup(ary);
|
||||
return rb_obj_dup(ary);
|
||||
}
|
||||
|
||||
len = RARRAY(ary)->len;
|
||||
|
@ -1492,7 +1477,7 @@ static VALUE
|
|||
rb_ary_uniq(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
ary = rb_ary_dup(ary);
|
||||
ary = rb_obj_dup(ary);
|
||||
rb_ary_uniq_bang(ary);
|
||||
return ary;
|
||||
}
|
||||
|
@ -1523,7 +1508,7 @@ static VALUE
|
|||
rb_ary_compact(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
ary = rb_ary_dup(ary);
|
||||
ary = rb_obj_dup(ary);
|
||||
rb_ary_compact_bang(ary);
|
||||
return ary;
|
||||
}
|
||||
|
@ -1582,7 +1567,7 @@ static VALUE
|
|||
rb_ary_flatten(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
ary = rb_ary_dup(ary);
|
||||
ary = rb_obj_dup(ary);
|
||||
rb_ary_flatten_bang(ary);
|
||||
return ary;
|
||||
}
|
||||
|
@ -1629,7 +1614,6 @@ Init_Array()
|
|||
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
|
||||
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
|
||||
rb_define_method(rb_cArray, "clone", rb_ary_clone, 0);
|
||||
rb_define_method(rb_cArray, "dup", rb_ary_dup, 0);
|
||||
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
|
||||
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
|
||||
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse, 0);
|
||||
|
|
62
eval.c
62
eval.c
|
@ -432,6 +432,7 @@ rb_method_boundp(klass, id, ex)
|
|||
}
|
||||
|
||||
static ID init, eqq, each, aref, aset, match, missing, added, singleton_added;
|
||||
static ID __id__, __send__;
|
||||
|
||||
void
|
||||
rb_attr(klass, id, read, write, ex)
|
||||
|
@ -2786,6 +2787,10 @@ rb_eval(self, n)
|
|||
if (ruby_class == rb_cObject && node->nd_mid == init) {
|
||||
rb_warn("re-defining Object#initialize may cause infinite loop");
|
||||
}
|
||||
if (node->nd_mid == __id__ || node->nd_mid == __send__) {
|
||||
rb_warn("redefining `%s' may cause serious problem",
|
||||
rb_id2name(node->nd_mid));
|
||||
}
|
||||
frozen_class_p(ruby_class);
|
||||
body = search_method(ruby_class, node->nd_mid, &origin);
|
||||
if (body){
|
||||
|
@ -2794,7 +2799,7 @@ rb_eval(self, n)
|
|||
}
|
||||
rb_clear_cache_by_id(node->nd_mid);
|
||||
if (node->nd_noex) { /* toplevel */
|
||||
/* should be upgrade to rb_warn() if no super was called? */
|
||||
/* should upgrade to rb_warn() if no super was called inside? */
|
||||
rb_warning("overriding global function `%s'",
|
||||
rb_id2name(node->nd_mid));
|
||||
}
|
||||
|
@ -5509,6 +5514,9 @@ Init_eval()
|
|||
added = rb_intern("method_added");
|
||||
singleton_added = rb_intern("singleton_method_added");
|
||||
|
||||
__id__ = rb_intern("__id__");
|
||||
__send__ = rb_intern("__send__");
|
||||
|
||||
rb_global_variable((VALUE*)&top_scope);
|
||||
rb_global_variable((VALUE*)&ruby_eval_tree_begin);
|
||||
|
||||
|
@ -6131,7 +6139,7 @@ mnew(klass, obj, id, mklass)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
method_unbound(obj)
|
||||
method_unbind(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE method;
|
||||
|
@ -6140,18 +6148,18 @@ method_unbound(obj)
|
|||
Data_Get_Struct(obj, struct METHOD, orig);
|
||||
method = Data_Make_Struct(rb_cUnboundMethod, struct METHOD, bm_mark, free, data);
|
||||
data->klass = orig->klass;
|
||||
data->recv = 0;
|
||||
data->recv = obj;
|
||||
data->id = orig->id;
|
||||
data->body = orig->body;
|
||||
data->oklass = orig->oklass;
|
||||
data->oid = orig->oid;
|
||||
OBJ_INFECT(method, orig->klass);
|
||||
OBJ_INFECT(method, obj);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
umethod_unbound(obj)
|
||||
umethod_unbind(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
return obj;
|
||||
|
@ -6189,10 +6197,10 @@ method_clone(self)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
mcall(argc, argv, method, recv)
|
||||
method_call(argc, argv, method)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE method, recv;
|
||||
VALUE method;
|
||||
{
|
||||
VALUE result;
|
||||
struct METHOD *data;
|
||||
|
@ -6206,7 +6214,7 @@ mcall(argc, argv, method, recv)
|
|||
if (ruby_safe_level < 4) ruby_safe_level = 4;
|
||||
}
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
result = rb_call0(data->klass,recv,data->id,argc,argv,data->body,0);
|
||||
result = rb_call0(data->klass,data->recv,data->id,argc,argv,data->body,0);
|
||||
}
|
||||
POP_TAG();
|
||||
POP_ITER();
|
||||
|
@ -6215,32 +6223,22 @@ mcall(argc, argv, method, recv)
|
|||
return result;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
method_call(argc, argv, method)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE method;
|
||||
{
|
||||
struct METHOD *data;
|
||||
|
||||
Data_Get_Struct(method, struct METHOD, data);
|
||||
return mcall(argc, argv, method, data->recv);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
umethod_call(argc, argv, method)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE method;
|
||||
{
|
||||
struct METHOD *data;
|
||||
VALUE recv;
|
||||
rb_raise(rb_eTypeError, "you cannot call unbound method; bind first");
|
||||
return Qnil; /* not reached */
|
||||
}
|
||||
|
||||
if (argc < 1) {
|
||||
rb_raise(rb_eArgError, "wrong # of arguments");
|
||||
}
|
||||
static VALUE
|
||||
umethod_bind(method, recv)
|
||||
VALUE method, recv;
|
||||
{
|
||||
struct METHOD *data, *bound;
|
||||
|
||||
recv = argv[0];
|
||||
Data_Get_Struct(method, struct METHOD, data);
|
||||
if (data->oklass != CLASS_OF(recv)) {
|
||||
if (FL_TEST(data->oklass, FL_SINGLETON)) {
|
||||
|
@ -6255,7 +6253,12 @@ umethod_call(argc, argv, method)
|
|||
rb_class2name(data->oklass));
|
||||
}
|
||||
}
|
||||
return mcall(argc-1, argv+1, method, recv);
|
||||
|
||||
method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound);
|
||||
*bound = *data;
|
||||
bound->recv = recv;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -6391,15 +6394,16 @@ Init_Proc()
|
|||
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
|
||||
rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
|
||||
rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
|
||||
rb_define_method(rb_cMethod, "unbound", method_unbound, 0);
|
||||
rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
|
||||
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
|
||||
|
||||
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod);
|
||||
rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1);
|
||||
rb_define_method(rb_cUnboundMethod, "[]", umethod_call, -1);
|
||||
rb_define_method(rb_cUnboundMethod, "to_proc", umethod_proc, 0);
|
||||
rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
|
||||
rb_define_method(rb_cUnboundMethod, "unbind", umethod_unbind, 0);
|
||||
rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1);
|
||||
rb_define_method(rb_cMethod, "unbound", umethod_unbound, 0);
|
||||
}
|
||||
|
||||
static VALUE rb_eThreadError;
|
||||
|
|
|
@ -404,6 +404,10 @@ archdir = $(pkglibdir)/@arch@
|
|||
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
||||
$objs.push f
|
||||
end
|
||||
else
|
||||
for i in $objs
|
||||
i.sub!(/\.o\z/, ".#{$OBJEXT}")
|
||||
end
|
||||
end
|
||||
mfile.printf $objs.join(" ")
|
||||
mfile.printf "\n"
|
||||
|
@ -485,7 +489,7 @@ $(DLLIB): $(OBJS)
|
|||
dfile = open("#{$srcdir}/depend", "r")
|
||||
mfile.printf "###\n"
|
||||
while line = dfile.gets()
|
||||
line.gsub!(/\.o/, ".#{$OBJEXT}")
|
||||
line.gsub!(/\.o\b/, ".#{$OBJEXT}")
|
||||
mfile.printf "%s", line.gsub('\$\(hdrdir\)/config.h', '$(topdir)/config.h')
|
||||
end
|
||||
dfile.close
|
||||
|
|
5
gc.c
5
gc.c
|
@ -1171,10 +1171,9 @@ run_final(obj)
|
|||
VALUE obj;
|
||||
{
|
||||
int i, status;
|
||||
VALUE id, args[2], table;
|
||||
VALUE args[2], table;
|
||||
|
||||
id = rb_obj_id(obj); /* make obj into id */
|
||||
args[1] = rb_ary_new3(1, id);
|
||||
args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */
|
||||
for (i=0; i<RARRAY(finalizers)->len; i++) {
|
||||
args[0] = RARRAY(finalizers)->ptr[i];
|
||||
rb_protect(run_single_final, (VALUE)args, &status);
|
||||
|
|
24
hash.c
24
hash.c
|
@ -264,27 +264,6 @@ rb_hash_clone(hash)
|
|||
return (VALUE)clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_hash_dup(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
VALUE klass = CLASS_OF(hash);
|
||||
|
||||
NEWOBJ(dup, struct RHash);
|
||||
while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
|
||||
klass = (VALUE)RCLASS(klass)->super;
|
||||
}
|
||||
OBJSETUP(dup, klass, T_HASH);
|
||||
|
||||
dup->iter_lev = 0;
|
||||
dup->ifnone = RHASH(hash)->ifnone;
|
||||
dup->tbl = 0; /* avoid GC crashing */
|
||||
dup->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
|
||||
|
||||
if (OBJ_TAINTED(hash)) OBJ_TAINT(dup);
|
||||
return (VALUE)dup;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
to_hash(hash)
|
||||
VALUE hash;
|
||||
|
@ -489,7 +468,7 @@ static VALUE
|
|||
rb_hash_reject(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
return rb_hash_delete_if(rb_hash_dup(hash));
|
||||
return rb_hash_delete_if(rb_obj_dup(hash));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1417,7 +1396,6 @@ Init_Hash()
|
|||
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
|
||||
|
||||
rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
|
||||
rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);
|
||||
rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
|
||||
|
||||
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
|
||||
|
|
1
intern.h
1
intern.h
|
@ -220,6 +220,7 @@ VALUE rb_obj_is_instance_of _((VALUE, VALUE));
|
|||
VALUE rb_obj_is_kind_of _((VALUE, VALUE));
|
||||
VALUE rb_obj_alloc _((VALUE));
|
||||
VALUE rb_obj_clone _((VALUE));
|
||||
VALUE rb_obj_dup _((VALUE));
|
||||
VALUE rb_obj_taint _((VALUE));
|
||||
VALUE rb_obj_tainted _((VALUE));
|
||||
VALUE rb_obj_untaint _((VALUE));
|
||||
|
|
11
io.c
11
io.c
|
@ -1793,7 +1793,7 @@ io_reopen(io, nfile)
|
|||
fd = fileno(fptr->f);
|
||||
if (fd < 3) {
|
||||
clearerr(fptr->f);
|
||||
/* need to keep stdio */
|
||||
/* need to keep stdio objects */
|
||||
if (dup2(fileno(orig->f), fd) < 0)
|
||||
rb_sys_fail(orig->path);
|
||||
}
|
||||
|
@ -1802,10 +1802,10 @@ io_reopen(io, nfile)
|
|||
if (dup2(fileno(orig->f), fd) < 0)
|
||||
rb_sys_fail(orig->path);
|
||||
fptr->f = rb_fdopen(fd, mode);
|
||||
if (orig->mode & FMODE_READABLE && pos >= 0) {
|
||||
fseek(fptr->f, pos, SEEK_SET);
|
||||
fseek(orig->f, pos, SEEK_SET);
|
||||
}
|
||||
}
|
||||
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
||||
fseek(fptr->f, pos, SEEK_SET);
|
||||
fseek(orig->f, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
if (fptr->f2) {
|
||||
|
@ -1887,6 +1887,7 @@ static VALUE
|
|||
rb_io_clone(io)
|
||||
VALUE io;
|
||||
{
|
||||
VALUE klass;
|
||||
OpenFile *fptr, *orig;
|
||||
int fd;
|
||||
char *mode;
|
||||
|
|
|
@ -365,6 +365,10 @@ def create_makefile(target)
|
|||
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
||||
$objs.push f
|
||||
end
|
||||
else
|
||||
for i in $objs
|
||||
i.sub!(/\.o\z/, ".#{$OBJEXT}")
|
||||
end
|
||||
end
|
||||
$objs = $objs.join(" ")
|
||||
|
||||
|
@ -459,7 +463,7 @@ EOMF
|
|||
dfile = open("depend", "r")
|
||||
mfile.printf "###\n"
|
||||
while line = dfile.gets()
|
||||
mfile.printf "%s", line.gsub(/\.o/, ".#{$OBJEXT}")
|
||||
mfile.printf "%s", line.gsub(/\.o\b/, ".#{$OBJEXT}")
|
||||
end
|
||||
dfile.close
|
||||
end
|
||||
|
|
|
@ -18,33 +18,33 @@ class WeakRef<Delegator
|
|||
|
||||
ID_MAP = {} # obj -> [ref,...]
|
||||
ID_REV_MAP = {} # ref -> obj
|
||||
ObjectSpace.add_finalizer(lambda{|id|
|
||||
__old_status = Thread.critical
|
||||
Thread.critical = true
|
||||
begin
|
||||
rids = ID_MAP[id]
|
||||
if rids
|
||||
for rid in rids
|
||||
ID_REV_MAP[rid] = nil
|
||||
end
|
||||
ID_MAP[id] = nil
|
||||
end
|
||||
rid = ID_REV_MAP[id]
|
||||
if rid
|
||||
ID_REV_MAP[id] = nil
|
||||
ID_MAP[rid].delete(id)
|
||||
ID_MAP[rid] = nil if ID_MAP[rid].empty?
|
||||
end
|
||||
ensure
|
||||
Thread.critical = __old_status
|
||||
end
|
||||
})
|
||||
@@final = lambda{|id|
|
||||
__old_status = Thread.critical
|
||||
Thread.critical = true
|
||||
begin
|
||||
rids = ID_MAP[id]
|
||||
if rids
|
||||
for rid in rids
|
||||
ID_REV_MAP[rid] = nil
|
||||
end
|
||||
ID_MAP[id] = nil
|
||||
end
|
||||
rid = ID_REV_MAP[id]
|
||||
if rid
|
||||
ID_REV_MAP[id] = nil
|
||||
ID_MAP[rid].delete(id)
|
||||
ID_MAP[rid] = nil if ID_MAP[rid].empty?
|
||||
end
|
||||
ensure
|
||||
Thread.critical = __old_status
|
||||
end
|
||||
}
|
||||
|
||||
def initialize(orig)
|
||||
super
|
||||
@__id = orig.__id__
|
||||
ObjectSpace.call_finalizer orig
|
||||
ObjectSpace.call_finalizer self
|
||||
ObjectSpace.define_finalizer orig, @@final
|
||||
ObjectSpace.defin_finalizer self, @@final
|
||||
ID_MAP[@__id] = [] unless ID_MAP[@__id]
|
||||
ID_MAP[@__id].push self.__id__
|
||||
ID_REV_MAP[self.id] = @__id
|
||||
|
@ -64,10 +64,6 @@ class WeakRef<Delegator
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
def []
|
||||
__getobj__
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
|
|
53
object.c
53
object.c
|
@ -32,6 +32,7 @@ VALUE rb_obj_alloc();
|
|||
|
||||
static ID eq, eql;
|
||||
static ID inspect;
|
||||
static ID clone;
|
||||
|
||||
VALUE
|
||||
rb_equal(obj1, obj2)
|
||||
|
@ -41,16 +42,15 @@ rb_equal(obj1, obj2)
|
|||
|
||||
if (obj1 == obj2) return Qtrue;
|
||||
result = rb_funcall(obj1, eq, 1, obj2);
|
||||
if (result == Qfalse || NIL_P(result))
|
||||
return Qfalse;
|
||||
return Qtrue;
|
||||
if (RTEST(result)) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
int
|
||||
rb_eql(obj1, obj2)
|
||||
VALUE obj1, obj2;
|
||||
{
|
||||
return rb_funcall(obj1, eql, 1, obj2) == Qtrue;
|
||||
return RTEST(rb_funcall(obj1, eql, 1, obj2));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -61,21 +61,14 @@ rb_obj_equal(obj1, obj2)
|
|||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_obj_hash(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
return ((long)obj)|FIXNUM_FLAG;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_obj_id(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
if (rb_special_const_p(obj)) {
|
||||
if (SPECIAL_CONST_P(obj)) {
|
||||
return INT2NUM((long)obj);
|
||||
}
|
||||
return (long)obj|FIXNUM_FLAG;
|
||||
return (VALUE)((long)obj|FIXNUM_FLAG);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -109,24 +102,21 @@ rb_obj_clone(obj)
|
|||
return clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
VALUE
|
||||
rb_obj_dup(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
if (TYPE(obj) == T_OBJECT) {
|
||||
VALUE klass = CLASS_OF(obj);
|
||||
VALUE dup;
|
||||
VALUE dup;
|
||||
|
||||
while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
|
||||
klass = (VALUE)RCLASS(klass)->super;
|
||||
}
|
||||
dup = rb_obj_alloc(klass);
|
||||
if (ROBJECT(obj)->iv_tbl) {
|
||||
ROBJECT(dup)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl);
|
||||
}
|
||||
return dup;
|
||||
dup = rb_funcall(obj, clone, 0, 0);
|
||||
if (TYPE(dup) != TYPE(obj)) {
|
||||
rb_raise(rb_eTypeError, "dupulicated object must be same type");
|
||||
}
|
||||
return rb_funcall(obj, rb_intern("clone"), 0, 0);
|
||||
if (!SPECIAL_CONST_P(dup)) {
|
||||
OBJSETUP(dup, rb_obj_type(obj), BUILTIN_TYPE(obj));
|
||||
OBJ_INFECT(dup, obj);
|
||||
}
|
||||
return dup;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -226,8 +216,6 @@ VALUE
|
|||
rb_obj_is_instance_of(obj, c)
|
||||
VALUE obj, c;
|
||||
{
|
||||
VALUE cl;
|
||||
|
||||
switch (TYPE(c)) {
|
||||
case T_MODULE:
|
||||
case T_CLASS:
|
||||
|
@ -250,11 +238,7 @@ rb_obj_is_instance_of(obj, c)
|
|||
rb_raise(rb_eTypeError, "class or module required");
|
||||
}
|
||||
|
||||
cl = CLASS_OF(obj);
|
||||
while (FL_TEST(cl, FL_SINGLETON) || TYPE(cl) == T_ICLASS) {
|
||||
cl = RCLASS(cl)->super;
|
||||
}
|
||||
if (c == cl) return Qtrue;
|
||||
if (rb_obj_type(obj) == c) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
|
@ -1087,7 +1071,7 @@ Init_Object()
|
|||
|
||||
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
||||
|
||||
rb_define_method(rb_mKernel, "hash", rb_obj_hash, 0);
|
||||
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
|
||||
rb_define_method(rb_mKernel, "id", rb_obj_id, 0);
|
||||
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
|
||||
rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
|
||||
|
@ -1217,4 +1201,5 @@ Init_Object()
|
|||
eq = rb_intern("==");
|
||||
eql = rb_intern("eql?");
|
||||
inspect = rb_intern("inspect");
|
||||
clone = rb_intern("clone");
|
||||
}
|
||||
|
|
|
@ -426,6 +426,7 @@ EXPORTS
|
|||
rb_eql
|
||||
rb_obj_id
|
||||
rb_obj_clone
|
||||
rb_obj_dup
|
||||
rb_any_to_s
|
||||
rb_inspect
|
||||
rb_obj_is_instance_of
|
||||
|
|
Загрузка…
Ссылка в новой задаче