Support destructors for non-GObject classes, patch by Jared Moore, fixes
authorJuerg Billeter <j@bitron.ch>
Sun, 25 May 2008 09:25:00 +0000 (09:25 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 25 May 2008 09:25:00 +0000 (09:25 +0000)
2008-05-25  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodeclassbinding.vala:

Support destructors for non-GObject classes,
patch by Jared Moore, fixes bug 522135

* tests/classes.exp:
* tests/classes.vala:

Test destructors for non-GObject classes

svn path=/trunk/; revision=1421

ChangeLog
gobject/valaccodeclassbinding.vala
tests/classes.exp
tests/classes.vala

index 6ee0596..cee9a68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-05-25  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodeclassbinding.vala:
+
+       Support destructors for non-GObject classes,
+       patch by Jared Moore, fixes bug 522135
+
+       * tests/classes.exp:
+       * tests/classes.vala:
+
+       Test destructors for non-GObject classes
+
+2008-05-25  Jürg Billeter  <j@bitron.ch>
+
        * vala/valacodenode.vala:
        * vala/valacreationmethod.vala:
        * vala/valaexpression.vala:
index e37695e..051c254 100644 (file)
@@ -264,6 +264,10 @@ public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
 
                        cblock.add_statement (codegen.instance_dispose_fragment);
 
+                       if (cl.destructor != null) {
+                               cblock.add_statement (cl.destructor.body.ccodenode);
+                       }
+
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
                        ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
                        ccall.add_argument (new CCodeIdentifier ("self"));
index 2be747b..c416ffb 100644 (file)
@@ -6,6 +6,8 @@ new ClassWithCreationMethod ()
 ClassWithCreationMethod
 new ClassWithNamedCreationMethod ()
 ClassWithNamedCreationMethod
+new ClassWithDestructor ()
+~ClassWithDestructor
 new SimpleGTypeInstanceClass ()
 new DerivedGTypeInstanceClass ()
 new PublicGTypeInstanceClass ()
index 5bfe296..ff53744 100644 (file)
@@ -4,6 +4,15 @@ class SimpleClass {
        public int field;
 }
 
+class ClassWithDestructor {
+       ~ClassWithDestructor () {
+               stdout.printf ("~ClassWithDestructor\n");
+       }
+
+       /* FIXME bug 533977 */
+       public char dummy;
+}
+
 class DerivedClass : SimpleClass {
 }
 
@@ -91,6 +100,9 @@ static class ClassesTest {
                var class_with_creation_method = new ClassWithCreationMethod ();
                stdout.printf ("new ClassWithNamedCreationMethod ()\n");
                var class_with_named_creation_method = new ClassWithNamedCreationMethod.named ();
+               stdout.printf ("new ClassWithDestructor ()\n");
+               var class_with_destructor = new ClassWithDestructor ();
+               class_with_destructor = null;
 
                stdout.printf ("new SimpleGTypeInstanceClass ()\n");
                var simple_gtypeinstance_class = new SimpleGTypeInstanceClass ();