]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Bug 571256 – [CCode (async_only = true)] formal parameter annotation
authorRyan Lortie <desrt@desrt.ca>
Wed, 11 Feb 2009 01:02:37 +0000 (01:02 +0000)
committerRyan Lortie <ryanl@src.gnome.org>
Wed, 11 Feb 2009 01:02:37 +0000 (01:02 +0000)
2009-02-11  Ryan Lortie  <desrt@desrt.ca>

        Bug 571256 – [CCode (async_only = true)] formal parameter annotation

        * vala/valacodewriter.vala:
        * vala/valaformalparameter.vala:
        * gobject/valaccodemethodcallmodule.vala:

        Allow emitting some C code arguments only in the case that we are
        calling the asynchronous version of a yielding function.  This helps
        with the io_priority oddity in GIO.

svn path=/trunk/; revision=2427

ChangeLog
gobject/valaccodemethodcallmodule.vala
vala/valacodewriter.vala
vala/valaformalparameter.vala

index cd0f91d5a01b20f2a07b16af2e72e1b5d0705d77..6bcc14bac607a25ebb66e1960ae581714eae2511 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-02-11  Ryan Lortie  <desrt@desrt.ca>
+
+       Bug 571256 – [CCode (async_only = true)] formal parameter annotation
+
+       * vala/valacodewriter.vala:
+       * vala/valaformalparameter.vala:
+       * gobject/valaccodemethodcallmodule.vala:
+
+       Allow emitting some C code arguments only in the case that we are
+       calling the asynchronous version of a yielding function.  This helps
+       with the io_priority oddity in GIO.
+
 2009-02-11  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaenum.vala:
index 49d1d5d871a12ced313df07bb55c0a8586838436..25e9eb7254789c6b958376c3ae2d21fce5bc9714 100644 (file)
@@ -212,6 +212,25 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                var param = params_it.get ();
                                ellipsis = param.params_array || param.ellipsis;
                                if (!ellipsis) {
+                                       if (param.async_only &&
+                                          /* only skip if we are in a sync function (or property handler) */
+                                            (current_method == null || !current_method.coroutine) &&
+                                          /* and not manually starting async */
+                                           (ma == null || ma.member_name != "begin")) {
+                                               /* [CCode (async_only = true)] and we're making a
+                                                * synchronous version of the call.  Emit the arg
+                                                * at the start of a comma expression so that we
+                                                * get any side effects but otherwise ignore the
+                                                * value.
+                                                */
+                                               var comma = new CCodeCommaExpression ();
+                                               comma.append_expression ((CCodeExpression) arg.ccodenode);
+                                               comma.append_expression (ccall_expr);
+                                               ccall_expr = comma;
+
+                                               continue;
+                                       }
+
                                        // if the vala argument expands to multiple C arguments,
                                        // we have to make sure that the C arguments don't depend
                                        // on each other as there is no guaranteed argument
index 0023fad7db4b39018b46a63b6fee5b95d0a1aaf8..8a2a5eb1b68f7d521f37065878c5a65ade66452c 100644 (file)
@@ -726,6 +726,10 @@ public class Vala.CodeWriter : CodeVisitor {
                                ccode_params.append_printf ("%sdelegate_target_pos = %g", separator, param.cdelegate_target_parameter_position);
                                separator = ", ";
                        }
+                       if (param.async_only) {
+                               ccode_params.append_printf ("%sasync_only = true", separator);
+                               separator = ", ";
+                       }
 
                        if (ccode_params.len > 0) {
                                write_string ("[CCode (%s)] ".printf (ccode_params.str));
index d848d17251b3e5ceba3deca0d0a8099d49b9c61a..74e03cad91093661206d422eaf639e86b9dd9189 100644 (file)
@@ -88,6 +88,12 @@ public class Vala.FormalParameter : Symbol {
         */
        public double cdelegate_target_parameter_position { get; set; }
 
+       /**
+        * Specifies that the argument should only be emitted for async
+        * calls (ie: from yielding functions).
+        */
+       public bool async_only { get; set; }
+
        /**
         * Specifies the type of the parameter in the C function.
         */
@@ -157,6 +163,9 @@ public class Vala.FormalParameter : Symbol {
                if (a.has_argument ("delegate_target_pos")) {
                        cdelegate_target_parameter_position = a.get_double ("delegate_target_pos");
                }
+               if (a.has_argument ("async_only")) {
+                       async_only = a.get_bool ("async_only");
+               }
        }
 
        /**