]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girwriter: Fix position of "result" parameter for struct constructor
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 5 Aug 2021 15:14:48 +0000 (17:14 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 5 Aug 2021 15:19:02 +0000 (17:19 +0200)
Thanks to Princeton Ferro

codegen/valagirwriter.vala
tests/girwriter/GirTest-1.0.gir-expected
tests/girwriter/girtest.vapigen-expected

index 49a8112a23c2640b6d2fdb8085b23d14f4f45d46..10504c2255d32f359a98a5fc2cf91cdb0dccd93d 100644 (file)
@@ -1202,6 +1202,11 @@ public class Vala.GIRWriter : CodeVisitor {
                                }
                        }
 
+                       if (constructor && ret_is_struct) {
+                               // struct constructor has its result as first parameter
+                               write_param_or_return (return_type, "parameter", ref index, false, "result", return_comment, ParameterDirection.OUT, constructor, true);
+                       }
+
                        if (type_params != null) {
                                foreach (var p in type_params) {
                                        write_type_parameter (p, "parameter");
@@ -1215,10 +1220,10 @@ public class Vala.GIRWriter : CodeVisitor {
                                write_implicit_params (param.variable_type, ref index, get_ccode_array_length (param), get_ccode_name (param), param.direction);
                        }
 
-                       if (ret_is_struct) {
+                       if (!constructor && ret_is_struct) {
                                // struct returns are converted to parameters
                                write_param_or_return (return_type, "parameter", ref index, false, "result", return_comment, ParameterDirection.OUT, constructor, true);
-                       } else {
+                       } else if (!constructor) {
                                write_implicit_params (return_type, ref index, return_array_length, "result", ParameterDirection.OUT);
                        }
 
index b40cdddae8342beff7457ffb0603789c81d49dbb..65ee2edd0a898bd2e3f400acacfe481f4b8cf2d3 100644 (file)
                                <type name="none" c:type="void"/>
                        </return-value>
                        <parameters>
+                               <parameter name="result" direction="out" transfer-ownership="full" caller-allocates="1">
+                                       <type name="GirTest.BoxedStruct" c:type="GirTestBoxedStruct*"/>
+                               </parameter>
                                <parameter name="param1" transfer-ownership="none">
                                        <type name="gint" c:type="gint"/>
                                </parameter>
                                <parameter name="param2" transfer-ownership="none">
                                        <type name="gint" c:type="gint"/>
                                </parameter>
-                               <parameter name="result" direction="out" transfer-ownership="full" caller-allocates="1">
-                                       <type name="GirTest.BoxedStruct" c:type="GirTestBoxedStruct*"/>
-                               </parameter>
                        </parameters>
                </function>
                <method name="inv" c:identifier="gir_test_boxed_struct_inv">
                                <type name="none" c:type="void"/>
                        </return-value>
                        <parameters>
+                               <parameter name="result" direction="out" transfer-ownership="full" caller-allocates="1">
+                                       <type name="GirTest.Struct" c:type="GirTestStruct*"/>
+                               </parameter>
                                <parameter name="param1" transfer-ownership="none">
                                        <type name="gint" c:type="gint"/>
                                </parameter>
                                <parameter name="param2" transfer-ownership="none">
                                        <type name="gint" c:type="gint"/>
                                </parameter>
-                               <parameter name="result" direction="out" transfer-ownership="full" caller-allocates="1">
-                                       <type name="GirTest.Struct" c:type="GirTestStruct*"/>
-                               </parameter>
                        </parameters>
                </function>
                <method name="inv" c:identifier="gir_test_struct_inv">
index e4fe02ae0fa26d7b2908fff96fc2546d9c8a9dd9..686780a4d77b9276348a0eff377676b1c62394cd 100644 (file)
@@ -198,7 +198,7 @@ namespace GirTest {
                public int field_name;
                public int internal_field_name;
                [CCode (cname = "gir_test_boxed_struct_init_foo")]
-               public static GirTest.BoxedStruct foo (int param1, int param2);
+               public void foo (int param1, int param2);
                public static GirTest.BoxedStruct init ();
                public void inv ();
        }
@@ -214,7 +214,7 @@ namespace GirTest {
                public int field_name;
                public int internal_field_name;
                [CCode (cname = "gir_test_struct_init_foo")]
-               public static GirTest.Struct foo (int param1, int param2);
+               public void foo (int param1, int param2);
                public static GirTest.Struct init ();
                public void inv ();
        }