From 35b3b43fda3da31f7439a87fc65a1811b930fd96 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Thu, 5 Aug 2021 17:14:48 +0200 Subject: [PATCH] girwriter: Fix position of "result" parameter for struct constructor Thanks to Princeton Ferro --- codegen/valagirwriter.vala | 9 +++++++-- tests/girwriter/GirTest-1.0.gir-expected | 12 ++++++------ tests/girwriter/girtest.vapigen-expected | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index 49a8112a2..10504c225 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -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); } diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected index b40cdddae..65ee2edd0 100644 --- a/tests/girwriter/GirTest-1.0.gir-expected +++ b/tests/girwriter/GirTest-1.0.gir-expected @@ -2765,15 +2765,15 @@ + + + - - - @@ -2809,15 +2809,15 @@ + + + - - - diff --git a/tests/girwriter/girtest.vapigen-expected b/tests/girwriter/girtest.vapigen-expected index e4fe02ae0..686780a4d 100644 --- a/tests/girwriter/girtest.vapigen-expected +++ b/tests/girwriter/girtest.vapigen-expected @@ -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 (); } -- 2.47.2