From e579dad9083b2a6771f0c6e7364d6607fdde210b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Fri, 16 Mar 2007 21:23:27 +0000 Subject: [PATCH] default to strong references for method return types reset MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2007-03-16 Jürg Billeter * vala/parser.y: default to strong references for method return types * vala/valasymbolresolver.vala: reset TypeReference.transfers_ownership for value-types * vala/valasourcefile.vala: assume ownership of include filenames * vala/valainterfacewriter.vala: use weak keyword for return types * vala/valacodecontext.vala, vala/valasourcefile.vala, vala/valasymbolbuilder.vala, vapi/glib-2.0.vala: add weak to return types svn path=/trunk/; revision=235 --- vala/ChangeLog | 11 +++ vala/vala/parser.y | 2 +- vala/vala/valacodecontext.vala | 2 +- vala/vala/valainterfacewriter.vala | 2 + vala/vala/valasourcefile.vala | 20 +++--- vala/vala/valasymbolbuilder.vala | 2 +- vala/vala/valasymbolresolver.vala | 8 ++- vala/vapi/glib-2.0.vala | 144 ++++++++++++++++++------------------- 8 files changed, 104 insertions(+), 87 deletions(-) diff --git a/vala/ChangeLog b/vala/ChangeLog index be1c865..40054e9 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,14 @@ +2007-03-16 Jürg Billeter + + * vala/parser.y: default to strong references for method return types + * vala/valasymbolresolver.vala: reset TypeReference.transfers_ownership + for value-types + * vala/valasourcefile.vala: assume ownership of include filenames + * vala/valainterfacewriter.vala: use weak keyword for return types + * vala/valacodecontext.vala, vala/valasourcefile.vala, + vala/valasymbolbuilder.vala, vapi/glib-2.0.vala: add weak to return + types + 2007-03-11 Jürg Billeter * vala/valasemanticanalyzer.vala: resolve generic return values diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 3991046..9954605 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -2463,7 +2463,7 @@ method_header { GList *l; - if (vala_type_reference_get_is_ref ($5)) { + if (!vala_type_reference_get_is_weak ($5)) { vala_type_reference_set_transfers_ownership ($5, TRUE); } diff --git a/vala/vala/valacodecontext.vala b/vala/vala/valacodecontext.vala index f427f3e..374cd8e 100644 --- a/vala/vala/valacodecontext.vala +++ b/vala/vala/valacodecontext.vala @@ -126,7 +126,7 @@ public class Vala.CodeContext { } - private SourceFile find_cycle_head (SourceFile! file) { + private weak SourceFile find_cycle_head (SourceFile! file) { foreach (SourceFile dep in file.get_header_internal_full_dependencies ()) { if (dep == file) { /* ignore file-internal dependencies */ diff --git a/vala/vala/valainterfacewriter.vala b/vala/vala/valainterfacewriter.vala index c013d50..550c9fa 100644 --- a/vala/vala/valainterfacewriter.vala +++ b/vala/vala/valainterfacewriter.vala @@ -417,6 +417,8 @@ public class Vala.InterfaceWriter : CodeVisitor { } else { if (m.return_type.transfers_ownership) { write_string ("ref "); + } else { + write_string ("weak "); } write_string (m.return_type.data_type.symbol.get_full_name ()); if (m.return_type.non_null) { diff --git a/vala/vala/valasourcefile.vala b/vala/vala/valasourcefile.vala index 733ba48..11972d5 100644 --- a/vala/vala/valasourcefile.vala +++ b/vala/vala/valasourcefile.vala @@ -77,10 +77,10 @@ public class Vala.SourceFile { private string csource_filename = null; private string cinclude_filename = null; - private List header_external_includes; - private List header_internal_includes; - private List source_external_includes; - private List source_internal_includes; + private List header_external_includes; + private List header_internal_includes; + private List source_external_includes; + private List source_internal_includes; private List header_internal_full_dependencies; private List header_internal_dependencies; @@ -283,7 +283,7 @@ public class Vala.SourceFile { * * @return external include list for C header file */ - public List get_header_external_includes () { + public weak List get_header_external_includes () { return header_external_includes; } @@ -303,7 +303,7 @@ public class Vala.SourceFile { * * @return internal include list for C header file */ - public List get_header_internal_includes () { + public weak List get_header_internal_includes () { return header_internal_includes; } @@ -313,7 +313,7 @@ public class Vala.SourceFile { * * @return include list for C source file */ - public List get_source_external_includes () { + public weak List get_source_external_includes () { return source_external_includes; } @@ -323,7 +323,7 @@ public class Vala.SourceFile { * * @return include list for C source file */ - public List get_source_internal_includes () { + public weak List get_source_internal_includes () { return source_internal_includes; } @@ -333,7 +333,7 @@ public class Vala.SourceFile { * * @return definite source file dependencies */ - public List get_header_internal_full_dependencies () { + public weak List get_header_internal_full_dependencies () { return header_internal_full_dependencies; } @@ -343,7 +343,7 @@ public class Vala.SourceFile { * * @return loose source file dependencies */ - public List get_header_internal_dependencies () { + public weak List get_header_internal_dependencies () { return header_internal_dependencies; } } diff --git a/vala/vala/valasymbolbuilder.vala b/vala/vala/valasymbolbuilder.vala index 0828f58..29fd518 100644 --- a/vala/vala/valasymbolbuilder.vala +++ b/vala/vala/valasymbolbuilder.vala @@ -66,7 +66,7 @@ public class Vala.SymbolBuilder : CodeVisitor { current_symbol = current_symbol.parent_symbol; } - private Symbol add_symbol (string name, CodeNode! node) { + private weak Symbol add_symbol (string name, CodeNode! node) { if (name != null) { if (current_symbol.lookup (name) != null) { node.error = true; diff --git a/vala/vala/valasymbolresolver.vala b/vala/vala/valasymbolresolver.vala index 6ffe73c..0091bee 100644 --- a/vala/vala/valasymbolresolver.vala +++ b/vala/vala/valasymbolresolver.vala @@ -136,6 +136,8 @@ public class Vala.SymbolResolver : CodeVisitor { public override void visit_type_reference (TypeReference! type) { if (type.type_name == null || type.type_name == "void") { + // reset transfers_ownership + type.transfers_ownership = false; return; } @@ -210,10 +212,12 @@ public class Vala.SymbolResolver : CodeVisitor { } if (type.data_type != null && !type.data_type.is_reference_type ()) { - /* reset takes_ownership of value-types for contexts - * where types are ref by default (field declarations) + /* reset takes_ownership and transfers_ownership of + * value-types for contexts where types are ref by + * default (field declarations and method return types) */ type.takes_ownership = false; + type.transfers_ownership = false; } } } diff --git a/vala/vapi/glib-2.0.vala b/vala/vapi/glib-2.0.vala index a2d4df8..f8a0131 100644 --- a/vala/vapi/glib-2.0.vala +++ b/vala/vapi/glib-2.0.vala @@ -173,7 +173,7 @@ public struct unichar { [CCode (cname = "char", const_cname = "const char", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string")] public struct string { [CCode (cname = "g_strstr")] - public string str (string! needle); + public weak string str (string! needle); [CCode (cname = "g_str_has_prefix")] public bool has_prefix (string! prefix); [CCode (cname = "g_str_has_suffix")] @@ -193,22 +193,22 @@ public struct string { public ref string[] split_set (string! delimiters, int max_tokens = 0); [CCode (cname = "g_utf8_next_char")] - public string next_char (); + public weak string next_char (); [CCode (cname = "g_utf8_get_char")] public unichar get_char (); [CCode (cname = "g_utf8_offset_to_pointer")] [PlusOperator ()] - public string offset (long offset); + public weak string offset (long offset); [CCode (cname = "g_utf8_pointer_to_offset")] public long pointer_to_offset (string pos); [CCode (cname = "g_utf8_prev_char")] - public string prev_char (); + public weak string prev_char (); [CCode (cname = "g_utf8_strlen")] public long len (long max = -1); [CCode (cname = "g_utf8_strchr")] - public string chr (long len, unichar c); + public weak string chr (long len, unichar c); [CCode (cname = "g_utf8_strreverse")] - public string reverse (int len = -1); + public ref string! reverse (int len = -1); [CCode (cname = "g_utf8_validate")] public bool validate (long max_len = -1, out string end = null); @@ -222,9 +222,9 @@ public struct string { public int collate (string str2); [CCode (cname="g_strchomp")] - public string chomp(); + public weak string chomp(); [CCode (cname="g_strchug")] - public string chug(); + public weak string chug(); [CCode (cname = "g_str_hash")] public uint hash (); @@ -258,7 +258,7 @@ namespace GLib { [ReferenceType ()] public struct ObjectClass { - public ParamSpec[] list_properties (ref int n_properties); + public ref ParamSpec[] list_properties (ref int n_properties); } public struct ObjectConstructParam { @@ -275,7 +275,7 @@ namespace GLib { [ReferenceType (free_function = "g_free")] public struct Value { - public Object get_object (); + public weak Object get_object (); } public struct SignalInvocationHint { @@ -325,7 +325,7 @@ namespace GLib { public void run (); public void quit (); public bool is_running (); - public MainContext get_context (); + public weak MainContext get_context (); } public enum Priority { @@ -339,12 +339,12 @@ namespace GLib { [ReferenceType (dup_function = "g_main_context_ref", free_function = "g_main_context_unref")] public struct MainContext { public MainContext (); - public static MainContext @default (); + public static weak MainContext @default (); public bool iteration (bool may_block); public bool pending (); - public Source find_source_by_id (uint source_id); - public Source find_source_by_user_data (pointer user_data); - public Source find_source_by_funcs_user_data (SourceFuncs funcs, pointer user_data); + public weak Source find_source_by_id (uint source_id); + public weak Source find_source_by_user_data (pointer user_data); + public weak Source find_source_by_funcs_user_data (SourceFuncs funcs, pointer user_data); public void wakeup (); public bool acquire (); public void release (); @@ -360,7 +360,7 @@ namespace GLib { public void add_poll (ref PollFD fd, int priority); public void remove_poll (ref PollFD fd); public int depth (); - public Source current_source (); + public weak Source current_source (); } public callback int PollFunc (PollFD[] ufds, uint nfsd, int timeout_); @@ -418,7 +418,7 @@ namespace GLib { public void set_can_recurse (bool can_recurse); public bool get_can_recurse (); public uint get_id (); - public MainContext get_context (); + public weak MainContext get_context (); public void set_callback (SourceFunc func, pointer data, DestroyNotify notify); public void set_callback_indirect (pointer callback_data, SourceCallbackFuncs callback_funcs); public void add_poll (ref PollFD fd); @@ -476,9 +476,9 @@ namespace GLib { public struct Thread { public static void init (ThreadFunctions vtable = null); public static bool supported (); - public static Thread create (ThreadFunc func, pointer data, bool joinable, out Error error); - public static Thread create_full (ThreadFunc func, pointer data, ulong stack_size, bool joinable, bool bound, ThreadPriority priority, out Error error); - public static Thread self (); + public static weak Thread create (ThreadFunc func, pointer data, bool joinable, out Error error); + public static weak Thread create_full (ThreadFunc func, pointer data, ulong stack_size, bool joinable, bool bound, ThreadPriority priority, out Error error); + public static weak Thread self (); public pointer join (); public void set_priority (ThreadPriority priority); public static void yield (); @@ -558,9 +558,9 @@ namespace GLib { public static ref string build_path (string directory, string module_name); public static ref Module open (string file_name, ModuleFlags @flags); public bool symbol (string! symbol_name, ref pointer symbol); - public string name (); + public weak string name (); public void make_resident (); - public string error (); + public weak string error (); } [CCode (cprefix = "G_MODULE_")] @@ -586,7 +586,7 @@ namespace GLib { [ReferenceType (dup_function = "g_io_channel_ref", free_function = "g_io_channel_unref")] public struct IOChannel { - public IOChannel file (string! filename, string! mode, out Error error); + public IOChannel.file (string! filename, string! mode, out Error error); public IOStatus read_chars (string! buf, ulong count, ref ulong bytes_read, out Error error); public IOStatus read_unichar (ref unichar thechar, out Error error); public IOStatus read_line (out string str_return, ref ulong length, ref ulong terminator_pos, out Error error); @@ -699,7 +699,7 @@ namespace GLib { public void add (long microseconds); [InstanceLast ()] public bool from_iso8601 (string iso_date); - public string to_iso8601 (); + public ref string to_iso8601 (); } @@ -734,26 +734,26 @@ namespace GLib { public struct Environment { [CCode (cname = "g_get_application_name")] - public static string get_application_name (); + public static weak string get_application_name (); [CCode (cname = "g_set_application_name")] public static void set_application_name (string application_name); [CCode (cname = "g_getenv")] - public static string get_variable (string! variable); + public static weak string get_variable (string! variable); [CCode (cname = "g_setenv")] public static bool set_variable (string! variable, string! value, bool overwrite); [CCode (cname = "g_get_user_name")] - public static string get_user_name (); + public static weak string get_user_name (); [CCode (cname = "g_get_host_name")] - public static string! get_host_name (); + public static weak string! get_host_name (); [CCode (cname = "g_get_home_dir")] - public static string get_home_dir (); + public static weak string get_home_dir (); [CCode (cname = "g_get_current_dir")] public static ref string get_current_dir (); } public struct Path { public static bool is_absolute (string! file_name); - public static string skip_root (string! file_name); + public static weak string skip_root (string! file_name); public static ref string get_basename (string file_name); public static ref string get_dirname (string file_name); [CCode (cname = "g_build_filename")] @@ -864,7 +864,7 @@ namespace GLib { [ReferenceType (free_function = "g_dir_close")] public struct Dir { public static ref Dir open (string filename, uint _flags, out Error error); - public string read_name (); + public weak string read_name (); [CCode (cname = "g_mkdir")] public static int create (string pathname, int mode); @@ -877,7 +877,7 @@ namespace GLib { public MappedFile (string filename, bool writable, out Error error); public void free (); public long get_length (); - public char[] get_contents (); + public weak char[] get_contents (); } [ReferenceType ()] @@ -983,8 +983,8 @@ namespace GLib { public bool load_from_file (string! file, KeyFileFlags @flags, out Error error); public bool load_from_data (string! data, ulong length, KeyFileFlags @flags, out Error error); public bool load_from_data_dirs (string! file, out string full_path, KeyFileFlags @flags, out Error error); - public string to_data (ref ulong length, out Error error); - public string get_start_group (); + public ref string to_data (ref ulong length, out Error error); + public ref string get_start_group (); public ref string[] get_groups (ref ulong length); public ref string[] get_keys (string! group_name, ref ulong length, out Error error); public bool has_group (string! group_name); @@ -1056,21 +1056,21 @@ namespace GLib { [ReturnsModifiedPointer ()] public void concat (ref List list2); - public List first (); - public List last (); - public List nth (uint n); - public G nth_data (uint n); - public List nth_prev (uint n); + public weak List first (); + public weak List last (); + public weak List nth (uint n); + public weak G nth_data (uint n); + public weak List nth_prev (uint n); - public List find_custom (G data, CompareFunc func); + public weak List find_custom (G data, CompareFunc func); - public List find (G data); + public weak List find (G data); public int position (List llink); public int index (G data); public G data; - public List next; - public List prev; + public weak List next; + public weak List prev; } /* Singly-Linked Lists */ @@ -1102,17 +1102,17 @@ namespace GLib { [ReturnsModifiedPointer ()] public void concat (ref SList list2); - public SList last (); - public SList nth (uint n); + public weak SList last (); + public weak SList nth (uint n); public pointer nth_data (uint n); - public SList find (G data); - public SList find_custom (G data, CompareFunc func); + public weak SList find (G data); + public weak SList find_custom (G data, CompareFunc func); public int position (SList llink); public int index (G data); - public G data; - public SList next; + public weak G data; + public weak SList next; } public callback int CompareFunc (pointer a, pointer b); @@ -1126,8 +1126,8 @@ namespace GLib { [ReferenceType (dup_function = "g_queue_copy", free_function = "g_queue_free")] public struct Queue { - public List head; - public List tail; + public weak List head; + public weak List tail; public uint length; public Queue (); @@ -1136,8 +1136,8 @@ namespace GLib { public uint get_length (); public void reverse (); public ref Queue copy (); - public List find (G data); - public List find_custom (G data, CompareFunc func); + public weak List find (G data); + public weak List find_custom (G data, CompareFunc func); public void sort (CompareDataFunc compare_func, pointer user_data); public void push_head (ref G data); public void push_tail (ref G data); @@ -1145,9 +1145,9 @@ namespace GLib { public ref G pop_head (); public ref G pop_tail (); public ref G pop_nth (); - public G peek_head (); - public G peek_tail (); - public G peek_nth (); + public weak G peek_head (); + public weak G peek_tail (); + public weak G peek_nth (); public int index (G data); public void remove (G data); public void remove_all (G data); @@ -1164,7 +1164,7 @@ namespace GLib { public HashTable.full (HashFunc hash_func, EqualFunc key_equal_func, DestroyNotify key_destroy_func, DestroyNotify value_destroy_func); public void insert (ref K key, ref V value); public void replace (ref K key, ref V value); - public V lookup (K key); + public weak V lookup (K key); public bool remove (K key); } @@ -1196,17 +1196,17 @@ namespace GLib { public String (string init = ""); [CCode (cname = "g_string_sized_new")] public String.sized (ulong dfl_size); - public String assign (string! rval); - public String append (string! val); - public String append_c (char c); - public String append_unichar (unichar wc); - public String append_len (string! val, long len); - public String prepend (string! val); - public String prepend_c (char c); - public String prepend_unichar (unichar wc); - public String prepend_len (string! val, long len); - public String insert (long pos, string! val); - public String erase (long pos, long len); + public weak String assign (string! rval); + public weak String append (string! val); + public weak String append_c (char c); + public weak String append_unichar (unichar wc); + public weak String append_len (string! val, long len); + public weak String prepend (string! val); + public weak String prepend_c (char c); + public weak String prepend_unichar (unichar wc); + public weak String prepend_len (string! val, long len); + public weak String insert (long pos, string! val); + public weak String erase (long pos, long len); public string str; public long len; @@ -1223,7 +1223,7 @@ namespace GLib { public struct Quark { public static Quark from_string (string string); - public string to_string (); + public weak string to_string (); } /* GArray */ @@ -1255,7 +1255,7 @@ namespace GLib { public void sort_with_data (CompareDataFunc compare_func, pointer user_data); [ReturnsModifiedPointer ()] public void set_size (uint length); - public string free (bool free_segment); + public ref string free (bool free_segment); } /* GTree */ @@ -1279,10 +1279,10 @@ namespace GLib { public void replace (K key, V value); public int nnodes (); public int height (); - public V lookup (K key); + public weak V lookup (K key); public bool lookup_extended (K lookup_key, K orig_key, V value); public void tree_foreach (TraverseFunc traverse_func, TraverseType traverse_type, pointer user_data); - public V tree_search (CompareFunc search_func, pointer user_data); + public weak V tree_search (CompareFunc search_func, pointer user_data); public bool remove (K key); public bool steal (K key); } -- 2.7.4