[macruby-changes] [2873] MacRuby/trunk/re.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 20 20:16:52 PDT 2009


Revision: 2873
          http://trac.macosforge.org/projects/ruby/changeset/2873
Author:   lsansonetti at apple.com
Date:     2009-10-20 20:16:49 -0700 (Tue, 20 Oct 2009)
Log Message:
-----------
do not leak Regexp objects

Modified Paths:
--------------
    MacRuby/trunk/re.c

Modified: MacRuby/trunk/re.c
===================================================================
--- MacRuby/trunk/re.c	2009-10-21 00:38:16 UTC (rev 2872)
+++ MacRuby/trunk/re.c	2009-10-21 03:16:49 UTC (rev 2873)
@@ -15,6 +15,7 @@
 #include "ruby/encoding.h"
 #include "ruby/util.h"
 #include "regint.h"
+#include "objc.h"
 #include <ctype.h>
 
 VALUE rb_eRegexpError;
@@ -2657,6 +2658,18 @@
     return (VALUE)re;
 }
 
+static IMP rb_objc_reg_finalize_super = NULL; 
+
+static void
+rb_objc_reg_finalize(void *rcv, SEL sel)
+{
+    struct RRegexp *re = RREGEXP(rcv);
+    onig_free(re->ptr);
+    if (rb_objc_reg_finalize_super != NULL) {
+	((void(*)(void *, SEL))rb_objc_reg_finalize_super)(rcv, sel);
+    }
+}
+
 VALUE
 rb_reg_new_str(VALUE s, int options)
 {
@@ -3700,6 +3713,9 @@
     rb_objc_define_method(*(VALUE *)rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
     rb_objc_define_method(*(VALUE *)rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
 
+    rb_objc_reg_finalize_super = rb_objc_install_method2((Class)rb_cRegexp,
+	    "finalize", (IMP)rb_objc_reg_finalize);
+
     rb_objc_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
     rb_objc_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
     rb_objc_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091020/f828799c/attachment.html>


More information about the macruby-changes mailing list