[前][次][番号順一覧][スレッド一覧]

ruby-changes:26836

From: nobu <ko1@a...>
Date: Sun, 20 Jan 2013 23:55:52 +0900 (JST)
Subject: [ruby-changes:26836] nobu:r38888 (trunk): marshal.c: get back to the old behavior

nobu	2013-01-20 23:55:42 +0900 (Sun, 20 Jan 2013)

  New Revision: 38888

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38888

  Log:
    marshal.c: get back to the old behavior
    
    * marshal.c (w_object, r_object0): separate respond_to checks and
      calling, and get back to the old behavior for 2.0.  [Bug #7564]

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38887)
+++ ChangeLog	(revision 38888)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan 20 23:55:37 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (w_object, r_object0): separate respond_to checks and
+	  calling, and get back to the old behavior for 2.0.  [Bug #7564]
+
 Sun Jan 20 22:24:28 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* tool/vpath.rb (VPath#def_options): hack for msys make, which
Index: marshal.c
===================================================================
--- marshal.c	(revision 38887)
+++ marshal.c	(revision 38888)
@@ -587,15 +587,6 @@ w_objivar(VALUE obj, struct dump_call_ar https://github.com/ruby/ruby/blob/trunk/marshal.c#L587
 }
 
 static void
-push_dump_object(int found, VALUE recv, ID mid, int argc, VALUE *argv, VALUE data)
-{
-    if (found) {
-	struct dump_arg *arg = (struct dump_arg *)data;
-	st_add_direct(arg->data, recv, arg->data->num_entries);
-    }
-}
-
-static void
 w_object(VALUE obj, struct dump_arg *arg, int limit)
 {
     struct dump_call_arg c_arg;
@@ -655,8 +646,10 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L646
 
 	arg->infection |= (int)FL_TEST(obj, MARSHAL_INFECTION);
 
-	v = rb_check_funcall_with_hook(obj, s_mdump, 0, 0, push_dump_object, (VALUE)arg);
-	if (v != Qundef) {
+	if (rb_obj_respond_to(obj, s_mdump, TRUE)) {
+	    st_add_direct(arg->data, obj, arg->data->num_entries);
+
+	    v = rb_funcall2(obj, s_mdump, 0, 0);
 	    check_dump_arg(arg, s_mdump);
 	    hasiv = has_ivars(obj, ivtbl);
 	    if (hasiv) w_byte(TYPE_IVAR, arg);
@@ -665,12 +658,12 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L658
 	    if (hasiv) w_ivar(obj, ivtbl, &c_arg);
 	    return;
 	}
-	v = INT2NUM(limit);
-	v = rb_check_funcall(obj, s_dump, 1, &v);
-	if (v != Qundef) {
+	if (rb_obj_respond_to(obj, s_dump, TRUE)) {
             st_table *ivtbl2 = 0;
             int hasiv2;
 
+	    v = INT2NUM(limit);
+	    v = rb_funcall2(obj, s_dump, 1, &v);
 	    check_dump_arg(arg, s_dump);
 	    if (!RB_TYPE_P(v, T_STRING)) {
 		rb_raise(rb_eTypeError, "_dump() must return string");
@@ -840,12 +833,12 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L833
 	    {
 		VALUE v;
 
-		v = rb_check_funcall(obj, s_dump_data, 0, 0);
-		if (v == Qundef) {
+		if (!rb_obj_respond_to(obj, s_dump_data, TRUE)) {
 		    rb_raise(rb_eTypeError,
 			     "no _dump_data is defined for class %s",
 			     rb_obj_classname(obj));
 		}
+		v = rb_funcall2(obj, s_dump_data, 0, 0);
 		check_dump_arg(arg, s_dump_data);
 		w_class(TYPE_DATA, obj, arg, TRUE);
 		w_object(v, arg, limit);
@@ -1033,7 +1026,6 @@ static VALUE r_entry0(VALUE v, st_index_ https://github.com/ruby/ruby/blob/trunk/marshal.c#L1026
 static VALUE r_object(struct load_arg *arg);
 static ID r_symbol(struct load_arg *arg);
 static VALUE path2class(VALUE path);
-static VALUE r_object0(struct load_arg *arg, int *ivp, VALUE extmod);
 
 NORETURN(static void too_short(void));
 static void
@@ -1442,42 +1434,6 @@ append_extmod(VALUE obj, VALUE extmod) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1434
     return obj;
 }
 
-static void
-load_data_hook(int found, VALUE recv, ID mid, int argc, VALUE *argv, VALUE data)
-{
-    if (found) {
-	struct load_arg *arg = (struct load_arg *)((VALUE *)data)[0];
-	VALUE extmod = ((VALUE *)data)[1];
-	*argv = r_object0(arg, 0, extmod);
-    }
-}
-
-static void
-load_userdef_hook(int found, VALUE recv, ID mid, int argc, VALUE *argv, VALUE data)
-{
-    if (found) {
-	struct load_arg *arg = (struct load_arg *)((VALUE *)data)[0];
-	int *ivp = (int *)((VALUE *)data)[1];
-	VALUE r = r_string(arg);
-	if (ivp) {
-	    r_ivar(r, NULL, arg);
-	    *ivp = FALSE;
-	}
-	*argv = r;
-    }
-}
-
-static void
-mload_hook(int found, VALUE recv, ID mid, int argc, VALUE *argv, VALUE data)
-{
-    if (found) {
-	struct load_arg *arg = (struct load_arg *)((VALUE *)data)[0];
-	VALUE v = ((VALUE *)data)[1];
-	r_entry(v, arg);
-	*argv = r_object(arg);
-    }
-}
-
 static VALUE
 r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
 {
@@ -1485,7 +1441,6 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1441
     int type = r_byte(arg);
     long id;
     st_data_t link;
-    VALUE args[2];
 
     switch (type) {
       case TYPE_LINK:
@@ -1763,14 +1718,16 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1718
 	    VALUE klass = path2class(r_unique(arg));
 	    VALUE data;
 
-	    args[0] = (VALUE)arg;
-	    args[1] = (VALUE)ivp;
-	    v = rb_check_funcall_with_hook(klass, s_load, 1, &data,
-					   load_userdef_hook, (VALUE)args);
-	    if (v == Qundef) {
+	    if (!rb_obj_respond_to(klass, s_load, TRUE)) {
 		rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
 			 rb_class2name(klass));
 	    }
+	    data = r_string(arg);
+	    if (ivp) {
+		r_ivar(data, NULL, arg);
+		*ivp = FALSE;
+	    }
+	    v = rb_funcall2(klass, s_load, 1, &data);
 	    check_load_arg(arg, s_load);
 	    v = r_entry(v, arg);
             v = r_leave(v, arg);
@@ -1788,13 +1745,13 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1745
 		/* for the case marshal_load is overridden */
 		append_extmod(v, extmod);
             }
-	    args[0] = (VALUE)arg;
-	    args[1] = v;
-	    data = rb_check_funcall_with_hook(v, s_mload, 1, &data, mload_hook, (VALUE)args);
-	    if (data == Qundef) {
+	    if (!rb_obj_respond_to(v, s_mload, TRUE)) {
 		rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
 			 rb_class2name(klass));
 	    }
+	    v = r_entry(v, arg);
+	    data = r_object(arg);
+	    rb_funcall2(v, s_mload, 1, &data);
 	    check_load_arg(arg, s_mload);
             v = r_leave(v, arg);
 	    if (!NIL_P(extmod)) {
@@ -1828,14 +1785,13 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1785
 		rb_raise(rb_eArgError, "dump format error");
 	    }
 	    v = r_entry(v, arg);
-	    args[0] = (VALUE)arg;
-	    args[1] = extmod;
-	    r = rb_check_funcall_with_hook(v, s_load_data, 1, &r, load_data_hook, (VALUE)args);
-	    if (r == Qundef) {
+	    if (!rb_obj_respond_to(v, s_load_data, TRUE)) {
 		rb_raise(rb_eTypeError,
 			 "class %s needs to have instance method `_load_data'",
 			 rb_class2name(klass));
 	    }
+	    r = r_object0(arg, 0, extmod);
+	    rb_funcall2(v, s_load_data, 1, &r);
 	    check_load_arg(arg, s_load_data);
 	    v = r_leave(v, arg);
 	}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]