From: Rico Tzschichholz Date: Fri, 6 Sep 2013 18:29:26 +0000 (+0200) Subject: girparser: Discover ref/unref methods X-Git-Tag: 0.21.2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6fcaa5420136aae54aa08310836d4d51ab21f1a;p=thirdparty%2Fvala.git girparser: Discover ref/unref methods Add ability to find ref/unref methods and add corresponding ccode attributes. Additionally rebuild all gir bindings to pick up the changes. https://bugzilla.gnome.org/show_bug.cgi?id=666796 --- diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 7a95b7bf6..8413e9ebc 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -3016,14 +3016,14 @@ public class Vala.GirParser : CodeVisitor { push_node (element_get_name (name), true); Class cl; + bool require_copy_free = false; if (current.new_symbol) { cl = new Class (current.name, current.source_reference); cl.is_compact = true; var typeid = reader.get_attribute ("glib:get-type"); if (typeid != null) { + require_copy_free = true; cl.set_attribute_string ("CCode", "type_id", "%s ()".printf (typeid)); - cl.set_attribute_string ("CCode", "free_function", "g_boxed_free"); - cl.set_attribute_string ("CCode", "copy_function", "g_boxed_copy"); } current.symbol = cl; @@ -3041,6 +3041,9 @@ public class Vala.GirParser : CodeVisitor { cl.comment = parse_symbol_doc (); + Node? ref_method = null; + Node? unref_method = null; + while (current_token == MarkupTokenType.START_ELEMENT) { if (!push_metadata ()) { skip_element (); @@ -3053,6 +3056,12 @@ public class Vala.GirParser : CodeVisitor { parse_constructor (); } else if (reader.name == "method") { parse_method ("method"); + var cname = old_current.get_cname (); + if (cname.has_suffix ("_ref")) { + ref_method = old_current; + } else if (cname.has_suffix ("_unref")) { + unref_method = old_current; + } } else if (reader.name == "function") { skip_element (); } else if (reader.name == "union") { @@ -3066,6 +3075,16 @@ public class Vala.GirParser : CodeVisitor { pop_metadata (); } + // Add ccode-attributes for ref/unref methodes if available + // otherwise fallback to default g_boxed_copy/free + if (ref_method != null && unref_method != null) { + cl.set_attribute_string ("CCode", "ref_function", ref_method.get_cname ()); + cl.set_attribute_string ("CCode", "unref_function", unref_method.get_cname ()); + } else if (require_copy_free) { + cl.set_attribute_string ("CCode", "copy_function", "g_boxed_copy"); + cl.set_attribute_string ("CCode", "free_function", "g_boxed_free"); + } + pop_node (); end_element (element_name); } diff --git a/vapi/gdk-3.0.vapi b/vapi/gdk-3.0.vapi index dead1dfee..f7794f6d4 100644 --- a/vapi/gdk-3.0.vapi +++ b/vapi/gdk-3.0.vapi @@ -4818,7 +4818,7 @@ namespace Gdk { public signal void resume_events (); public signal void update (); } - [CCode (cheader_filename = "gdk/gdk.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "gdk_frame_timings_get_type ()")] + [CCode (cheader_filename = "gdk/gdk.h", ref_function = "gdk_frame_timings_ref", type_id = "gdk_frame_timings_get_type ()", unref_function = "gdk_frame_timings_unref")] [Compact] public class FrameTimings { public bool get_complete (); diff --git a/vapi/gio-2.0.vapi b/vapi/gio-2.0.vapi index 0e505f92a..414d432d2 100644 --- a/vapi/gio-2.0.vapi +++ b/vapi/gio-2.0.vapi @@ -465,6 +465,8 @@ namespace GLib { public string key; public int ref_count; public string value; + public GLib.DBusAnnotationInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", ref_function = "g_dbus_arg_info_ref", type_id = "g_dbus_arg_info_get_type ()", unref_function = "g_dbus_arg_info_unref")] [Compact] @@ -474,6 +476,8 @@ namespace GLib { public string name; public int ref_count; public string signature; + public GLib.DBusArgInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", type_id = "g_dbus_auth_observer_get_type ()")] public class DBusAuthObserver : GLib.Object { @@ -561,6 +565,8 @@ namespace GLib { public unowned GLib.DBusMethodInfo lookup_method (string name); public unowned GLib.DBusPropertyInfo lookup_property (string name); public unowned GLib.DBusSignalInfo lookup_signal (string name); + public GLib.DBusInterfaceInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", type_id = "g_dbus_interface_skeleton_get_type ()")] public abstract class DBusInterfaceSkeleton : GLib.Object, GLib.DBusInterface { @@ -664,6 +670,8 @@ namespace GLib { [CCode (array_length = false, array_null_terminated = true)] public GLib.DBusArgInfo[] out_args; public int ref_count; + public GLib.DBusMethodInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", type_id = "g_dbus_method_invocation_get_type ()")] public class DBusMethodInvocation : GLib.Object { @@ -703,6 +711,8 @@ namespace GLib { public DBusNodeInfo.for_xml (string xml_data) throws GLib.Error; public void generate_xml (uint indent, GLib.StringBuilder string_builder); public unowned GLib.DBusInterfaceInfo lookup_interface (string name); + public GLib.DBusNodeInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", type_id = "g_dbus_object_manager_client_get_type ()")] public class DBusObjectManagerClient : GLib.Object, GLib.AsyncInitable, GLib.DBusObjectManager, GLib.Initable, GLib.AsyncInitable, GLib.DBusObjectManager, GLib.Initable { @@ -773,7 +783,7 @@ namespace GLib { public string g_object_path { owned get; set construct; } public virtual signal bool authorize_method (GLib.DBusInterfaceSkeleton interface_, GLib.DBusMethodInvocation invocation); } - [CCode (cheader_filename = "gio/gio.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "g_dbus_property_info_get_type ()")] + [CCode (cheader_filename = "gio/gio.h", ref_function = "g_dbus_property_info_ref", type_id = "g_dbus_property_info_get_type ()", unref_function = "g_dbus_property_info_unref")] [Compact] public class DBusPropertyInfo { [CCode (array_length = false, array_null_terminated = true)] @@ -782,6 +792,8 @@ namespace GLib { public string name; public int ref_count; public string signature; + public GLib.DBusPropertyInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h")] public class DBusProxy : GLib.Object, GLib.AsyncInitable, GLib.DBusInterface, GLib.Initable, GLib.AsyncInitable, GLib.DBusInterface, GLib.Initable { @@ -865,6 +877,8 @@ namespace GLib { public GLib.DBusArgInfo[] args; public string name; public int ref_count; + public GLib.DBusSignalInfo @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h")] public class DataInputStream : GLib.BufferedInputStream, GLib.Seekable { @@ -944,6 +958,8 @@ namespace GLib { public void add (string name, GLib.FileAttributeType type, GLib.FileAttributeInfoFlags flags); public GLib.FileAttributeInfoList dup (); public unowned GLib.FileAttributeInfo? lookup (string name); + public GLib.FileAttributeInfoList @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", ref_function = "g_file_attribute_matcher_ref", type_id = "g_file_attribute_matcher_get_type ()", unref_function = "g_file_attribute_matcher_unref")] [Compact] @@ -954,8 +970,10 @@ namespace GLib { public unowned string enumerate_next (); public bool matches (string attribute); public bool matches_only (string attribute); + public GLib.FileAttributeMatcher @ref (); public GLib.FileAttributeMatcher subtract (GLib.FileAttributeMatcher subtract); public string to_string (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h", type_id = "g_file_enumerator_get_type ()")] public class FileEnumerator : GLib.Object { @@ -1203,6 +1221,7 @@ namespace GLib { [CCode (has_construct_function = false)] public IOModuleScope (GLib.IOModuleScopeFlags flags); public void block (string basename); + public void free (); } [CCode (cheader_filename = "gio/gio.h")] [Compact] @@ -1646,6 +1665,8 @@ namespace GLib { public static GLib.Resource load (string filename) throws GLib.Error; public GLib.Bytes lookup_data (string path, GLib.ResourceLookupFlags lookup_flags) throws GLib.Error; public GLib.InputStream open_stream (string path, GLib.ResourceLookupFlags lookup_flags) throws GLib.Error; + public GLib.Resource @ref (); + public void unref (); } [CCode (cheader_filename = "gio/gio.h")] public class Settings : GLib.Object { @@ -1729,7 +1750,7 @@ namespace GLib { [CCode (has_construct_function = false)] protected SettingsBackend (); } - [CCode (cheader_filename = "gio/gio.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "g_settings_schema_get_type ()")] + [CCode (cheader_filename = "gio/gio.h", ref_function = "g_settings_schema_ref", type_id = "g_settings_schema_get_type ()", unref_function = "g_settings_schema_unref")] [Compact] public class SettingsSchema { public unowned string get_id (); @@ -1737,7 +1758,7 @@ namespace GLib { public GLib.SettingsSchema @ref (); public void unref (); } - [CCode (cheader_filename = "gio/gio.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "g_settings_schema_source_get_type ()")] + [CCode (cheader_filename = "gio/gio.h", ref_function = "g_settings_schema_source_ref", type_id = "g_settings_schema_source_get_type ()", unref_function = "g_settings_schema_source_unref")] [Compact] public class SettingsSchemaSource { [CCode (has_construct_function = false)] @@ -2023,6 +2044,7 @@ namespace GLib { [CCode (has_construct_function = false)] public SrvTarget (string hostname, uint16 port, uint16 priority, uint16 weight); public GLib.SrvTarget copy (); + public void free (); public unowned string get_hostname (); public uint16 get_port (); public uint16 get_priority (); diff --git a/vapi/gstreamer-video-1.0.vapi b/vapi/gstreamer-video-1.0.vapi index daa716866..ed00c3a54 100644 --- a/vapi/gstreamer-video-1.0.vapi +++ b/vapi/gstreamer-video-1.0.vapi @@ -30,7 +30,7 @@ namespace Gst { public void set_user_data (owned T user_data); public void unref (); } - [CCode (cheader_filename = "gst/video/colorbalance.h,gst/video/colorbalancechannel.h,gst/video/gstvideodecoder.h,gst/video/gstvideoencoder.h,gst/video/gstvideofilter.h,gst/video/gstvideometa.h,gst/video/gstvideopool.h,gst/video/gstvideosink.h,gst/video/gstvideoutils.h,gst/video/navigation.h,gst/video/video-blend.h,gst/video/video-color.h,gst/video/video-enumtypes.h,gst/video/video-event.h,gst/video/video-format.h,gst/video/video-frame.h,gst/video/video-info.h,gst/video/video-overlay-composition.h,gst/video/video.h,gst/video/videoorientation.h,gst/video/videooverlay.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "gst_video_codec_state_get_type ()")] + [CCode (cheader_filename = "gst/video/colorbalance.h,gst/video/colorbalancechannel.h,gst/video/gstvideodecoder.h,gst/video/gstvideoencoder.h,gst/video/gstvideofilter.h,gst/video/gstvideometa.h,gst/video/gstvideopool.h,gst/video/gstvideosink.h,gst/video/gstvideoutils.h,gst/video/navigation.h,gst/video/video-blend.h,gst/video/video-color.h,gst/video/video-enumtypes.h,gst/video/video-event.h,gst/video/video-format.h,gst/video/video-frame.h,gst/video/video-info.h,gst/video/video-overlay-composition.h,gst/video/video.h,gst/video/videoorientation.h,gst/video/videooverlay.h", ref_function = "gst_video_codec_state_ref", type_id = "gst_video_codec_state_get_type ()", unref_function = "gst_video_codec_state_unref")] [Compact] [GIR (name = "VideoCodecState")] public class CodecState { diff --git a/vapi/json-glib-1.0.vapi b/vapi/json-glib-1.0.vapi index 9d67ec4bb..268846554 100644 --- a/vapi/json-glib-1.0.vapi +++ b/vapi/json-glib-1.0.vapi @@ -2,7 +2,7 @@ [CCode (cprefix = "Json", gir_namespace = "Json", gir_version = "1.0", lower_case_cprefix = "json_")] namespace Json { - [CCode (cheader_filename = "json-glib/json-glib.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "json_array_get_type ()")] + [CCode (cheader_filename = "json-glib/json-glib.h", ref_function = "json_array_ref", type_id = "json_array_get_type ()", unref_function = "json_array_unref")] [Compact] public class Array { [CCode (has_construct_function = false)] @@ -113,7 +113,7 @@ namespace Json { public void take_object (owned Json.Object object); public unowned string type_name (); } - [CCode (cheader_filename = "json-glib/json-glib.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "json_object_get_type ()")] + [CCode (cheader_filename = "json-glib/json-glib.h", ref_function = "json_object_ref", type_id = "json_object_get_type ()", unref_function = "json_object_unref")] [Compact] public class Object { [CCode (has_construct_function = false)] diff --git a/vapi/metadata/Gio-2.0-custom.vala b/vapi/metadata/Gio-2.0-custom.vala index 012f0a742..7a03812d6 100644 --- a/vapi/metadata/Gio-2.0-custom.vala +++ b/vapi/metadata/Gio-2.0-custom.vala @@ -545,53 +545,6 @@ namespace GLib { [CCode (cheader_filename = "gio/gio.h", cname = "g_tls_error_quark")] public static GLib.Quark g_tls_error_quark (); - /*** Bug #: GIR parser doesn't pick up ref/unref functions ***/ - - [CCode (cheader_filename = "gio/gio.h", ref_function = "g_dbus_annotation_info_ref", type_id = "g_dbus_annotation_info_get_type ()", unref_function = "g_dbus_annotation_info_unref")] - [Compact] - public class DBusAnnotationInfo { - } - - [CCode (cheader_filename = "gio/gio.h", ref_function = "g_dbus_arg_info_ref", type_id = "g_dbus_arg_info_get_type ()", unref_function = "g_dbus_arg_info_unref")] - [Compact] - public class DBusArgInfo { - } - - [CCode (ref_function = "g_dbus_interface_info_ref", type_id = "g_dbus_interface_info_get_type ()", unref_function = "g_dbus_interface_info_unref")] - [Compact] - public class DBusInterfaceInfo { - } - - [CCode (ref_function = "g_dbus_method_info_ref", type_id = "g_dbus_method_info_get_type ()", unref_function = "g_dbus_method_info_unref")] - [Compact] - public class DBusMethodInfo { - } - - [CCode (ref_function = "g_dbus_node_info_ref", type_id = "g_dbus_node_info_get_type ()", unref_function = "g_dbus_node_info_unref")] - [Compact] - public class DBusNodeInfo { - } - - [CCode (ref_function = "g_dbus_signal_info_ref", type_id = "g_dbus_signal_info_get_type ()", unref_function = "g_dbus_signal_info_unref")] - [Compact] - public class DBusSignalInfo { - } - - [CCode (ref_function = "g_file_attribute_info_list_ref", type_id = "g_file_attribute_info_list_get_type ()", unref_function = "g_file_attribute_info_list_unref")] - [Compact] - public class FileAttributeInfoList { - } - - [CCode (ref_function = "g_file_attribute_matcher_ref", type_id = "g_file_attribute_matcher_get_type ()", unref_function = "g_file_attribute_matcher_unref")] - [Compact] - public class FileAttributeMatcher { - } - - [CCode (ref_function = "g_resource_ref", type_id = "g_resource_get_type ()", unref_function = "g_resource_unref")] - [Compact] - public class Resource { - } - [CCode (cheader_filename = "gio/gio.h", has_target = false, cname = "GSettingsBindGetMapping")] public delegate bool SettingsBindGetMappingShared (GLib.Value value, GLib.Variant variant, void* user_data); [CCode (cheader_filename = "gio/gio.h", has_target = false, cname = "GSettingsBindSetMapping")] diff --git a/vapi/metadata/Gio-2.0.metadata b/vapi/metadata/Gio-2.0.metadata index f9898a573..29cad7dab 100644 --- a/vapi/metadata/Gio-2.0.metadata +++ b/vapi/metadata/Gio-2.0.metadata @@ -114,8 +114,6 @@ FileInfo .list_attributes nullable FileEnumerator .next_file nullable -IOModuleScope - .free skip IOStream .close* skip .input_stream abstract @@ -193,8 +191,6 @@ SocketControlMessage .serialize.data type="uint8[]" SocketListener .accept*.source_object#parameter default=null -SrvTarget - .free skip srv_target_list_sort type_arguments="GLib.SrvTarget" skip=false srv_target_list_sort.targets type_arguments="GLib.SrvTarget" owned StaticResource @@ -268,21 +264,6 @@ proxy_resolver_get_default skip simple_async_report_gerror_in_idle parent="GLib.SimpleAsyncResult" name="report_gerror_in_idle" tls_* skip - -// Bug #666796: GIR parser doesn't pick up ref/unref functions -DBus*Info - .ref skip - .unref skip -FileAttributeInfoList - .ref skip - .unref skip -FileAttributeMatcher - .ref skip - .unref skip -Resource - .ref skip - .unref skip - // Bug #659886: Async constuctors don't work DBusConnection .new skip diff --git a/vapi/pango.vapi b/vapi/pango.vapi index 3af047b64..8ae455aeb 100644 --- a/vapi/pango.vapi +++ b/vapi/pango.vapi @@ -66,7 +66,7 @@ namespace Pango { [CCode (has_construct_function = false, type = "PangoAttribute*")] public AttrLanguage (Pango.Language language); } - [CCode (cheader_filename = "pango/pango.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "pango_attr_list_get_type ()")] + [CCode (cheader_filename = "pango/pango.h", ref_function = "pango_attr_list_ref", type_id = "pango_attr_list_get_type ()", unref_function = "pango_attr_list_unref")] [Compact] public class AttrList { [CCode (has_construct_function = false)] @@ -241,7 +241,7 @@ namespace Pango { public Pango.Font load_font (Pango.Context context, Pango.FontDescription desc); public Pango.Fontset load_fontset (Pango.Context context, Pango.FontDescription desc, Pango.Language language); } - [CCode (cheader_filename = "pango/pango.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "pango_font_metrics_get_type ()")] + [CCode (cheader_filename = "pango/pango.h", ref_function = "pango_font_metrics_ref", type_id = "pango_font_metrics_get_type ()", unref_function = "pango_font_metrics_unref")] [Compact] public class FontMetrics { public int get_approximate_char_width (); @@ -406,7 +406,7 @@ namespace Pango { public bool next_line (); public bool next_run (); } - [CCode (cheader_filename = "pango/pango.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "pango_layout_line_get_type ()")] + [CCode (cheader_filename = "pango/pango.h", ref_function = "pango_layout_line_ref", type_id = "pango_layout_line_get_type ()", unref_function = "pango_layout_line_unref")] [Compact] public class LayoutLine { public uint is_paragraph_start; diff --git a/vapi/rest-0.7.vapi b/vapi/rest-0.7.vapi index c6d9c1187..ef88f8d52 100644 --- a/vapi/rest-0.7.vapi +++ b/vapi/rest-0.7.vapi @@ -56,8 +56,9 @@ namespace Rest { [CCode (has_construct_function = false)] protected OAuthProxyCall (); public void parse_token_reponse (); + public void parse_token_response (); } - [CCode (cheader_filename = "rest/rest-param.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "rest_param_get_type ()")] + [CCode (cheader_filename = "rest/rest-param.h", ref_function = "rest_param_ref", type_id = "rest_param_get_type ()", unref_function = "rest_param_unref")] [Compact] public class Param { [CCode (has_construct_function = false)] @@ -160,7 +161,7 @@ namespace Rest { [NoAccessorMethod] public Rest.Proxy proxy { owned get; construct; } } - [CCode (cheader_filename = "rest/rest-xml-node.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "rest_xml_node_get_type ()")] + [CCode (cheader_filename = "rest/rest-xml-node.h", ref_function = "rest_xml_node_ref", type_id = "rest_xml_node_get_type ()", unref_function = "rest_xml_node_unref")] [Compact] public class XmlNode { public weak GLib.HashTable attrs; @@ -242,7 +243,7 @@ namespace Rest { HTTP_HTTP_VERSION_NOT_SUPPORTED; public static GLib.Quark quark (); } - [CCode (cheader_filename = "rest/oauth-proxy.h", cname = "OAuthProxyAuthCallback", instance_pos = 3.9)] + [CCode (cheader_filename = "rest/oauth-proxy.h", instance_pos = 3.9)] public delegate void OAuthProxyAuthCallback (Rest.OAuthProxy proxy, GLib.Error? error, GLib.Object? weak_object); [CCode (cheader_filename = "rest/rest-proxy-call.h", instance_pos = 3.9)] public delegate void ProxyCallAsyncCallback (Rest.ProxyCall call, GLib.Error? error, GLib.Object? weak_object);