[vala] Mark GObject *_get_type() functions as constant



commit fc7525d9c972feefe33de199ee9ae059115bf6f4
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Jun 22 14:42:54 2010 +0100

    Mark GObject *_get_type() functions as constant
    
    Add the G_GNUC_CONST attribute to the declarations of all *_get_type()
    functions, since they are constant functions.
    
    Fixes bug 622399.

 codegen/valaccodebasemodule.vala      |    1 +
 codegen/valadbusclientmodule.vala     |    4 +++-
 codegen/valagdbusclientmodule.vala    |    1 +
 codegen/valatyperegisterfunction.vala |    5 ++++-
 4 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ed0dab8..b54ff41 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -707,6 +707,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
 
 		var fun_name = "%s_get_type".printf (en.get_lower_case_cname (null));
 		var regfun = new CCodeFunction (fun_name, "GType");
+		regfun.attributes = "G_GNUC_CONST";
 
 		if (en.access == SymbolAccessibility.PRIVATE) {
 			regfun.modifiers = CCodeModifiers.STATIC;
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index e047785..9e02444 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -1082,7 +1082,9 @@ public class Vala.DBusClientModule : DBusModule {
 
 		source_declarations.add_type_definition (instance_struct);
 
-		source_declarations.add_type_member_declaration (new CCodeFunction(lower_cname + "_get_type", "GType"));
+		var type_fun = new CCodeFunction(lower_cname + "_get_type", "GType");
+		type_fun.attributes = "G_GNUC_CONST";
+		source_declarations.add_type_member_declaration (type_fun);
 
 		var define_type = new CCodeFunctionCall (new CCodeIdentifier ("G_DEFINE_TYPE_EXTENDED"));
 		define_type.add_argument (new CCodeIdentifier (cname));
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index e83d3c6..1113df6 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -186,6 +186,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		// declare proxy_get_type function
 		var proxy_get_type = new CCodeFunction (get_type_name, "GType");
+		proxy_get_type.attributes = "G_GNUC_CONST";
 		decl_space.add_type_member_declaration (proxy_get_type);
 	}
 
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index 7ce7205..5d541e0 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -68,17 +68,20 @@ public abstract class Vala.TypeRegisterFunction {
 		CCodeFunction fun;
 		if (!plugin) {
 			fun = new CCodeFunction ("%s_get_type".printf (get_type_declaration ().get_lower_case_cname (null)), "GType");
+			fun.attributes = "G_GNUC_CONST";
+
 			/* Function will not be prototyped anyway */
 			if (get_accessibility () == SymbolAccessibility.PRIVATE) {
 				fun.modifiers = CCodeModifiers.STATIC;
 				// avoid C warning as this function is not always used
-				fun.attributes = "G_GNUC_UNUSED";
+				fun.attributes += " G_GNUC_UNUSED";
 			}
 		} else {
 			fun = new CCodeFunction ("%s_register_type".printf (get_type_declaration ().get_lower_case_cname (null)), "GType");
 			fun.add_parameter (new CCodeFormalParameter ("module", "GTypeModule *"));
 
 			var get_fun = new CCodeFunction ("%s_get_type".printf (get_type_declaration ().get_lower_case_cname (null)), "GType");
+			get_fun.attributes = "G_GNUC_CONST";
 
 			declaration_fragment.append (get_fun.copy ());
 



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