]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dova: Make methods equals, hash, and to_string null-safe
authorJürg Billeter <j@bitron.ch>
Fri, 23 Jul 2010 09:33:23 +0000 (11:33 +0200)
committerJürg Billeter <j@bitron.ch>
Fri, 23 Jul 2010 09:36:26 +0000 (11:36 +0200)
codegen/valadovaobjectmodule.vala

index e4e47613e01bda62fbd4968cded56778172d0982..44e07cecf2993d106591808b841b95e5f0a9ed4b 100644 (file)
@@ -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));