summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--ToDo1
-rw-r--r--array.c28
-rw-r--r--eval.c58
-rw-r--r--ext/extmk.rb.in6
-rw-r--r--gc.c5
-rw-r--r--hash.c24
-rw-r--r--intern.h1
-rw-r--r--io.c11
-rw-r--r--lib/mkmf.rb6
-rw-r--r--lib/weakref.rb50
-rw-r--r--object.c53
-rw-r--r--win32/ruby.def1
13 files changed, 112 insertions, 145 deletions
diff --git a/ChangeLog b/ChangeLog
index 47824482b1b..50dd71eddfc 100644
--- a/ChangeLog
+++ b/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>
diff --git a/ToDo b/ToDo
index b4918d91b75..8af987f091b 100644
--- a/ToDo
+++ b/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(?)
diff --git a/array.c b/array.c
index f2089996e5f..88683334a43 100644
--- a/array.c
+++ b/array.c
@@ -677,21 +677,6 @@ rb_ary_clone(ary)
}
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);
diff --git a/eval.c b/eval.c
index dda4ef33bcd..70051cab9c8 100644
--- a/eval.c
+++ b/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();
@@ -6216,31 +6224,21 @@ mcall(argc, argv, method, recv)
}
static VALUE
-method_call(argc, argv, method)
+umethod_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);
+ rb_raise(rb_eTypeError, "you cannot call unbound method; bind first");
+ return Qnil; /* not reached */
}
static VALUE
-umethod_call(argc, argv, method)
- int argc;
- VALUE *argv;
- VALUE method;
+umethod_bind(method, recv)
+ VALUE method, recv;
{
- struct METHOD *data;
- VALUE recv;
+ struct METHOD *data, *bound;
- if (argc < 1) {
- rb_raise(rb_eArgError, "wrong # of arguments");
- }
-
- 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;
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in
index 4ac7b4ee9b7..dc5eddfab8b 100644
--- a/ext/extmk.rb.in
+++ b/ext/extmk.rb.in
@@ -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
diff --git a/gc.c b/gc.c
index 6a31ee0a1c3..8c7169ed17e 100644
--- a/gc.c
+++ b/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);
diff --git a/hash.c b/hash.c
index 3ecd6a2b04d..630fb4c305a 100644
--- a/hash.c
+++ b/hash.c
@@ -265,27 +265,6 @@ rb_hash_clone(hash)
}
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);
diff --git a/intern.h b/intern.h
index 8f1a78ba94c..fbda2a459b8 100644
--- a/intern.h
+++ b/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));
diff --git a/io.c b/io.c
index f3fd3153236..dabc6805491 100644
--- a/io.c
+++ b/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;
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index c042561e13a..cab2b769a73 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -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
diff --git a/lib/weakref.rb b/lib/weakref.rb
index a6519e64c02..3307a2e5aa8 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -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
diff --git a/object.c b/object.c
index 5ca7624ee13..e4ccf1b7e03 100644
--- a/object.c
+++ b/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");
+ }
+ if (!SPECIAL_CONST_P(dup)) {
+ OBJSETUP(dup, rb_obj_type(obj), BUILTIN_TYPE(obj));
+ OBJ_INFECT(dup, obj);
}
- return rb_funcall(obj, rb_intern("clone"), 0, 0);
+ 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");
}
diff --git a/win32/ruby.def b/win32/ruby.def
index ebb37a0d306..977eb57e3f6 100644
--- a/win32/ruby.def
+++ b/win32/ruby.def
@@ -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