don't free arguments of ref and out parameters
authorJuerg Billeter <j@bitron.ch>
Sun, 2 Mar 2008 22:10:37 +0000 (22:10 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 2 Mar 2008 22:10:37 +0000 (22:10 +0000)
2008-03-02  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala: don't free arguments of ref and
  out parameters

* tests/classes-methods.vala: test ref parameter

svn path=/trunk/; revision=1096

ChangeLog
gobject/valaccodegenerator.vala
tests/classes-methods.vala

index abe06af..47d4aa6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-03-02  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegenerator.vala: don't free arguments of ref and
+         out parameters
+
+       * tests/classes-methods.vala: test ref parameter
+
+2008-03-02  Jürg Billeter  <j@bitron.ch>
+
        * tests/testrunner.sh: make sure we detect failed test cases
 
 2008-03-02  Jürg Billeter  <j@bitron.ch>
index ab5013e..e3499e5 100644 (file)
@@ -916,7 +916,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                if (b.parent_symbol is Method) {
                        var m = (Method) b.parent_symbol;
                        foreach (FormalParameter param in m.get_parameters ()) {
-                               if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership) {
+                               if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
                                        var ma = new MemberAccess.simple (param.name);
                                        ma.symbol_reference = param;
                                        cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (param.name)), param.type_reference, ma)));
@@ -1936,7 +1936,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
 
        private void append_param_free (Method m, CCodeFragment cfrag) {
                foreach (FormalParameter param in m.get_parameters ()) {
-                       if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership) {
+                       if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
                                var ma = new MemberAccess.simple (param.name);
                                ma.symbol_reference = param;
                                cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (param.name)), param.type_reference, ma)));
@@ -1981,7 +1981,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                bool found = false;
 
                foreach (FormalParameter param in m.get_parameters ()) {
-                       if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership) {
+                       if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
                                found = true;
                                var ma = new MemberAccess.simple (param.name);
                                ma.symbol_reference = param;
index 3d1dc7c..1637908 100644 (file)
@@ -19,6 +19,14 @@ class Maman.SubBar : Bar {
                stdout.printf (" 2");
        }
 
+       static void accept_ref_string (ref string str) {
+       }
+
+       static void test_classes_methods_ref_parameters () {
+               string str = "hello";
+               accept_ref_string (ref str);
+       }
+
        static int main (string[] args) {
                stdout.printf ("Inheritance Test: 1");
 
@@ -48,6 +56,8 @@ class Maman.SubBar : Bar {
        
                stdout.printf (" 3\n");
 
+               test_classes_methods_ref_parameters ();
+
                return 0;
        }
 }