]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
fix runtime crash when using nullable struct parameters, patch by Alberto
authorJuerg Billeter <j@bitron.ch>
Sat, 15 Mar 2008 02:48:42 +0000 (02:48 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 15 Mar 2008 02:48:42 +0000 (02:48 +0000)
2008-03-15  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala,
  gobject/valaccodegeneratormemberaccess.vala,
  gobject/valaccodegeneratormethod.vala: fix runtime crash when
  using nullable struct parameters,
  patch by Alberto Ruiz, fixes bug 514864

svn path=/trunk/; revision=1127

ChangeLog
gobject/valaccodegenerator.vala
gobject/valaccodegeneratormemberaccess.vala
gobject/valaccodegeneratormethod.vala

index fcd63fb51d13fdca90cf3ae7d8bd3652a45344fb..83c06da7ed24d4ed3c0427119ddcf7fd2b69dcfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-15  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodegenerator.vala,
+         gobject/valaccodegeneratormemberaccess.vala,
+         gobject/valaccodegeneratormethod.vala: fix runtime crash when
+         using nullable struct parameters,
+         patch by Alberto Ruiz, fixes bug 514864
+
 2008-03-14  Jürg Billeter  <j@bitron.ch>
 
        * vapi/packages/gdk-2.0/, vapi/packages/gtk+-2.0/: fix gdk/gtk_init
index 636b9db22b0258bc76c4f7d62c500f0845765ec2..9c4261866ef091beed8df09d992cc9cff71dd9fd 100644 (file)
@@ -600,7 +600,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                var st = (Struct) p.type_reference.data_type;
                                if (!st.is_simple_type () && !p.type_reference.is_ref && !p.type_reference.is_out) {
                                        ctypename += "*";
-                                       cname = "_%s_p".printf (p.name);
                                }
                        }
 
@@ -3031,6 +3030,9 @@ public class Vala.CCodeGenerator : CodeGenerator {
                
                if (expr.operator == BinaryOperator.EQUALITY ||
                    expr.operator == BinaryOperator.INEQUALITY) {
+                       var left_type_as_struct = expr.left.static_type.data_type as Struct;
+                       var right_type_as_struct = expr.right.static_type.data_type as Struct;
+
                        if (expr.left.static_type.data_type is Class && ((Class) expr.left.static_type.data_type).is_subtype_of (gobject_type) &&
                            expr.right.static_type.data_type is Class && ((Class) expr.right.static_type.data_type).is_subtype_of (gobject_type)) {
                                var left_cl = (Class) expr.left.static_type.data_type;
@@ -3043,6 +3045,10 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                                cright = new InstanceCast (cright, left_cl);
                                        }
                                }
+                       } else if (left_type_as_struct != null && expr.right.static_type is NullType) {
+                               cleft = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cleft);
+                       } else if (right_type_as_struct != null && expr.left.static_type is NullType) {
+                               cright = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cright);
                        }
                }
 
index 4c1a7097d2ada80dff74ffb51cba4da61c22f99a..9ba17ec435fe036f1f00b9191dbef8c94a27616a 100644 (file)
@@ -178,7 +178,10 @@ public class Vala.CCodeGenerator {
                        if (p.name == "this") {
                                expr.ccodenode = pub_inst;
                        } else {
-                               if (p.type_reference.is_out || p.type_reference.is_ref) {
+                               var type_as_struct = p.type_reference.data_type as Struct;
+                               if (p.type_reference.is_out
+                                   || p.type_reference.is_ref
+                                   || (type_as_struct != null && !type_as_struct.is_simple_type ())) {
                                        expr.ccodenode = new CCodeIdentifier ("(*%s)".printf (p.name));
                                } else {
                                        // Property setters of non simple structs shall replace all occurences
index f222de89fe532afa15b1bc7d4aa8e7509b5e4291..ab8b860c80c208f937c54b59f3f87fe4c5c8b9e3 100644 (file)
@@ -312,13 +312,6 @@ public class Vala.CCodeGenerator {
                                                        var a = new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeConstant ("NULL"));
                                                        cinit.append (new CCodeExpressionStatement (a));
                                                }
-                                       } else if (t is Struct) {
-                                               var st = (Struct) t;
-                                               if (!st.is_simple_type () && !param.type_reference.is_ref && !param.type_reference.is_out) {
-                                                       var cdecl = new CCodeDeclaration (param.type_reference.get_cname ());
-                                                       cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (param.name, new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("_%s_p".printf (param.name)))));
-                                                       cinit.append (cdecl);
-                                               }
                                        }
                                }