]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Fix server methods returning structs
authorJürg Billeter <j@bitron.ch>
Wed, 16 Sep 2009 17:36:03 +0000 (19:36 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 16 Sep 2009 17:36:29 +0000 (19:36 +0200)
codegen/valadbusservermodule.vala

index 582cfe800595e42679f04445577b62ceb4f07df2..84ebe988c4557ac03f8abeffbf5fb29512678b6a 100644 (file)
@@ -268,10 +268,37 @@ internal class Vala.DBusServerModule : DBusClientModule {
                if (!(m.return_type is VoidType)) {
                        if (get_type_signature (m.return_type) == null) {
                                Report.error (m.return_type.source_reference, "D-Bus serialization of type `%s' is not supported".printf (m.return_type.to_string ()));
+                       } else if (m.return_type.is_real_struct_type ()) {
+                               cdecl = new CCodeDeclaration (m.return_type.get_cname ());
+                               cdecl.add_declarator (new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true)));
+                               out_prefragment.append (cdecl);
+
+                               if (!m.coroutine) {
+                                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+                               } else {
+                                       finish_ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+                               }
+
+                               write_expression (out_postfragment, m.return_type, new CCodeIdentifier ("iter"), new CCodeIdentifier ("result"));
+
+                               if (requires_destroy (m.return_type)) {
+                                       // keep local alive (symbol_reference is weak)
+                                       // space before `result' is work around to not trigger
+                                       // variable renaming, we really mean C identifier `result' here
+                                       var local = new LocalVariable (m.return_type, " result");
+                                       var ma = new MemberAccess.simple ("result");
+                                       ma.symbol_reference = local;
+                                       out_postfragment.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier ("result"), m.return_type, ma)));
+                               }
+
+                               block.add_statement (new CCodeExpressionStatement (ccall));
+                               if (m.coroutine) {
+                                       ready_block.add_statement (new CCodeExpressionStatement (finish_ccall));
+                               }
                        } else {
                                cdecl = new CCodeDeclaration (m.return_type.get_cname ());
                                cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
-                               out_postfragment.append (cdecl);
+                               out_prefragment.append (cdecl);
                                if (!m.coroutine) {
                                        block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("result"), ccall)));
                                } else {