Skip to content

Commit b0faee9

Browse files
author
matz
committed
clone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 3f8dd52 commit b0faee9

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ VALUE rb_f_untrace_var _((int, VALUE*));
309309
VALUE rb_gvar_set2 _((const char*, VALUE));
310310
VALUE rb_f_global_variables _((void));
311311
void rb_alias_variable _((ID, ID));
312+
void rb_clone_generic_ivar _((VALUE,VALUE));
312313
void rb_mark_generic_ivar _((VALUE));
313314
void rb_mark_generic_ivar_tbl _((void));
314315
void rb_free_generic_ivar _((VALUE));

io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ rb_io_clone(io)
17721772
char *mode;
17731773

17741774
NEWOBJ(obj, struct RFile);
1775-
OBJSETUP(obj, CLASS_OF(io), T_FILE);
1775+
CLONESETUP(obj, io);
17761776

17771777
GetOpenFile(io, orig);
17781778
MakeOpenFile(obj, fptr);

ruby.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ VALUE rb_newobj _((void));
209209
RBASIC(obj)->flags = (t);\
210210
if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT);\
211211
}
212-
#define CLONESETUP(clone,obj) {\
212+
#define CLONESETUP(clone,obj) do {\
213213
OBJSETUP(clone,rb_singleton_class_clone(RBASIC(obj)->klass),RBASIC(obj)->flags);\
214214
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);\
215-
}
215+
if (FL_TEST(obj, FL_EXIVAR)) rb_clone_generic_ivar((VALUE)clone,(VALUE)obj);\
216+
} while (0)
216217

217218
struct RBasic {
218219
unsigned long flags;

variable.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,9 @@ generic_ivar_set(obj, id, val)
717717
VALUE val;
718718
{
719719
st_table *tbl;
720-
int special = Qfalse;
721720

722721
if (rb_special_const_p(obj)) {
723722
special_generic_ivar = 1;
724-
special = Qtrue;
725723
}
726724
if (!generic_iv_tbl) {
727725
generic_iv_tbl = st_init_numtable();
@@ -771,26 +769,27 @@ generic_ivar_remove(obj, id)
771769
return val;
772770
}
773771

774-
static int
775-
givar_mark_i(key, value)
776-
ID key;
777-
VALUE value;
778-
{
779-
rb_gc_mark(value);
780-
return ST_CONTINUE;
781-
}
782-
783772
void
784773
rb_mark_generic_ivar(obj)
785774
VALUE obj;
786775
{
787776
st_table *tbl;
788777

778+
if (!generic_iv_tbl) return;
789779
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
790780
rb_mark_tbl(tbl);
791781
}
792782
}
793783

784+
static int
785+
givar_mark_i(key, value)
786+
ID key;
787+
VALUE value;
788+
{
789+
rb_gc_mark(value);
790+
return ST_CONTINUE;
791+
}
792+
794793
static int
795794
givar_i(obj, tbl)
796795
VALUE obj;
@@ -805,8 +804,8 @@ givar_i(obj, tbl)
805804
void
806805
rb_mark_generic_ivar_tbl()
807806
{
808-
if (special_generic_ivar == 0) return;
809807
if (!generic_iv_tbl) return;
808+
if (special_generic_ivar == 0) return;
810809
st_foreach(generic_iv_tbl, givar_i, 0);
811810
}
812811

@@ -820,6 +819,18 @@ rb_free_generic_ivar(obj)
820819
st_free_table(tbl);
821820
}
822821

822+
void
823+
rb_clone_generic_ivar(clone, obj)
824+
VALUE clone, obj;
825+
{
826+
st_table *tbl;
827+
828+
if (!generic_iv_tbl) return;
829+
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
830+
st_add_direct(generic_iv_tbl, clone, st_copy(tbl));
831+
}
832+
}
833+
823834
VALUE
824835
rb_ivar_get(obj, id)
825836
VALUE obj;

0 commit comments

Comments
 (0)