[vala] Use generics for g_object_*_{,q}data bindings



commit b3460482026b093f08109accee92f5a980c14744
Author: Jürg Billeter <j bitron ch>
Date:   Sat Mar 20 22:39:34 2010 +0100

    Use generics for g_object_*_{,q}data bindings
    
    Fixes bug 531043.

 codegen/valaccodemethodcallmodule.vala |   13 ++++++++++++-
 vala/valamethod.vala                   |    5 +++++
 vapi/gobject-2.0.vapi                  |   18 ++++++++++++------
 3 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index c03e4f6..267bf5c 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -152,7 +152,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			}
 		} else if (m is CreationMethod && m.parent_symbol is Struct) {
 			ccall.add_argument (new CCodeIdentifier ("self"));
-		} else if (m != null && m.get_type_parameters ().size > 0 && !m.has_generic_type_parameter) {
+		} else if (m != null && m.get_type_parameters ().size > 0 && !m.has_generic_type_parameter && !m.simple_generics) {
 			// generic method
 			add_generic_type_arguments (in_arg_map, ma.get_type_arguments (), expr);
 		}
@@ -370,6 +370,17 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 						CCodeExpression delegate_target_destroy_notify;
 						carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_delegate_target_cexpression (arg, out delegate_target_destroy_notify));
 						multiple_cargs = true;
+					} else if (param.parameter_type is GenericType) {
+						if (m != null && m.simple_generics) {
+							var generic_type = (GenericType) param.parameter_type;
+							int type_param_index = m.get_type_parameter_index (generic_type.type_parameter.name);
+							var type_arg = ma.get_type_arguments ().get (type_param_index);
+							if (requires_copy (type_arg)) {
+								carg_map.set (get_param_pos (param.cparameter_position + 0.1), get_destroy_func_expression (type_arg));
+							} else {
+								carg_map.set (get_param_pos (param.cparameter_position + 0.1), new CCodeConstant ("NULL"));
+							}
+						}
 					}
 
 					cexpr = handle_struct_argument (param, arg, cexpr);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 795baf0..17775ab 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -221,6 +221,8 @@ public class Vala.Method : Member {
 
 	public double generic_type_parameter_position { get; set; }
 
+	public bool simple_generics { get; set; }
+
 	public weak Signal signal_reference { get; set; }
 
 	public bool closure { get; set; }
@@ -460,6 +462,9 @@ public class Vala.Method : Member {
 			has_generic_type_parameter = true;
 			generic_type_parameter_position = a.get_double ("generic_type_pos");
 		}
+		if (a.has_argument ("simple_generics")) {
+			simple_generics = a.get_bool ("simple_generics");
+		}
 		if (a.has_argument ("returns_floating_reference")) {
 			returns_floating_reference = a.get_bool ("returns_floating_reference");
 		}
diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi
index d8f0bc8..ec9378a 100644
--- a/vapi/gobject-2.0.vapi
+++ b/vapi/gobject-2.0.vapi
@@ -313,14 +313,20 @@ namespace GLib {
 		public void set (string first_property_name, ...);
 		public void get_property (string property_name, ref Value value);
 		public void set_property (string property_name, Value value);
-		public void* get_data (string key);
-		public void set_data (string key, void* data);
+		[CCode (simple_generics = true)]
+		public unowned T get_data<T> (string key);
+		[CCode (cname = "g_object_set_data_full", simple_generics = true)]
+		public void set_data<T> (string key, owned T data);
 		public void set_data_full (string key, void* data, DestroyNotify? destroy);
-		public void* steal_data (string key);
-		public void* get_qdata (Quark quark);
-		public void set_qdata (Quark quark, void* data);
+		[CCode (simple_generics = true)]
+		public T steal_data<T> (string key);
+		[CCode (simple_generics = true)]
+		public unowned T get_qdata<T> (Quark quark);
+		[CCode (cname = "g_object_set_qdata_full", simple_generics = true)]
+		public void set_qdata<T> (Quark quark, owned T data);
 		public void set_qdata_full (Quark quark, void* data, DestroyNotify? destroy);
-		public void* steal_qdata (Quark quark);
+		[CCode (simple_generics = true)]
+		public T steal_qdata<T> (Quark quark);
 		public void freeze_notify ();
 		public void thaw_notify ();
 		[CCode (cname = "g_object_run_dispose")]



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