]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: mark non-simpletype struct return values as nullable
authorEvan Nemerson <evan@coeus-group.com>
Mon, 18 Feb 2013 11:55:01 +0000 (03:55 -0800)
committerEvan Nemerson <evan@coeus-group.com>
Tue, 19 Feb 2013 06:46:53 +0000 (22:46 -0800)
Functions which return structs currently generate incorrect C code
since valac thinks the struct is actually an out argument.  This patch
will mark the return values of functions returning structs as nullable
in order to prevent valac from adding extra arguments.

vala/valagirparser.vala

index 2773397981a85f5d137004f58e97dacf955b161a..f58345c5a5e91d904b7e289000a627378d0dc4be 100644 (file)
@@ -3308,6 +3308,31 @@ public class Vala.GirParser : CodeVisitor {
                                        }
                                }
                        }
+               } else {
+                       if (return_type is UnresolvedType && !return_type.nullable) {
+                               var st = resolve_symbol (node.parent, ((UnresolvedType) return_type).unresolved_symbol) as Struct;
+                               if (st != null) {
+                                       bool is_simple_type = false;
+                                       Struct? base_st = st;
+
+                                       while (base_st != null) {
+                                               if (base_st.is_simple_type ()) {
+                                                       is_simple_type = true;
+                                                       break;
+                                               }
+
+                                               if (base_st.base_type is UnresolvedType) {
+                                                       base_st = resolve_symbol (node.parent, ((UnresolvedType) base_st.base_type).unresolved_symbol) as Struct;
+                                               } else {
+                                                       base_st = base_st.base_struct;
+                                               }
+                                       }
+
+                                       if (!is_simple_type) {
+                                               return_type.nullable = true;
+                                       }
+                               }
+                       }
                }
                if (parameters.size > 1) {
                        ParameterInfo last_param = parameters[parameters.size-1];