Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 225465 | Differences between
and this patch

Collapse All | Expand All

(-)ruby-1.8.6-p230/class.c (-40 / +10 lines)
Lines 48-73 rb_class_new(super) Link Here
48
    return rb_class_boot(super);
48
    return rb_class_boot(super);
49
}
49
}
50
50
51
struct clone_method_data {
52
    st_table *tbl;
53
    VALUE klass;
54
};
55
56
static int
51
static int
57
clone_method(mid, body, data)
52
clone_method(mid, body, tbl)
58
    ID mid;
53
    ID mid;
59
    NODE *body;
54
    NODE *body;
60
    struct clone_method_data *data;
55
    st_table *tbl;
61
{
56
{
62
    NODE *fbody = body->nd_body;
57
    st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
63
64
    if (fbody && nd_type(fbody) == NODE_SCOPE) {
65
	VALUE cref = data->klass ?
66
	    (VALUE)NEW_NODE(NODE_CREF,data->klass,0,fbody->nd_rval) :
67
	    fbody->nd_rval;
68
	fbody = NEW_NODE(NODE_SCOPE, fbody->nd_tbl, cref, fbody->nd_next);
69
    }
70
    st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
71
    return ST_CONTINUE;
58
    return ST_CONTINUE;
72
}
59
}
73
60
Lines 78-85 rb_mod_init_copy(clone, orig) Link Here
78
{
65
{
79
    rb_obj_init_copy(clone, orig);
66
    rb_obj_init_copy(clone, orig);
80
    if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
67
    if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
81
	RBASIC(clone)->klass = RBASIC(orig)->klass;
68
	RBASIC(clone)->klass = rb_singleton_class_clone(orig);
82
	RBASIC(clone)->klass = rb_singleton_class_clone(clone);
83
    }
69
    }
84
    RCLASS(clone)->super = RCLASS(orig)->super;
70
    RCLASS(clone)->super = RCLASS(orig)->super;
85
    if (RCLASS(orig)->iv_tbl) {
71
    if (RCLASS(orig)->iv_tbl) {
Lines 92-103 rb_mod_init_copy(clone, orig) Link Here
92
	st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
78
	st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
93
    }
79
    }
94
    if (RCLASS(orig)->m_tbl) {
80
    if (RCLASS(orig)->m_tbl) {
95
	struct clone_method_data data;
81
	RCLASS(clone)->m_tbl = st_init_numtable();
96
82
	st_foreach(RCLASS(orig)->m_tbl, clone_method,
97
	data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
83
	  (st_data_t)RCLASS(clone)->m_tbl);
98
	data.klass = (VALUE)clone;
99
100
	st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
101
    }
84
    }
102
85
103
    return clone;
86
    return clone;
Lines 143-164 rb_singleton_class_clone(obj) Link Here
143
	if (RCLASS(klass)->iv_tbl) {
126
	if (RCLASS(klass)->iv_tbl) {
144
	    clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
127
	    clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
145
	}
128
	}
146
	{
129
	clone->m_tbl = st_init_numtable();
147
	    struct clone_method_data data;
130
	st_foreach(RCLASS(klass)->m_tbl, clone_method,
148
131
	  (st_data_t)clone->m_tbl);
149
	    data.tbl = clone->m_tbl = st_init_numtable();
150
	    switch (TYPE(obj)) {
151
	      case T_CLASS:
152
	      case T_MODULE:
153
		data.klass = obj;
154
		break;
155
	      default:
156
		data.klass = 0;
157
		break;
158
	    }
159
160
	    st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
161
	}
162
	rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
132
	rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
163
	FL_SET(clone, FL_SINGLETON);
133
	FL_SET(clone, FL_SINGLETON);
164
	return (VALUE)clone;
134
	return (VALUE)clone;

Return to bug 225465