[vala] girparser: Support scope=async parameters.



commit 3e20fd82c05daa60005aaff11411cd1814beb778
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon Jul 8 23:03:58 2013 -0700

    girparser: Support scope=async parameters.
    
    Based on patch by Evan.
    
    Fixes bug 704176.

 vala/valagirparser.vala |   89 +++++++++++++++++++++++++++++------------------
 vapi/gstreamer-1.0.vapi |    4 +-
 vapi/libsoup-2.4.vapi   |   12 +++---
 3 files changed, 63 insertions(+), 42 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index b6cbe16..fde6b68 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2734,13 +2734,14 @@ public class Vala.GirParser : CodeVisitor {
        }
 
        class ParameterInfo {
-               public ParameterInfo (Parameter param, int array_length_idx, int closure_idx, int 
destroy_idx) {
+               public ParameterInfo (Parameter param, int array_length_idx, int closure_idx, int 
destroy_idx, bool is_async = false) {
                        this.param = param;
                        this.array_length_idx = array_length_idx;
                        this.closure_idx = closure_idx;
                        this.destroy_idx = destroy_idx;
                        this.vala_idx = 0.0F;
                        this.keep = true;
+                       this.is_async = is_async;
                }
 
                public Parameter param;
@@ -2749,6 +2750,7 @@ public class Vala.GirParser : CodeVisitor {
                public int closure_idx;
                public int destroy_idx;
                public bool keep;
+               public bool is_async;
        }
 
        void parse_function (string element_name) {
@@ -2940,7 +2942,7 @@ public class Vala.GirParser : CodeVisitor {
                                        comment.add_content_for_parameter ((param.ellipsis)? "..." : 
param.name, param_comment);
                                }
 
-                               var info = new ParameterInfo (param, array_length_idx, closure_idx, 
destroy_idx);
+                               var info = new ParameterInfo (param, array_length_idx, closure_idx, 
destroy_idx, scope == "async");
 
                                if (s is Method && scope == "async") {
                                        var unresolved_type = param.variable_type as UnresolvedType;
@@ -3387,42 +3389,61 @@ public class Vala.GirParser : CodeVisitor {
                }
 
                foreach (ParameterInfo info in parameters) {
-                       if (info.keep) {
-
-                               /* add_parameter sets carray_length_parameter_position and 
cdelegate_target_parameter_position
-                                  so do it first*/
-                               if (s is Method) {
-                                       ((Method) s).add_parameter (info.param);
-                               } else if (s is Delegate) {
-                                       ((Delegate) s).add_parameter (info.param);
-                               } else if (s is Signal) {
-                                       ((Signal) s).add_parameter (info.param);
-                               }
-
-                               if (info.array_length_idx != -1) {
-                                       if ((info.array_length_idx) >= parameters.size) {
-                                               Report.error (get_current_src (), "invalid array_length 
index");
-                                               continue;
-                                       }
-                                       set_array_ccode (info.param, parameters[info.array_length_idx]);
+                       if (!info.keep) {
+                               continue;
+                       }
+
+                       /* add_parameter sets carray_length_parameter_position and 
cdelegate_target_parameter_position
+                          so do it first*/
+                       if (s is Method) {
+                               ((Method) s).add_parameter (info.param);
+                       } else if (s is Delegate) {
+                               ((Delegate) s).add_parameter (info.param);
+                       } else if (s is Signal) {
+                               ((Signal) s).add_parameter (info.param);
+                       }
+
+                       if (info.array_length_idx != -1) {
+                               if ((info.array_length_idx) >= parameters.size) {
+                                       Report.error (get_current_src (), "invalid array_length index");
+                                       continue;
                                }
+                               set_array_ccode (info.param, parameters[info.array_length_idx]);
+                       }
 
-                               if (info.closure_idx != -1) {
-                                       if ((info.closure_idx) >= parameters.size) {
-                                               Report.error (get_current_src (), "invalid closure index");
-                                               continue;
-                                       }
-                                       if ("%g".printf (parameters[info.closure_idx].vala_idx) != 
"%g".printf (info.vala_idx + 0.1)) {
-                                               info.param.set_attribute_double ("CCode", 
"delegate_target_pos", parameters[info.closure_idx].vala_idx);
-                                       }
+                       if (info.closure_idx != -1) {
+                               if ((info.closure_idx) >= parameters.size) {
+                                       Report.error (get_current_src (), "invalid closure index");
+                                       continue;
+                               }
+                               if ("%g".printf (parameters[info.closure_idx].vala_idx) != "%g".printf 
(info.vala_idx + 0.1)) {
+                                       info.param.set_attribute_double ("CCode", "delegate_target_pos", 
parameters[info.closure_idx].vala_idx);
+                               }
+                       }
+                       if (info.destroy_idx != -1) {
+                               if (info.destroy_idx >= parameters.size) {
+                                       Report.error (get_current_src (), "invalid destroy index");
+                                       continue;
                                }
-                               if (info.destroy_idx != -1) {
-                                       if (info.destroy_idx >= parameters.size) {
-                                               Report.error (get_current_src (), "invalid destroy index");
-                                               continue;
+                               if ("%g".printf (parameters[info.destroy_idx].vala_idx) != "%g".printf 
(info.vala_idx + 0.2)) {
+                                       info.param.set_attribute_double ("CCode", "destroy_notify_pos", 
parameters[info.destroy_idx].vala_idx);
+                               }
+                       }
+
+                       if (info.is_async) {
+                               var resolved_type = info.param.variable_type;
+                               if (resolved_type is UnresolvedType) {
+                                       var resolved_symbol = resolve_symbol (node.parent, ((UnresolvedType) 
resolved_type).unresolved_symbol);
+                                       if (resolved_symbol is Delegate) {
+                                               resolved_type = new DelegateType ((Delegate) resolved_symbol);
                                        }
-                                       if ("%g".printf (parameters[info.destroy_idx].vala_idx) != 
"%g".printf (info.vala_idx + 0.2)) {
-                                               info.param.set_attribute_double ("CCode", 
"destroy_notify_pos", parameters[info.destroy_idx].vala_idx);
+                               }
+
+                               if (resolved_type is DelegateType) {
+                                       var d = ((DelegateType) resolved_type).delegate_symbol;
+                                       if (!(d.name == "DestroyNotify" && d.parent_symbol.name == "GLib")) {
+                                               info.param.set_attribute_string ("CCode", "scope", "async");
+                                               info.param.variable_type.value_owned = true;
                                        }
                                }
                        }
diff --git a/vapi/gstreamer-1.0.vapi b/vapi/gstreamer-1.0.vapi
index 54d4aa5..e5bc8cf 100644
--- a/vapi/gstreamer-1.0.vapi
+++ b/vapi/gstreamer-1.0.vapi
@@ -1772,7 +1772,7 @@ namespace Gst {
                public virtual void cleanup ();
                public virtual void join (void* id);
                public virtual void prepare () throws GLib.Error;
-               public virtual void* push (Gst.TaskPoolFunction func) throws GLib.Error;
+               public virtual void* push ([CCode (scope = "async")] owned Gst.TaskPoolFunction func) throws 
GLib.Error;
        }
        [CCode (cheader_filename = "gst/gst.h", ref_function = "gst_toc_ref", type_id = "gst_toc_get_type 
()", unref_function = "gst_toc_unref")]
        [Compact]
@@ -1961,7 +1961,7 @@ namespace Gst {
                public static bool api_type_has_tag (GLib.Type api, GLib.Quark tag);
                public static GLib.Type api_type_register (string api, string tags);
                public static unowned Gst.MetaInfo? get_info (string impl);
-               public static unowned Gst.MetaInfo? register (GLib.Type api, string impl, size_t size, 
Gst.MetaInitFunction init_func, Gst.MetaFreeFunction free_func, Gst.MetaTransformFunction transform_func);
+               public static unowned Gst.MetaInfo? register (GLib.Type api, string impl, size_t size, [CCode 
(scope = "async")] owned Gst.MetaInitFunction init_func, [CCode (scope = "async")] owned Gst.MetaFreeFunction 
free_func, [CCode (scope = "async")] owned Gst.MetaTransformFunction transform_func);
        }
        [CCode (cheader_filename = "gst/gst.h", has_type_id = false)]
        public struct MetaInfo {
diff --git a/vapi/libsoup-2.4.vapi b/vapi/libsoup-2.4.vapi
index c78e634..334a8ad 100644
--- a/vapi/libsoup-2.4.vapi
+++ b/vapi/libsoup-2.4.vapi
@@ -90,7 +90,7 @@ namespace Soup {
                public uint hash_by_ip ();
                public uint hash_by_name ();
                public bool is_resolved ();
-               public void resolve_async (GLib.MainContext? async_context, GLib.Cancellable? cancellable, 
Soup.AddressCallback callback);
+               public void resolve_async (GLib.MainContext? async_context, GLib.Cancellable? cancellable, 
[CCode (scope = "async")] owned Soup.AddressCallback callback);
                public uint resolve_sync (GLib.Cancellable? cancellable = null);
                [NoAccessorMethod]
                public Soup.AddressFamily family { get; construct; }
@@ -645,10 +645,10 @@ namespace Soup {
                [NoWrapper]
                public virtual void kick ();
                public void pause_message (Soup.Message msg);
-               public void prefetch_dns (string hostname, GLib.Cancellable? cancellable, 
Soup.AddressCallback? callback);
+               public void prefetch_dns (string hostname, GLib.Cancellable? cancellable, [CCode (scope = 
"async")] owned Soup.AddressCallback? callback);
                [Deprecated (since = "2.38")]
                public void prepare_for_uri (Soup.URI uri);
-               public virtual void queue_message (owned Soup.Message msg, Soup.SessionCallback? callback);
+               public virtual void queue_message (owned Soup.Message msg, [CCode (scope = "async")] owned 
Soup.SessionCallback? callback);
                public bool redirect_message (Soup.Message msg);
                public void remove_feature (Soup.SessionFeature feature);
                public void remove_feature_by_type (GLib.Type feature_type);
@@ -728,7 +728,7 @@ namespace Soup {
        public class Socket : GLib.Object {
                [CCode (has_construct_function = false)]
                public Socket (string optname1, ...);
-               public void connect_async (GLib.Cancellable? cancellable, Soup.SocketCallback callback);
+               public void connect_async (GLib.Cancellable? cancellable, [CCode (scope = "async")] owned 
Soup.SocketCallback callback);
                public uint connect_sync (GLib.Cancellable? cancellable = null);
                public void disconnect ();
                public int get_fd ();
@@ -822,7 +822,7 @@ namespace Soup {
        }
        [CCode (cheader_filename = "libsoup/soup.h", type_cname = "SoupPasswordManagerInterface", type_id = 
"soup_password_manager_get_type ()")]
        public interface PasswordManager : Soup.SessionFeature, GLib.Object {
-               public abstract void get_passwords_async (Soup.Message msg, Soup.Auth auth, bool retrying, 
GLib.MainContext async_context, GLib.Cancellable? cancellable, Soup.PasswordManagerCallback callback);
+               public abstract void get_passwords_async (Soup.Message msg, Soup.Auth auth, bool retrying, 
GLib.MainContext async_context, GLib.Cancellable? cancellable, [CCode (scope = "async")] owned 
Soup.PasswordManagerCallback callback);
                public abstract void get_passwords_sync (Soup.Message msg, Soup.Auth auth, GLib.Cancellable? 
cancellable = null);
        }
        [CCode (cheader_filename = "libsoup/soup.h", type_cname = "SoupProxyResolverInterface", type_id = 
"soup_proxy_resolver_get_type ()")]
@@ -833,7 +833,7 @@ namespace Soup {
        }
        [CCode (cheader_filename = "libsoup/soup.h", type_cname = "SoupProxyURIResolverInterface", type_id = 
"soup_proxy_uri_resolver_get_type ()")]
        public interface ProxyURIResolver : Soup.SessionFeature, GLib.Object {
-               public abstract void get_proxy_uri_async (Soup.URI uri, GLib.MainContext? async_context, 
GLib.Cancellable? cancellable, Soup.ProxyURIResolverCallback callback);
+               public abstract void get_proxy_uri_async (Soup.URI uri, GLib.MainContext? async_context, 
GLib.Cancellable? cancellable, [CCode (scope = "async")] owned Soup.ProxyURIResolverCallback callback);
                public abstract uint get_proxy_uri_sync (Soup.URI uri, GLib.Cancellable? cancellable, out 
Soup.URI proxy_uri);
        }
        [CCode (cheader_filename = "libsoup/soup.h", type_cname = "SoupSessionFeatureInterface", type_id = 
"soup_session_feature_get_type ()")]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]