Skip to content

Commit

Permalink
* object.c (copy_object): copy finalizers as well if any.
Browse files Browse the repository at this point in the history
* gc.c (rb_gc_copy_finalizer): new function to copy finalizers.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 4, 2002
1 parent f2bfa4d commit d14560a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .cvsignore
Expand Up @@ -11,7 +11,7 @@ ChangeLog.pre1_1
Makefile
README.fat-patch
README.v6
a.rb
README.atheos
archive
autom4te*.cache
automake
Expand Down
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
Wed Dec 4 16:37:11 2002 Yukihiro Matsumoto <matz@ruby-lang.org>

* object.c (copy_object): copy finalizers as well if any.

* gc.c (rb_gc_copy_finalizer): new function to copy finalizers.

Tue Dec 3 01:13:41 2002 Tanaka Akira <akr@m17n.org>

* lib/pp.rb (PP.singleline_pp): new method.
Expand Down
16 changes: 16 additions & 0 deletions gc.c
Expand Up @@ -1475,6 +1475,22 @@ define_final(argc, argv, os)
return proc;
}

void
rb_gc_copy_finalizer(dest, obj)
VALUE dest, obj;
{
VALUE table;

if (!finalizer_table) return;
if (!FL_TEST(obj, FL_FINALIZE)) return;
if (FL_TEST(dest, FL_FINALIZE)) {
rb_warn("copy_finalizer: descarding old finalizers");
}
if (st_lookup(finalizer_table, obj, &table)) {
st_insert(finalizer_table, dest, table);
}
}

static VALUE
run_single_final(args)
VALUE *args;
Expand Down
1 change: 1 addition & 0 deletions intern.h
Expand Up @@ -220,6 +220,7 @@ void rb_gc_mark_maybe _((VALUE));
void rb_gc_mark _((VALUE));
void rb_gc_force_recycle _((VALUE));
void rb_gc _((void));
void rb_gc_copy_finalizer _((VALUE,VALUE));
void rb_gc_call_finalizer_at_exit _((void));
VALUE rb_gc_enable _((void));
VALUE rb_gc_disable _((void));
Expand Down
1 change: 1 addition & 0 deletions object.c
Expand Up @@ -119,6 +119,7 @@ copy_object(dest, obj)
if (FL_TEST(obj, FL_EXIVAR)) {
rb_copy_generic_ivar(dest, obj);
}
rb_gc_copy_finalizer(dest, obj);
switch (TYPE(obj)) {
case T_OBJECT:
case T_CLASS:
Expand Down
27 changes: 16 additions & 11 deletions pack.c
Expand Up @@ -1850,6 +1850,16 @@ uv_to_utf8(buf, uv)
#endif
}

static const long utf8_limits[] = {
0x0, /* 1 */
0x80, /* 2 */
0x800, /* 3 */
0x1000, /* 4 */
0x200000, /* 5 */
0x4000000, /* 6 */
0x80000000, /* 7 */
};

static unsigned long
utf8_to_uv(p, lenp)
char *p;
Expand Down Expand Up @@ -1882,7 +1892,6 @@ utf8_to_uv(p, lenp)
return 0xfffd;
}
*lenp = n--;

if (n != 0) {
while (n--) {
c = *p++ & 0xff;
Expand All @@ -1893,20 +1902,16 @@ utf8_to_uv(p, lenp)
}
else {
c &= 0x3f;
if (uv == 0 && c == 0) {
int i;

for (i=0; n-i>0 && (p[i] & 0x3f) == 0; i++)
;
rb_warning("redundant UTF-8 sequence (skip %d bytes)", i+1);
n -= i;
p += i;
continue;
}
uv = uv << 6 | c;
}
}
}
n = *lenp - 1;
if (n < 6) {
if (uv < utf8_limits[n] || utf8_limits[n+1] <= uv) {
rb_warning("redundant UTF-8 sequence");
}
}
return uv;
}

Expand Down

0 comments on commit d14560a

Please sign in to comment.