]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support [CCode (ref_function_void = true)] attribute for bindings, based
authorJürg Billeter <j@bitron.ch>
Tue, 6 Jan 2009 22:59:20 +0000 (22:59 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 6 Jan 2009 22:59:20 +0000 (22:59 +0000)
2009-01-06  Jürg Billeter  <j@bitron.ch>

* vala/valaclass.vala:
* gobject/valaccodebasemodule.vala:

Support [CCode (ref_function_void = true)] attribute for bindings,
based on patch by Andreas Brauchli, fixes bug 566078

svn path=/trunk/; revision=2279

ChangeLog
gobject/valaccodebasemodule.vala
vala/valaclass.vala

index 892506c2277051ae322aa165f65670d72806665e..da51212c8004e0117f027356d41edba727989330 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-01-06  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaclass.vala:
+       * gobject/valaccodebasemodule.vala:
+
+       Support [CCode (ref_function_void = true)] attribute for bindings,
+       based on patch by Andreas Brauchli, fixes bug 566078
+
 2009-01-06  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaarraytype.vala:
index 731a193e2a39a0f9d4c9e8e322fd88ee711548c1..acdf90a25b2f1cbdf852b0eef59449f2ae956608 100644 (file)
@@ -2460,6 +2460,15 @@ public class Vala.CCodeBaseModule : CCodeModule {
                return true;
        }
 
+       bool is_ref_function_void (DataType type) {
+               var cl = type.data_type as Class;
+               if (cl != null && cl.ref_function_void) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
        public CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
                if (expression_type is ValueType && !expression_type.nullable) {
                        // normal value type, no null check
@@ -2521,7 +2530,8 @@ public class Vala.CCodeBaseModule : CCodeModule {
 
                var ccall = new CCodeFunctionCall (dupexpr);
 
-               if (!(expression_type is ArrayType) && expr != null && expr.is_non_null ()) {
+               if (!(expression_type is ArrayType) && expr != null && expr.is_non_null ()
+                   && !is_ref_function_void (expression_type)) {
                        // expression is non-null
                        ccall.add_argument ((CCodeExpression) expr.ccodenode);
                        
@@ -2582,6 +2592,12 @@ public class Vala.CCodeBaseModule : CCodeModule {
                        }
                        ccomma.append_expression (new CCodeConditionalExpression (cisnull, cifnull, ccall));
 
+                       // repeat temp variable at the end of the comma expression
+                       // if the ref function returns void
+                       if (is_ref_function_void (expression_type)) {
+                               ccomma.append_expression (ctemp);
+                       }
+
                        return ccomma;
                }
        }
index 31c1241730d2ea06f253b132caae2cd0e184064d..3c889a4be104ca37af9c3a3b7dc9c443a020c22c 100644 (file)
@@ -70,6 +70,12 @@ public class Vala.Class : ObjectTypeSymbol {
                }
        }
 
+       /**
+        * Specifies wheather the ref function returns void instead of the
+        * object.
+        */
+       public bool ref_function_void { get; set; }
+
        /**
         * The name of the function to use to check whether a value is an instance of
         * this class. If this is null then the default type check function should be 
@@ -575,6 +581,9 @@ public class Vala.Class : ObjectTypeSymbol {
                if (a.has_argument ("ref_function")) {
                        set_ref_function (a.get_string ("ref_function"));
                }
+               if (a.has_argument ("ref_function_void")) {
+                       this.ref_function_void = a.get_bool ("ref_function_void");
+               }
                if (a.has_argument ("unref_function")) {
                        set_unref_function (a.get_string ("unref_function"));
                }