]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Return NULL in to_string() for invalid enum values
authorLuca Bruno <lethalman88@gmail.com>
Mon, 8 Mar 2010 20:48:52 +0000 (21:48 +0100)
committerJürg Billeter <j@bitron.ch>
Fri, 19 Mar 2010 17:31:22 +0000 (18:31 +0100)
Fixes bug 612141.

codegen/valaccodebasemodule.vala
codegen/valagtypemodule.vala

index c7c6f81ec536cdbe9172c5ced403e12e543735af..72b4aa2c9403a2372aee535deace26433ef71984 100644 (file)
@@ -190,6 +190,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
        public TypeSymbol gptrarray_type;
        public TypeSymbol gthreadpool_type;
        public DataType gquark_type;
+       public DataType genumvalue_type;
        public Struct gvalue_type;
        public Struct mutex_type;
        public TypeSymbol type_module_type;
@@ -332,6 +333,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        gthreadpool_type = (TypeSymbol) glib_ns.scope.lookup ("ThreadPool");
 
                        gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark"));
+                       genumvalue_type = new ObjectType ((Class) glib_ns.scope.lookup ("EnumValue"));
                        gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
                        mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex");
 
index 5a028b52b60bd013a582ddd44bedcb02edfc81f5..a919e5128d23a9028fe17a2e20b197d62094928d 100644 (file)
@@ -1934,13 +1934,19 @@ internal class Vala.GTypeModule : GErrorModule {
                        return;
                }
 
+               var ccomma = new CCodeCommaExpression ();
+               var temp_var = get_temp_variable (genumvalue_type, false, expr, false);
+               temp_vars.insert (0, temp_var);
+
                var class_ref = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_ref"));
                class_ref.add_argument (new CCodeIdentifier (ma.inner.value_type.get_type_id ()));
-
                var get_value = new CCodeFunctionCall (new CCodeIdentifier ("g_enum_get_value"));
                get_value.add_argument (class_ref);
                get_value.add_argument ((CCodeExpression) get_ccodenode (((MemberAccess) expr.call).inner));
-               var value_name = new CCodeMemberAccess.pointer (get_value, "value_name");
-               expr.ccodenode = value_name;
+
+               ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), get_value));
+               var is_null_value = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, get_variable_cexpression (temp_var.name), new CCodeIdentifier ("NULL"));
+               ccomma.append_expression (new CCodeConditionalExpression (is_null_value, new CCodeMemberAccess.pointer (get_variable_cexpression (temp_var.name), "value_name"), new CCodeIdentifier ("NULL")));
+               expr.ccodenode = ccomma;
        }
 }