From: Michal Hruby Date: Tue, 18 Jan 2011 18:30:03 +0000 (+0100) Subject: girwriter: Fix methods returning non-null structs X-Git-Tag: 0.11.5~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b7a02ad0c54b6358dec9800057684a417fa9fce;p=thirdparty%2Fvala.git girwriter: Fix methods returning non-null structs --- diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index f6b999fdd..2bb06aebc 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -631,7 +631,8 @@ public class Vala.GIRWriter : CodeVisitor { private void write_params_and_return (List params, DataType? return_type, bool return_array_length, bool constructor = false, DataType? instance_type = null, bool user_data = false) { int last_index = 0; - if (params.size != 0 || instance_type != null || (return_type is ArrayType && return_array_length) || (return_type is DelegateType)) { + bool ret_is_struct = return_type != null && return_type.is_real_non_null_struct_type (); + if (params.size != 0 || instance_type != null || (return_type is ArrayType && return_array_length) || (return_type is DelegateType) || ret_is_struct) { write_indent (); buffer.append_printf ("\n"); indent++; @@ -647,6 +648,11 @@ public class Vala.GIRWriter : CodeVisitor { write_implicit_params (param.variable_type, ref index, !param.no_array_length, param.name, param.direction); } + if (ret_is_struct) { + // struct returns are converted to parameters + write_param_or_return (return_type, "parameter", ref index, return_array_length, "result", ParameterDirection.OUT, constructor, true); + } + last_index = index - 1; write_implicit_params (return_type, ref index, return_array_length, "result", ParameterDirection.OUT); @@ -666,8 +672,10 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); } - if (return_type != null) { + if (return_type != null && !ret_is_struct) { write_param_or_return (return_type, "return-value", ref last_index, return_array_length, null, ParameterDirection.IN, constructor); + } else if (ret_is_struct) { + write_param_or_return (new VoidType (), "return-value", ref last_index, return_array_length, null, ParameterDirection.IN); } } @@ -891,7 +899,7 @@ public class Vala.GIRWriter : CodeVisitor { } - private void write_param_or_return (DataType type, string tag, ref int index, bool has_array_length, string? name = null, ParameterDirection direction = ParameterDirection.IN, bool constructor = false) { + private void write_param_or_return (DataType type, string tag, ref int index, bool has_array_length, string? name = null, ParameterDirection direction = ParameterDirection.IN, bool constructor = false, bool caller_allocates = false) { write_indent (); buffer.append_printf ("<%s", tag); if (name != null) { @@ -910,6 +918,9 @@ public class Vala.GIRWriter : CodeVisitor { } else { buffer.append_printf (" transfer-ownership=\"none\""); } + if (caller_allocates) { + buffer.append_printf (" caller-allocates=\"1\""); + } if (type.nullable) { buffer.append_printf (" allow-none=\"1\""); }