From: Jürg Billeter Date: Fri, 23 Jul 2010 09:33:23 +0000 (+0200) Subject: dova: Make methods equals, hash, and to_string null-safe X-Git-Tag: 0.9.4~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6454b8edf555ecb002b324339e02d272ca1a2cb;p=thirdparty%2Fvala.git dova: Make methods equals, hash, and to_string null-safe --- diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala index e4e47613e..44e07cecf 100644 --- a/codegen/valadovaobjectmodule.vala +++ b/codegen/valadovaobjectmodule.vala @@ -1459,6 +1459,25 @@ internal class Vala.DovaObjectModule : DovaArrayModule { vfunc.add_parameter (new CCodeFormalParameter ("result", "void *")); } + if (m.get_full_name () == "any.equals") { + // make this null-safe + var null_block = new CCodeBlock (); + null_block.add_statement (new CCodeReturnStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("other")))); + vfunc.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("this")), null_block)); + } else if (m.get_full_name () == "any.hash") { + // make this null-safe + var null_block = new CCodeBlock (); + null_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("0"))); + vfunc.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("this")), null_block)); + } else if (m.get_full_name () == "any.to_string") { + // make this null-safe + var null_string = new CCodeFunctionCall (new CCodeIdentifier ("string_create_from_cstring")); + null_string.add_argument (new CCodeConstant ("\"(null)\"")); + var null_block = new CCodeBlock (); + null_block.add_statement (new CCodeReturnStatement (null_string)); + vfunc.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("this")), null_block)); + } + var vcast = get_type_private_from_type ((ObjectTypeSymbol) m.parent_symbol, get_type_from_instance (new CCodeIdentifier ("this"))); var vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, m.vfunc_name));