This updated fact takes nto account that property setters return weak
strings.



This patch allows sentinels to be specified on a class and apply to all
varargs methods of that class and subclasses.

it also allows an empty string to be specified
[CCode (sentinel="")]

which results in no sentinel argument being emitted.

I find it useful so I can declare access to macro's of a c library
without vala worrying about the arguments matching up; as traditionally
macros can be very liberal about arguments.

to use Samba's DLIST_ADD, I can use DLIST.ADD declared below:

    [Compact]
    [CCode (cprefix="DLIST_")]
    [CCode (sentinel="")]
    class DLIST {
        public static void REMOVE(...);
        public static void ADD(...);
    }

Sam


Index: vala/valaclass.vala
===================================================================
--- vala/valaclass.vala	(revision 1755)
+++ vala/valaclass.vala	(working copy)
@@ -88,10 +115,30 @@
 	 */
 	public bool has_private_fields { get; private set; }
 
+	/**
+	 * default sentinel for varargs methods of this class
+	 */
+	public string? sentinel {
+		get {
+			if (_sentinel != null) {
+				return _sentinel;
+			}
+			if (base_class != null) {
+				return base_class.sentinel;
+			}
+			return null;
+		}
+
+		set {
+			_sentinel = value;
+		}
+	}
+
 	private string cname;
 	private string const_cname;
 	private string lower_case_cprefix;
 	private string lower_case_csuffix;
+	private string _sentinel;
 	private string type_id;
 	private string ref_function;
 	private string unref_function;
@@ -580,8 +634,11 @@
 		if (a.has_argument ("type_check_function")) {
 			type_check_function = a.get_string ("type_check_function");
 		}
+		if (a.has_argument ("sentinel")) {
+			sentinel = a.get_string ("sentinel");
+		}
 	}
-	
+
 	/**
 	 * Process all associated attributes.
 	 */
Index: vala/valamethod.vala
===================================================================
--- vala/valamethod.vala	(revision 1755)
+++ vala/valamethod.vala	(working copy)
@@ -82,9 +82,14 @@
 	public string sentinel {
 		get {
 			if (_sentinel == null) {
+				if (parent_symbol != null && parent_symbol is Class) {
+					weak string s = (parent_symbol as Class).sentinel;
+					if (s != null) {
+						return s;
+					}
+				}
 				return DEFAULT_SENTINEL;
 			}
-
 			return _sentinel;
 		}
 
Index: gobject/valaccodeinvocationexpressionbinding.vala
===================================================================
--- gobject/valaccodeinvocationexpressionbinding.vala	(revision 1755)
+++ gobject/valaccodeinvocationexpressionbinding.vala	(working copy)
@@ -392,7 +392,7 @@
 		if (ellipsis) {
 			/* ensure variable argument list ends with NULL
 			 * except when using printf-style arguments */
-			if ((m == null || !m.printf_format)) {
+			if (!m.printf_format && m.sentinel != "") {
 				carg_map.set (codegen.get_param_pos (-1, true), new CCodeConstant (m.sentinel));
 			}
 		} else if (itype is DelegateType) {
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to