From: Luca Bruno Date: Mon, 8 Mar 2010 20:48:52 +0000 (+0100) Subject: Return NULL in to_string() for invalid enum values X-Git-Tag: 0.8.0~162 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ba0881e981db557345c551546a432f527ff5f787;p=thirdparty%2Fvala.git Return NULL in to_string() for invalid enum values Fixes bug 612141. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index c7c6f81ec..72b4aa2c9 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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"); diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 5a028b52b..a919e5128 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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; } }