mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
23dd3051c0
commit
448e63d627
13 changed files with 114 additions and 147 deletions
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>
|
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
|
* gc.c (define_final): integrate final.rb features into the
|
||||||
interpreter. define_finalizer and undefine_finalizer was
|
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>
|
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
|
- consistent /, %, divmod
|
||||||
- unbound method object
|
- unbound method object
|
||||||
- integrate final.rb into the core.
|
- integrate final.rb into the core.
|
||||||
* make clone depend on dup
|
|
||||||
* Enumerable#sort_by for Schwartzian transformation
|
* Enumerable#sort_by for Schwartzian transformation
|
||||||
* String#scanf(?)
|
* String#scanf(?)
|
||||||
* Object#fmt(?)
|
* Object#fmt(?)
|
||||||
|
|
28
array.c
28
array.c
|
@ -676,21 +676,6 @@ rb_ary_clone(ary)
|
||||||
return clone;
|
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
|
static VALUE
|
||||||
to_ary(ary)
|
to_ary(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
|
@ -928,7 +913,7 @@ static VALUE
|
||||||
rb_ary_reverse_m(ary)
|
rb_ary_reverse_m(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
return rb_ary_reverse(rb_ary_dup(ary));
|
return rb_ary_reverse(rb_obj_dup(ary));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID cmp;
|
static ID cmp;
|
||||||
|
@ -991,7 +976,7 @@ VALUE
|
||||||
rb_ary_sort(ary)
|
rb_ary_sort(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
ary = rb_ary_dup(ary);
|
ary = rb_obj_dup(ary);
|
||||||
rb_ary_sort_bang(ary);
|
rb_ary_sort_bang(ary);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +989,7 @@ rb_ary_collect(ary)
|
||||||
VALUE collect;
|
VALUE collect;
|
||||||
|
|
||||||
if (!rb_block_given_p()) {
|
if (!rb_block_given_p()) {
|
||||||
return rb_ary_dup(ary);
|
return rb_obj_dup(ary);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = RARRAY(ary)->len;
|
len = RARRAY(ary)->len;
|
||||||
|
@ -1492,7 +1477,7 @@ static VALUE
|
||||||
rb_ary_uniq(ary)
|
rb_ary_uniq(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
ary = rb_ary_dup(ary);
|
ary = rb_obj_dup(ary);
|
||||||
rb_ary_uniq_bang(ary);
|
rb_ary_uniq_bang(ary);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
@ -1523,7 +1508,7 @@ static VALUE
|
||||||
rb_ary_compact(ary)
|
rb_ary_compact(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
ary = rb_ary_dup(ary);
|
ary = rb_obj_dup(ary);
|
||||||
rb_ary_compact_bang(ary);
|
rb_ary_compact_bang(ary);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
@ -1582,7 +1567,7 @@ static VALUE
|
||||||
rb_ary_flatten(ary)
|
rb_ary_flatten(ary)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
ary = rb_ary_dup(ary);
|
ary = rb_obj_dup(ary);
|
||||||
rb_ary_flatten_bang(ary);
|
rb_ary_flatten_bang(ary);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
@ -1629,7 +1614,6 @@ Init_Array()
|
||||||
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
|
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, "indices", rb_ary_indexes, -1);
|
||||||
rb_define_method(rb_cArray, "clone", rb_ary_clone, 0);
|
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, "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_m, 0);
|
||||||
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse, 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 init, eqq, each, aref, aset, match, missing, added, singleton_added;
|
||||||
|
static ID __id__, __send__;
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_attr(klass, id, read, write, ex)
|
rb_attr(klass, id, read, write, ex)
|
||||||
|
@ -2786,6 +2787,10 @@ rb_eval(self, n)
|
||||||
if (ruby_class == rb_cObject && node->nd_mid == init) {
|
if (ruby_class == rb_cObject && node->nd_mid == init) {
|
||||||
rb_warn("re-defining Object#initialize may cause infinite loop");
|
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);
|
frozen_class_p(ruby_class);
|
||||||
body = search_method(ruby_class, node->nd_mid, &origin);
|
body = search_method(ruby_class, node->nd_mid, &origin);
|
||||||
if (body){
|
if (body){
|
||||||
|
@ -2794,7 +2799,7 @@ rb_eval(self, n)
|
||||||
}
|
}
|
||||||
rb_clear_cache_by_id(node->nd_mid);
|
rb_clear_cache_by_id(node->nd_mid);
|
||||||
if (node->nd_noex) { /* toplevel */
|
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_warning("overriding global function `%s'",
|
||||||
rb_id2name(node->nd_mid));
|
rb_id2name(node->nd_mid));
|
||||||
}
|
}
|
||||||
|
@ -5509,6 +5514,9 @@ Init_eval()
|
||||||
added = rb_intern("method_added");
|
added = rb_intern("method_added");
|
||||||
singleton_added = rb_intern("singleton_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*)&top_scope);
|
||||||
rb_global_variable((VALUE*)&ruby_eval_tree_begin);
|
rb_global_variable((VALUE*)&ruby_eval_tree_begin);
|
||||||
|
|
||||||
|
@ -6131,7 +6139,7 @@ mnew(klass, obj, id, mklass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
method_unbound(obj)
|
method_unbind(obj)
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
VALUE method;
|
VALUE method;
|
||||||
|
@ -6140,18 +6148,18 @@ method_unbound(obj)
|
||||||
Data_Get_Struct(obj, struct METHOD, orig);
|
Data_Get_Struct(obj, struct METHOD, orig);
|
||||||
method = Data_Make_Struct(rb_cUnboundMethod, struct METHOD, bm_mark, free, data);
|
method = Data_Make_Struct(rb_cUnboundMethod, struct METHOD, bm_mark, free, data);
|
||||||
data->klass = orig->klass;
|
data->klass = orig->klass;
|
||||||
data->recv = 0;
|
data->recv = obj;
|
||||||
data->id = orig->id;
|
data->id = orig->id;
|
||||||
data->body = orig->body;
|
data->body = orig->body;
|
||||||
data->oklass = orig->oklass;
|
data->oklass = orig->oklass;
|
||||||
data->oid = orig->oid;
|
data->oid = orig->oid;
|
||||||
OBJ_INFECT(method, orig->klass);
|
OBJ_INFECT(method, obj);
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
umethod_unbound(obj)
|
umethod_unbind(obj)
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -6189,10 +6197,10 @@ method_clone(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
mcall(argc, argv, method, recv)
|
method_call(argc, argv, method)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
VALUE method, recv;
|
VALUE method;
|
||||||
{
|
{
|
||||||
VALUE result;
|
VALUE result;
|
||||||
struct METHOD *data;
|
struct METHOD *data;
|
||||||
|
@ -6206,7 +6214,7 @@ mcall(argc, argv, method, recv)
|
||||||
if (ruby_safe_level < 4) ruby_safe_level = 4;
|
if (ruby_safe_level < 4) ruby_safe_level = 4;
|
||||||
}
|
}
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
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_TAG();
|
||||||
POP_ITER();
|
POP_ITER();
|
||||||
|
@ -6215,32 +6223,22 @@ mcall(argc, argv, method, recv)
|
||||||
return result;
|
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
|
static VALUE
|
||||||
umethod_call(argc, argv, method)
|
umethod_call(argc, argv, method)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
VALUE method;
|
VALUE method;
|
||||||
{
|
{
|
||||||
struct METHOD *data;
|
rb_raise(rb_eTypeError, "you cannot call unbound method; bind first");
|
||||||
VALUE recv;
|
return Qnil; /* not reached */
|
||||||
|
|
||||||
if (argc < 1) {
|
|
||||||
rb_raise(rb_eArgError, "wrong # of arguments");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = argv[0];
|
static VALUE
|
||||||
|
umethod_bind(method, recv)
|
||||||
|
VALUE method, recv;
|
||||||
|
{
|
||||||
|
struct METHOD *data, *bound;
|
||||||
|
|
||||||
Data_Get_Struct(method, struct METHOD, data);
|
Data_Get_Struct(method, struct METHOD, data);
|
||||||
if (data->oklass != CLASS_OF(recv)) {
|
if (data->oklass != CLASS_OF(recv)) {
|
||||||
if (FL_TEST(data->oklass, FL_SINGLETON)) {
|
if (FL_TEST(data->oklass, FL_SINGLETON)) {
|
||||||
|
@ -6255,7 +6253,12 @@ umethod_call(argc, argv, method)
|
||||||
rb_class2name(data->oklass));
|
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
|
static VALUE
|
||||||
|
@ -6391,15 +6394,16 @@ Init_Proc()
|
||||||
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
|
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_s", method_inspect, 0);
|
||||||
rb_define_method(rb_cMethod, "to_proc", method_proc, 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_define_method(rb_mKernel, "method", rb_obj_method, 1);
|
||||||
|
|
||||||
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod);
|
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod);
|
||||||
rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1);
|
rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1);
|
||||||
rb_define_method(rb_cUnboundMethod, "[]", 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, "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_cModule, "instance_method", rb_mod_method, 1);
|
||||||
rb_define_method(rb_cMethod, "unbound", umethod_unbound, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE rb_eThreadError;
|
static VALUE rb_eThreadError;
|
||||||
|
|
|
@ -404,6 +404,10 @@ archdir = $(pkglibdir)/@arch@
|
||||||
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
||||||
$objs.push f
|
$objs.push f
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
for i in $objs
|
||||||
|
i.sub!(/\.o\z/, ".#{$OBJEXT}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
mfile.printf $objs.join(" ")
|
mfile.printf $objs.join(" ")
|
||||||
mfile.printf "\n"
|
mfile.printf "\n"
|
||||||
|
@ -485,7 +489,7 @@ $(DLLIB): $(OBJS)
|
||||||
dfile = open("#{$srcdir}/depend", "r")
|
dfile = open("#{$srcdir}/depend", "r")
|
||||||
mfile.printf "###\n"
|
mfile.printf "###\n"
|
||||||
while line = dfile.gets()
|
while line = dfile.gets()
|
||||||
line.gsub!(/\.o/, ".#{$OBJEXT}")
|
line.gsub!(/\.o\b/, ".#{$OBJEXT}")
|
||||||
mfile.printf "%s", line.gsub('\$\(hdrdir\)/config.h', '$(topdir)/config.h')
|
mfile.printf "%s", line.gsub('\$\(hdrdir\)/config.h', '$(topdir)/config.h')
|
||||||
end
|
end
|
||||||
dfile.close
|
dfile.close
|
||||||
|
|
5
gc.c
5
gc.c
|
@ -1171,10 +1171,9 @@ run_final(obj)
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
int i, status;
|
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, rb_obj_id(obj)); /* make obj into id */
|
||||||
args[1] = rb_ary_new3(1, id);
|
|
||||||
for (i=0; i<RARRAY(finalizers)->len; i++) {
|
for (i=0; i<RARRAY(finalizers)->len; i++) {
|
||||||
args[0] = RARRAY(finalizers)->ptr[i];
|
args[0] = RARRAY(finalizers)->ptr[i];
|
||||||
rb_protect(run_single_final, (VALUE)args, &status);
|
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;
|
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
|
static VALUE
|
||||||
to_hash(hash)
|
to_hash(hash)
|
||||||
VALUE hash;
|
VALUE hash;
|
||||||
|
@ -489,7 +468,7 @@ static VALUE
|
||||||
rb_hash_reject(hash)
|
rb_hash_reject(hash)
|
||||||
VALUE hash;
|
VALUE hash;
|
||||||
{
|
{
|
||||||
return rb_hash_delete_if(rb_hash_dup(hash));
|
return rb_hash_delete_if(rb_obj_dup(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1417,7 +1396,6 @@ Init_Hash()
|
||||||
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
|
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,"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,"rehash", rb_hash_rehash, 0);
|
||||||
|
|
||||||
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 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_is_kind_of _((VALUE, VALUE));
|
||||||
VALUE rb_obj_alloc _((VALUE));
|
VALUE rb_obj_alloc _((VALUE));
|
||||||
VALUE rb_obj_clone _((VALUE));
|
VALUE rb_obj_clone _((VALUE));
|
||||||
|
VALUE rb_obj_dup _((VALUE));
|
||||||
VALUE rb_obj_taint _((VALUE));
|
VALUE rb_obj_taint _((VALUE));
|
||||||
VALUE rb_obj_tainted _((VALUE));
|
VALUE rb_obj_tainted _((VALUE));
|
||||||
VALUE rb_obj_untaint _((VALUE));
|
VALUE rb_obj_untaint _((VALUE));
|
||||||
|
|
7
io.c
7
io.c
|
@ -1793,7 +1793,7 @@ io_reopen(io, nfile)
|
||||||
fd = fileno(fptr->f);
|
fd = fileno(fptr->f);
|
||||||
if (fd < 3) {
|
if (fd < 3) {
|
||||||
clearerr(fptr->f);
|
clearerr(fptr->f);
|
||||||
/* need to keep stdio */
|
/* need to keep stdio objects */
|
||||||
if (dup2(fileno(orig->f), fd) < 0)
|
if (dup2(fileno(orig->f), fd) < 0)
|
||||||
rb_sys_fail(orig->path);
|
rb_sys_fail(orig->path);
|
||||||
}
|
}
|
||||||
|
@ -1802,11 +1802,11 @@ io_reopen(io, nfile)
|
||||||
if (dup2(fileno(orig->f), fd) < 0)
|
if (dup2(fileno(orig->f), fd) < 0)
|
||||||
rb_sys_fail(orig->path);
|
rb_sys_fail(orig->path);
|
||||||
fptr->f = rb_fdopen(fd, mode);
|
fptr->f = rb_fdopen(fd, mode);
|
||||||
if (orig->mode & FMODE_READABLE && pos >= 0) {
|
}
|
||||||
|
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
||||||
fseek(fptr->f, pos, SEEK_SET);
|
fseek(fptr->f, pos, SEEK_SET);
|
||||||
fseek(orig->f, pos, SEEK_SET);
|
fseek(orig->f, pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (fptr->f2) {
|
if (fptr->f2) {
|
||||||
fd = fileno(fptr->f2);
|
fd = fileno(fptr->f2);
|
||||||
|
@ -1887,6 +1887,7 @@ static VALUE
|
||||||
rb_io_clone(io)
|
rb_io_clone(io)
|
||||||
VALUE io;
|
VALUE io;
|
||||||
{
|
{
|
||||||
|
VALUE klass;
|
||||||
OpenFile *fptr, *orig;
|
OpenFile *fptr, *orig;
|
||||||
int fd;
|
int fd;
|
||||||
char *mode;
|
char *mode;
|
||||||
|
|
|
@ -365,6 +365,10 @@ def create_makefile(target)
|
||||||
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
||||||
$objs.push f
|
$objs.push f
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
for i in $objs
|
||||||
|
i.sub!(/\.o\z/, ".#{$OBJEXT}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
$objs = $objs.join(" ")
|
$objs = $objs.join(" ")
|
||||||
|
|
||||||
|
@ -459,7 +463,7 @@ EOMF
|
||||||
dfile = open("depend", "r")
|
dfile = open("depend", "r")
|
||||||
mfile.printf "###\n"
|
mfile.printf "###\n"
|
||||||
while line = dfile.gets()
|
while line = dfile.gets()
|
||||||
mfile.printf "%s", line.gsub(/\.o/, ".#{$OBJEXT}")
|
mfile.printf "%s", line.gsub(/\.o\b/, ".#{$OBJEXT}")
|
||||||
end
|
end
|
||||||
dfile.close
|
dfile.close
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WeakRef<Delegator
|
||||||
|
|
||||||
ID_MAP = {} # obj -> [ref,...]
|
ID_MAP = {} # obj -> [ref,...]
|
||||||
ID_REV_MAP = {} # ref -> obj
|
ID_REV_MAP = {} # ref -> obj
|
||||||
ObjectSpace.add_finalizer(lambda{|id|
|
@@final = lambda{|id|
|
||||||
__old_status = Thread.critical
|
__old_status = Thread.critical
|
||||||
Thread.critical = true
|
Thread.critical = true
|
||||||
begin
|
begin
|
||||||
|
@ -38,13 +38,13 @@ class WeakRef<Delegator
|
||||||
ensure
|
ensure
|
||||||
Thread.critical = __old_status
|
Thread.critical = __old_status
|
||||||
end
|
end
|
||||||
})
|
}
|
||||||
|
|
||||||
def initialize(orig)
|
def initialize(orig)
|
||||||
super
|
super
|
||||||
@__id = orig.__id__
|
@__id = orig.__id__
|
||||||
ObjectSpace.call_finalizer orig
|
ObjectSpace.define_finalizer orig, @@final
|
||||||
ObjectSpace.call_finalizer self
|
ObjectSpace.defin_finalizer self, @@final
|
||||||
ID_MAP[@__id] = [] unless ID_MAP[@__id]
|
ID_MAP[@__id] = [] unless ID_MAP[@__id]
|
||||||
ID_MAP[@__id].push self.__id__
|
ID_MAP[@__id].push self.__id__
|
||||||
ID_REV_MAP[self.id] = @__id
|
ID_REV_MAP[self.id] = @__id
|
||||||
|
@ -64,10 +64,6 @@ class WeakRef<Delegator
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def []
|
|
||||||
__getobj__
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
|
|
45
object.c
45
object.c
|
@ -32,6 +32,7 @@ VALUE rb_obj_alloc();
|
||||||
|
|
||||||
static ID eq, eql;
|
static ID eq, eql;
|
||||||
static ID inspect;
|
static ID inspect;
|
||||||
|
static ID clone;
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_equal(obj1, obj2)
|
rb_equal(obj1, obj2)
|
||||||
|
@ -41,16 +42,15 @@ rb_equal(obj1, obj2)
|
||||||
|
|
||||||
if (obj1 == obj2) return Qtrue;
|
if (obj1 == obj2) return Qtrue;
|
||||||
result = rb_funcall(obj1, eq, 1, obj2);
|
result = rb_funcall(obj1, eq, 1, obj2);
|
||||||
if (result == Qfalse || NIL_P(result))
|
if (RTEST(result)) return Qtrue;
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_eql(obj1, obj2)
|
rb_eql(obj1, obj2)
|
||||||
VALUE obj1, obj2;
|
VALUE obj1, obj2;
|
||||||
{
|
{
|
||||||
return rb_funcall(obj1, eql, 1, obj2) == Qtrue;
|
return RTEST(rb_funcall(obj1, eql, 1, obj2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -61,21 +61,14 @@ rb_obj_equal(obj1, obj2)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_obj_hash(obj)
|
|
||||||
VALUE obj;
|
|
||||||
{
|
|
||||||
return ((long)obj)|FIXNUM_FLAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_obj_id(obj)
|
rb_obj_id(obj)
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
if (rb_special_const_p(obj)) {
|
if (SPECIAL_CONST_P(obj)) {
|
||||||
return INT2NUM((long)obj);
|
return INT2NUM((long)obj);
|
||||||
}
|
}
|
||||||
return (long)obj|FIXNUM_FLAG;
|
return (VALUE)((long)obj|FIXNUM_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -109,25 +102,22 @@ rb_obj_clone(obj)
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
rb_obj_dup(obj)
|
rb_obj_dup(obj)
|
||||||
VALUE 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)) {
|
dup = rb_funcall(obj, clone, 0, 0);
|
||||||
klass = (VALUE)RCLASS(klass)->super;
|
if (TYPE(dup) != TYPE(obj)) {
|
||||||
|
rb_raise(rb_eTypeError, "dupulicated object must be same type");
|
||||||
}
|
}
|
||||||
dup = rb_obj_alloc(klass);
|
if (!SPECIAL_CONST_P(dup)) {
|
||||||
if (ROBJECT(obj)->iv_tbl) {
|
OBJSETUP(dup, rb_obj_type(obj), BUILTIN_TYPE(obj));
|
||||||
ROBJECT(dup)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl);
|
OBJ_INFECT(dup, obj);
|
||||||
}
|
}
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
return rb_funcall(obj, rb_intern("clone"), 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_any_to_a(obj)
|
rb_any_to_a(obj)
|
||||||
|
@ -226,8 +216,6 @@ VALUE
|
||||||
rb_obj_is_instance_of(obj, c)
|
rb_obj_is_instance_of(obj, c)
|
||||||
VALUE obj, c;
|
VALUE obj, c;
|
||||||
{
|
{
|
||||||
VALUE cl;
|
|
||||||
|
|
||||||
switch (TYPE(c)) {
|
switch (TYPE(c)) {
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
|
@ -250,11 +238,7 @@ rb_obj_is_instance_of(obj, c)
|
||||||
rb_raise(rb_eTypeError, "class or module required");
|
rb_raise(rb_eTypeError, "class or module required");
|
||||||
}
|
}
|
||||||
|
|
||||||
cl = CLASS_OF(obj);
|
if (rb_obj_type(obj) == c) return Qtrue;
|
||||||
while (FL_TEST(cl, FL_SINGLETON) || TYPE(cl) == T_ICLASS) {
|
|
||||||
cl = RCLASS(cl)->super;
|
|
||||||
}
|
|
||||||
if (c == cl) return Qtrue;
|
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1087,7 +1071,7 @@ Init_Object()
|
||||||
|
|
||||||
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
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, "__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);
|
rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
|
||||||
|
@ -1217,4 +1201,5 @@ Init_Object()
|
||||||
eq = rb_intern("==");
|
eq = rb_intern("==");
|
||||||
eql = rb_intern("eql?");
|
eql = rb_intern("eql?");
|
||||||
inspect = rb_intern("inspect");
|
inspect = rb_intern("inspect");
|
||||||
|
clone = rb_intern("clone");
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,6 +426,7 @@ EXPORTS
|
||||||
rb_eql
|
rb_eql
|
||||||
rb_obj_id
|
rb_obj_id
|
||||||
rb_obj_clone
|
rb_obj_clone
|
||||||
|
rb_obj_dup
|
||||||
rb_any_to_s
|
rb_any_to_s
|
||||||
rb_inspect
|
rb_inspect
|
||||||
rb_obj_is_instance_of
|
rb_obj_is_instance_of
|
||||||
|
|
Loading…
Add table
Reference in a new issue